Ignore:
File:
1 edited

Legend:

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

    rd7ee5866 r2746eab  
    1616import os 
    1717import logging 
    18 import wx 
    1918import webbrowser 
    2019import urllib 
    2120import sys 
    2221 
    23 SPHINX_DOC_ENV = "SASVIEW_DOC_PATH" 
    24 WX_SUPPORTS_HTML2 = True 
     22import wx 
    2523try: 
    2624    import wx.html2 as html 
    27 except: 
     25    WX_SUPPORTS_HTML2 = True 
     26except ImportError: 
    2827    WX_SUPPORTS_HTML2 = False 
    2928 
     29from .gui_manager import get_app_dir 
    3030 
    31 from gui_manager import get_app_dir 
     31# Don't use wx html renderer on windows. 
     32if os.name == 'nt': 
     33    WX_SUPPORTS_HTML2 = False 
    3234 
     35logger = logging.getLogger(__name__) 
     36 
     37SPHINX_DOC_ENV = "SASVIEW_DOC_PATH" 
     38 
     39THREAD_STARTED = False 
     40def start_documentation_server(doc_root, port): 
     41    import thread 
     42    global THREAD_STARTED 
     43    if not THREAD_STARTED: 
     44        thread.start_new_thread(_documentation_server, (doc_root, port)) 
     45        THREAD_STARTED = True 
     46 
     47def _documentation_server(doc_root, port): 
     48    from SimpleHTTPServer import SimpleHTTPRequestHandler 
     49    from SocketServer import TCPServer 
     50 
     51    os.chdir(doc_root) 
     52    httpd = TCPServer(("127.0.0.1", port), SimpleHTTPRequestHandler, bind_and_activate=False) 
     53    httpd.allow_reuse_address = True 
     54    try: 
     55        httpd.server_bind() 
     56        httpd.server_activate() 
     57        httpd.serve_forever() 
     58    finally: 
     59        httpd.server_close() 
    3360 
    3461class DocumentationWindow(wx.Frame): 
     
    6895        #Note added June 21, 2015     PDB 
    6996        file_path = os.path.join(docs_path, path) 
    70         url = "file:///" + urllib.quote(file_path, r'/\:')+ url_instruction 
     97        if path.startswith('http'): 
     98            url = path 
     99        elif not os.path.exists(file_path): 
     100            url = "index.html" 
     101            logger.error("Could not find Sphinx documentation at %s \ 
     102            -- has it been built?", file_path) 
     103        elif False: 
     104            start_documentation_server(docs_path, port=7999) 
     105            url = "http://127.0.0.1:7999/" + path.replace('\\', '/') + url_instruction 
     106        else: 
     107            url = "file:///" + urllib.quote(file_path, r'/\:')+ url_instruction 
    71108 
    72         if not os.path.exists(file_path): 
    73             logging.error("Could not find Sphinx documentation at %s \ 
    74             -- has it been built?", file_path) 
    75         #Commenting following 5 lines, so default browser is forced 
    76         #This is due to CDN mathjax discontinuation of service, intenal help 
    77         #browser should be back with qt version 
    78         #Note added by Wojtek Potrzebowski, July 4th 2017 
    79         # elif WX_SUPPORTS_HTML2: 
    80         #     # Complete HTML/CSS support! 
    81         #     self.view = html.WebView.New(self) 
    82         #     self.view.LoadURL(url) 
    83         #     self.Show() 
     109        logger.info("showing url " + url) 
     110        if WX_SUPPORTS_HTML2: 
     111            # Complete HTML/CSS support! 
     112            self.view = html.WebView.New(self) 
     113            self.view.LoadURL(url) 
     114            self.Bind(html.EVT_WEBVIEW_ERROR, self.OnError, self.view) 
     115            self.Show() 
    84116        else: 
    85             logging.error("No html2 support, popping up a web browser") 
     117            logger.error("No html2 support, popping up a web browser") 
    86118            #For cases that do not build against current version dependency 
    87119            # Wx 3.0 we provide a webbrowser call - this is particularly for 
     
    90122            webbrowser.open_new_tab(url) 
    91123 
     124    def OnError(self, evt): 
     125        logger.error("%d: %s", evt.GetInt(), evt.GetString()) 
     126 
    92127def main(): 
    93128    """ 
    94129    main loop function if running alone for testing. 
    95130    """ 
     131    url = "index.html" if len(sys.argv) <= 1 else sys.argv[1] 
    96132    app = wx.App() 
    97     DocumentationWindow(None, -1, "index.html", "", "Documentation",) 
     133    DocumentationWindow(None, -1, url, "", "Documentation",) 
    98134    app.MainLoop() 
    99135 
Note: See TracChangeset for help on using the changeset viewer.