source: sasview/src/sas/guiframe/documentation_window.py @ db41746

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since db41746 was db41746, checked in by Doucet, Mathieu <doucetm@…>, 9 years ago

encode url

  • Property mode set to 100644
File size: 1.8 KB
Line 
1import os
2import logging
3import wx
4import webbrowser
5import urllib
6
7wx_supports_html2 = True
8try:
9    import wx.html2 as html
10except:
11    wx_supports_html2 = False
12
13from gui_manager import get_app_dir
14
15
16class DocumentationWindow(wx.Frame):
17    def __init__(self, parent, id, path, title, size=(850, 540)):
18        wx.Frame.__init__(self, parent, id, title, size=size)
19
20        SPHINX_DOC_ENV = "SASVIEW_DOC_PATH"
21        if SPHINX_DOC_ENV in os.environ:
22            docs_path = os.path.join(os.environ[SPHINX_DOC_ENV])
23        else:
24            # For the installer, docs are in a top-level directory.  We're not
25            # bothering to worry about docs when running using the old
26            # (non - run.py) way.
27            docs_path = os.path.join(get_app_dir(), "doc")
28
29        file_path = os.path.join(docs_path, path)
30        url = "file://" + urllib.quote(file_path)
31
32        if not os.path.exists(file_path):
33            logging.error("Could not find Sphinx documentation at %s \
34            -- has it been built?", file_path)
35        elif wx_supports_html2:
36            # Complete HTML/CSS support!
37            self.view = html.WebView.New(self)
38            self.view.LoadURL(url)
39            self.Show()
40        else: 
41            logging.error("No html2 support, popping up a web browser")
42            #For cases that do not build against current version dependency
43            # Wx 3.0 we provide a webbrowser call - this is particularly for
44            #Red hat used at SNS for which Wx 3.0 is not available.  This
45            #does not deal with issue of math in docs of course.
46            webbrowser.open_new_tab(url)
47
48def main():
49    app = wx.App()
50    DocumentationWindow(None, -1, "index.html", "Documentation",)
51    app.MainLoop()
52
53if __name__ == '__main__':
54    main()
Note: See TracBrowser for help on using the repository browser.