Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/guiframe/documentation_window.py

    rf202138 r7a508b6  
     1""" 
     2documentation module provides a simple means to add help throughout the 
     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 
     14reasons. 
     15""" 
    116import os 
    217import logging 
     
    419import webbrowser 
    520import urllib 
     21import sys 
    622 
    7 wx_supports_html2 = True 
     23SPHINX_DOC_ENV = "SASVIEW_DOC_PATH" 
     24WX_SUPPORTS_HTML2 = True 
    825try: 
    926    import wx.html2 as html 
    1027except: 
    11     wx_supports_html2 = False 
     28    WX_SUPPORTS_HTML2 = False 
     29 
    1230 
    1331from gui_manager import get_app_dir 
     
    1533 
    1634class DocumentationWindow(wx.Frame): 
    17     def __init__(self, parent, id, path, title, size=(850, 540)): 
    18         wx.Frame.__init__(self, parent, id, title, size=size) 
     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)) 
    1944 
    20         SPHINX_DOC_ENV = "SASVIEW_DOC_PATH" 
     45    :param path: path to html file beginning AFTER /doc/ and ending in the 
     46    file.html 
     47    :param url_instructions: anchor string or other query e.g. '#MyAnchor 
     48    :param title - text to place in the title bar of the help panel 
     49    """ 
     50    def __init__(self, parent, dummy_id, path, url_instruction, title, size=(850, 540)): 
     51        wx.Frame.__init__(self, parent, dummy_id, title, size=size) 
     52 
    2153        if SPHINX_DOC_ENV in os.environ: 
    2254            docs_path = os.path.join(os.environ[SPHINX_DOC_ENV]) 
     
    2759            docs_path = os.path.join(get_app_dir(), "doc") 
    2860 
     61        #note that filepath for mac OS, at least in bundle starts with a 
     62        #forward slash as /Application, while the PC string begins C:\ 
     63        #It seems that mac OS is happy with four slashes as in file:////App... 
     64        #Two slashes is not sufficient to indicate path from root.  Thus for now 
     65        #we use "file:///" +... If the mac behavior changes may need to make the 
     66        #file:/// be another constant at the beginning that yields // for Mac 
     67        #and /// for PC. 
     68        #Note added June 21, 2015     PDB 
    2969        file_path = os.path.join(docs_path, path) 
    30         url = "file:///" + urllib.quote(file_path) 
     70        url = "file:///" + urllib.quote(file_path, r'/\:')+ url_instruction 
    3171 
    3272        if not os.path.exists(file_path): 
    3373            logging.error("Could not find Sphinx documentation at %s \ 
    3474            -- has it been built?", file_path) 
    35         elif wx_supports_html2: 
     75        elif WX_SUPPORTS_HTML2: 
    3676            # Complete HTML/CSS support! 
    3777            self.view = html.WebView.New(self) 
    3878            self.view.LoadURL(url) 
    3979            self.Show() 
    40         else:  
     80        else: 
    4181            logging.error("No html2 support, popping up a web browser") 
    4282            #For cases that do not build against current version dependency 
    43             # Wx 3.0 we provide a webbrowser call - this is particularly for  
     83            # Wx 3.0 we provide a webbrowser call - this is particularly for 
    4484            #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.  
     85            #does not deal with issue of math in docs of course. 
    4686            webbrowser.open_new_tab(url) 
    4787 
    4888def main(): 
     89    """ 
     90    main loop function if running alone for testing. 
     91    """ 
    4992    app = wx.App() 
    50     DocumentationWindow(None, -1, "index.html", "Documentation",) 
     93    DocumentationWindow(None, -1, "index.html", "", "Documentation",) 
    5194    app.MainLoop() 
    5295 
Note: See TracChangeset for help on using the changeset viewer.