[e8af9b1] | 1 | """ |
---|
[d20eb45] | 2 | documentation module provides a simple means to add help throughout the |
---|
[e8af9b1] | 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 |
---|
[d20eb45] | 14 | reasons. |
---|
[e8af9b1] | 15 | """ |
---|
[a4340d1] | 16 | import os |
---|
| 17 | import logging |
---|
[c3437260] | 18 | import wx |
---|
[a4340d1] | 19 | import webbrowser |
---|
[db41746] | 20 | import urllib |
---|
[f349f85] | 21 | import sys |
---|
[90662e6] | 22 | |
---|
[e8af9b1] | 23 | SPHINX_DOC_ENV = "SASVIEW_DOC_PATH" |
---|
| 24 | WX_SUPPORTS_HTML2 = True |
---|
[90662e6] | 25 | try: |
---|
[c3437260] | 26 | import wx.html2 as html |
---|
[90662e6] | 27 | except: |
---|
[e8af9b1] | 28 | WX_SUPPORTS_HTML2 = False |
---|
[d20eb45] | 29 | |
---|
[90662e6] | 30 | |
---|
[9afc543] | 31 | from gui_manager import get_app_dir |
---|
| 32 | |
---|
[c3437260] | 33 | |
---|
[90662e6] | 34 | class DocumentationWindow(wx.Frame): |
---|
[d20eb45] | 35 | """ |
---|
| 36 | DocumentationWindow inherits from wx.Frame and provides a centralized |
---|
| 37 | coherent framework for all help documentation. Help files must be html |
---|
| 38 | files stored in an properly organized tree below the top 'doc' folder. In |
---|
| 39 | order to display the appropriate help file from anywhere in the gui, the |
---|
| 40 | code simply needs to know the location below the top level where the |
---|
| 41 | help file resides along with the name of the help file. |
---|
| 42 | called |
---|
| 43 | (self, parent, dummy_id, path, url_instruction, title, size=(850, 540)) |
---|
[c8d22ec] | 44 | |
---|
| 45 | :param path: path to html file beginning AFTER /doc/ and ending in the |
---|
[a12c0a6] | 46 | file.html. |
---|
| 47 | |
---|
| 48 | :param url_instructions: anchor string or other query e.g. '#MyAnchor' |
---|
| 49 | :param title: text to place in the title bar of the help panel |
---|
[d20eb45] | 50 | """ |
---|
[e8af9b1] | 51 | def __init__(self, parent, dummy_id, path, url_instruction, title, size=(850, 540)): |
---|
| 52 | wx.Frame.__init__(self, parent, dummy_id, title, size=size) |
---|
[c3437260] | 53 | |
---|
[a4340d1] | 54 | if SPHINX_DOC_ENV in os.environ: |
---|
| 55 | docs_path = os.path.join(os.environ[SPHINX_DOC_ENV]) |
---|
| 56 | else: |
---|
[9afc543] | 57 | # For the installer, docs are in a top-level directory. We're not |
---|
| 58 | # bothering to worry about docs when running using the old |
---|
| 59 | # (non - run.py) way. |
---|
[90662e6] | 60 | docs_path = os.path.join(get_app_dir(), "doc") |
---|
[a4340d1] | 61 | |
---|
[d20eb45] | 62 | #note that filepath for mac OS, at least in bundle starts with a |
---|
| 63 | #forward slash as /Application, while the PC string begins C:\ |
---|
| 64 | #It seems that mac OS is happy with four slashes as in file:////App... |
---|
| 65 | #Two slashes is not sufficient to indicate path from root. Thus for now |
---|
| 66 | #we use "file:///" +... If the mac behavior changes may need to make the |
---|
| 67 | #file:/// be another constant at the beginning that yields // for Mac |
---|
| 68 | #and /// for PC. |
---|
[c8d22ec] | 69 | #Note added June 21, 2015 PDB |
---|
[41eee5f] | 70 | file_path = os.path.join(docs_path, path) |
---|
[d20eb45] | 71 | url = "file:///" + urllib.quote(file_path, r'/\:')+ url_instruction |
---|
[78bcf3c3] | 72 | |
---|
[90662e6] | 73 | if not os.path.exists(file_path): |
---|
[a4340d1] | 74 | logging.error("Could not find Sphinx documentation at %s \ |
---|
[90662e6] | 75 | -- has it been built?", file_path) |
---|
[e8af9b1] | 76 | elif WX_SUPPORTS_HTML2: |
---|
[c3437260] | 77 | # Complete HTML/CSS support! |
---|
| 78 | self.view = html.WebView.New(self) |
---|
[db41746] | 79 | self.view.LoadURL(url) |
---|
[a4340d1] | 80 | self.Show() |
---|
[e8af9b1] | 81 | else: |
---|
[90662e6] | 82 | logging.error("No html2 support, popping up a web browser") |
---|
[a4340d1] | 83 | #For cases that do not build against current version dependency |
---|
[e8af9b1] | 84 | # Wx 3.0 we provide a webbrowser call - this is particularly for |
---|
[a4340d1] | 85 | #Red hat used at SNS for which Wx 3.0 is not available. This |
---|
[e8af9b1] | 86 | #does not deal with issue of math in docs of course. |
---|
[db41746] | 87 | webbrowser.open_new_tab(url) |
---|
[a4340d1] | 88 | |
---|
[90662e6] | 89 | def main(): |
---|
[d20eb45] | 90 | """ |
---|
| 91 | main loop function if running alone for testing. |
---|
| 92 | """ |
---|
[90662e6] | 93 | app = wx.App() |
---|
[3db44fb] | 94 | DocumentationWindow(None, -1, "index.html", "", "Documentation",) |
---|
[90662e6] | 95 | app.MainLoop() |
---|
| 96 | |
---|
| 97 | if __name__ == '__main__': |
---|
[f202138] | 98 | main() |
---|