source: sasview/src/sas/sasgui/guiframe/documentation_window.py @ f3bf622

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.2.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since f3bf622 was 463e7ffc, checked in by Ricardo Ferraz Leal <ricleal@…>, 8 years ago

getLogger with module name

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