1 | """ |
---|
2 | documentation module provides a simple means to add help throughout the |
---|
3 | application. It checks for the existence of html2 package needed to support |
---|
4 | fully html panel which supports css. The class defined here takes a title for |
---|
5 | the particular help panel, a pointer to the html documentation file of interest |
---|
6 | within the documentation tree along with a 'command' string such as a page |
---|
7 | anchor or a query string etc. The path to the doc directory is retrieved |
---|
8 | automatically by the class itself. Thus with these three pieces of information |
---|
9 | the class generates a panel with the appropriate title bar and help file |
---|
10 | formatted according the style sheets called in the html file. Finally, if an |
---|
11 | old version of Python is running and the html2 package is not available the |
---|
12 | class brings up the default browser and passes the file:/// string to it. In |
---|
13 | this case however the instruction portion is usually not passed for security |
---|
14 | reasons. |
---|
15 | """ |
---|
16 | import sys |
---|
17 | import os |
---|
18 | import logging |
---|
19 | import wx |
---|
20 | import webbrowser |
---|
21 | import urllib |
---|
22 | |
---|
23 | SPHINX_DOC_ENV = "SASVIEW_DOC_PATH" |
---|
24 | WX_SUPPORTS_HTML2 = True |
---|
25 | try: |
---|
26 | import wx.html2 as html |
---|
27 | except: |
---|
28 | WX_SUPPORTS_HTML2 = False |
---|
29 | if sys.platform.count("win32") > 0: |
---|
30 | #this is a PC |
---|
31 | WX_SUPPORTS_HTML2 = True |
---|
32 | else: |
---|
33 | #this is a MAC |
---|
34 | WX_SUPPORTS_HTML2 = False |
---|
35 | |
---|
36 | from gui_manager import get_app_dir |
---|
37 | |
---|
38 | |
---|
39 | class DocumentationWindow(wx.Frame): |
---|
40 | def __init__(self, parent, dummy_id, path, url_instruction, title, size=(850, 540)): |
---|
41 | wx.Frame.__init__(self, parent, dummy_id, title, size=size) |
---|
42 | |
---|
43 | if SPHINX_DOC_ENV in os.environ: |
---|
44 | docs_path = os.path.join(os.environ[SPHINX_DOC_ENV]) |
---|
45 | else: |
---|
46 | # For the installer, docs are in a top-level directory. We're not |
---|
47 | # bothering to worry about docs when running using the old |
---|
48 | # (non - run.py) way. |
---|
49 | docs_path = os.path.join(get_app_dir(), "doc") |
---|
50 | |
---|
51 | file_path = os.path.join(docs_path, path) |
---|
52 | url = "file:///" + urllib.quote(file_path, '/\:')+ url_instruction |
---|
53 | |
---|
54 | if not os.path.exists(file_path): |
---|
55 | logging.error("Could not find Sphinx documentation at %s \ |
---|
56 | -- has it been built?", file_path) |
---|
57 | elif WX_SUPPORTS_HTML2: |
---|
58 | # Complete HTML/CSS support! |
---|
59 | self.view = html.WebView.New(self) |
---|
60 | self.view.LoadURL(url) |
---|
61 | self.Show() |
---|
62 | else: |
---|
63 | logging.error("No html2 support, popping up a web browser") |
---|
64 | #For cases that do not build against current version dependency |
---|
65 | # Wx 3.0 we provide a webbrowser call - this is particularly for |
---|
66 | #Red hat used at SNS for which Wx 3.0 is not available. This |
---|
67 | #does not deal with issue of math in docs of course. |
---|
68 | webbrowser.open_new_tab(url) |
---|
69 | |
---|
70 | def main(): |
---|
71 | app = wx.App() |
---|
72 | DocumentationWindow(None, -1, "index.html", "", "Documentation",) |
---|
73 | app.MainLoop() |
---|
74 | |
---|
75 | if __name__ == '__main__': |
---|
76 | main() |
---|