Ignore:
Timestamp:
Sep 21, 2017 1:12:37 PM (7 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
12d3e0e
Parents:
ce81f70 (diff), d76c43a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into ticket-887-reorg

File:
1 edited

Legend:

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

    rd66dbcc r724af06  
    2424    import wx.html2 as html 
    2525    WX_SUPPORTS_HTML2 = True 
    26 except: 
     26except ImportError: 
    2727    WX_SUPPORTS_HTML2 = False 
    2828 
    2929from sas.sasgui import get_app_dir 
    3030 
     31# Don't use wx html renderer on windows. 
     32if os.name == 'nt': 
     33    WX_SUPPORTS_HTML2 = False 
     34 
    3135logger = logging.getLogger(__name__) 
    3236 
    3337SPHINX_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() 
    3460 
    3561class DocumentationWindow(wx.Frame): 
     
    6995        #Note added June 21, 2015     PDB 
    7096        file_path = os.path.join(docs_path, path) 
    71         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 -- has it been built?", 
     102                         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 
    72108 
    73         if not os.path.exists(file_path): 
    74             logger.error("Could not find Sphinx documentation at %s \ 
    75             -- has it been built?", file_path) 
    76         elif WX_SUPPORTS_HTML2: 
     109        #logger.info("showing url " + url) 
     110        if WX_SUPPORTS_HTML2: 
    77111            # Complete HTML/CSS support! 
    78112            self.view = html.WebView.New(self) 
    79113            self.view.LoadURL(url) 
     114            self.Bind(html.EVT_WEBVIEW_ERROR, self.OnError, self.view) 
    80115            self.Show() 
    81116        else: 
     
    87122            webbrowser.open_new_tab(url) 
    88123 
     124    def OnError(self, evt): 
     125        logger.error("%d: %s", evt.GetInt(), evt.GetString()) 
     126 
    89127def main(): 
    90128    """ 
    91129    main loop function if running alone for testing. 
    92130    """ 
     131    url = "index.html" if len(sys.argv) <= 1 else sys.argv[1] 
    93132    app = wx.App() 
    94     DocumentationWindow(None, -1, "index.html", "", "Documentation",) 
     133    DocumentationWindow(None, -1, url, "", "Documentation",) 
    95134    app.MainLoop() 
    96135 
Note: See TracChangeset for help on using the changeset viewer.