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