Ignore:
Timestamp:
Sep 20, 2017 2:39:48 PM (7 years ago)
Author:
GitHub <noreply@…>
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:
fca1f50, 793713d
Parents:
ce0a245 (diff), f80b416e (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.
git-author:
Paul Kienzle <pkienzle@…> (09/20/17 14:39:48)
git-committer:
GitHub <noreply@…> (09/20/17 14:39:48)
Message:

Merge pull request #103 from SasView?/ticket-639-katex

Ticket 639 katex

File:
1 edited

Legend:

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

    r6a455cd3 rf80b416e  
    1616import os 
    1717import logging 
    18 import wx 
    1918import webbrowser 
    2019import urllib 
    2120import sys 
    2221 
     22import wx 
     23try: 
     24    import wx.html2 as html 
     25    WX_SUPPORTS_HTML2 = True 
     26except ImportError: 
     27    WX_SUPPORTS_HTML2 = False 
     28 
     29from .gui_manager import get_app_dir 
     30 
     31# Don't use wx html renderer on windows. 
     32if os.name == 'nt': 
     33    WX_SUPPORTS_HTML2 = False 
     34 
    2335logger = logging.getLogger(__name__) 
    2436 
    2537SPHINX_DOC_ENV = "SASVIEW_DOC_PATH" 
    26 WX_SUPPORTS_HTML2 = True 
    27 try: 
    28     import wx.html2 as html 
    29 except: 
    30     WX_SUPPORTS_HTML2 = False 
    3138 
     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 
    3246 
    33 from gui_manager import get_app_dir 
     47def _documentation_server(doc_root, port): 
     48    from SimpleHTTPServer import SimpleHTTPRequestHandler 
     49    from SocketServer import TCPServer 
    3450 
     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() 
    3560 
    3661class DocumentationWindow(wx.Frame): 
     
    7095        #Note added June 21, 2015     PDB 
    7196        file_path = os.path.join(docs_path, path) 
    72         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 
    73108 
    74         if not os.path.exists(file_path): 
    75             logger.error("Could not find Sphinx documentation at %s \ 
    76             -- has it been built?", file_path) 
    77         #Commenting following 5 lines, so default browser is forced 
    78         #This is due to CDN mathjax discontinuation of service, intenal help 
    79         #browser should be back with qt version 
    80         #Note added by Wojtek Potrzebowski, July 4th 2017 
    81         # elif WX_SUPPORTS_HTML2: 
    82         #     # Complete HTML/CSS support! 
    83         #     self.view = html.WebView.New(self) 
    84         #     self.view.LoadURL(url) 
    85         #     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() 
    86116        else: 
    87117            logger.error("No html2 support, popping up a web browser") 
     
    92122            webbrowser.open_new_tab(url) 
    93123 
     124    def OnError(self, evt): 
     125        logger.error("%d: %s", evt.GetInt(), evt.GetString()) 
     126 
    94127def main(): 
    95128    """ 
    96129    main loop function if running alone for testing. 
    97130    """ 
     131    url = "index.html" if len(sys.argv) <= 1 else sys.argv[1] 
    98132    app = wx.App() 
    99     DocumentationWindow(None, -1, "index.html", "", "Documentation",) 
     133    DocumentationWindow(None, -1, url, "", "Documentation",) 
    100134    app.MainLoop() 
    101135 
Note: See TracChangeset for help on using the changeset viewer.