source: sasview/src/sas/guiframe/documentation_window.py @ 5f93489

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 5f93489 was 5f93489, checked in by butler, 9 years ago

Temporary fix to mac doc I think.

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