1 | import sys |
---|
2 | import os |
---|
3 | import logging |
---|
4 | import wx |
---|
5 | import webbrowser |
---|
6 | import urllib |
---|
7 | |
---|
8 | wx_supports_html2 = True |
---|
9 | try: |
---|
10 | import wx.html2 as html |
---|
11 | except: |
---|
12 | wx_supports_html2 = False |
---|
13 | if sys.platform.count("win32") > 0: |
---|
14 | #this is a PC |
---|
15 | wx_supports_html2 = True |
---|
16 | else: |
---|
17 | #this is a MAC |
---|
18 | wx_supports_html2 = False |
---|
19 | |
---|
20 | |
---|
21 | |
---|
22 | from gui_manager import get_app_dir |
---|
23 | |
---|
24 | |
---|
25 | class 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 | |
---|
57 | def main(): |
---|
58 | app = wx.App() |
---|
59 | DocumentationWindow(None, -1, "index.html", "", "Documentation",) |
---|
60 | app.MainLoop() |
---|
61 | |
---|
62 | if __name__ == '__main__': |
---|
63 | main() |
---|