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