Changes in src/sas/sasgui/guiframe/documentation_window.py [d7ee5866:2746eab] in sasview
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/guiframe/documentation_window.py
rd7ee5866 r2746eab 16 16 import os 17 17 import logging 18 import wx19 18 import webbrowser 20 19 import urllib 21 20 import sys 22 21 23 SPHINX_DOC_ENV = "SASVIEW_DOC_PATH" 24 WX_SUPPORTS_HTML2 = True 22 import wx 25 23 try: 26 24 import wx.html2 as html 27 except: 25 WX_SUPPORTS_HTML2 = True 26 except ImportError: 28 27 WX_SUPPORTS_HTML2 = False 29 28 29 from .gui_manager import get_app_dir 30 30 31 from gui_manager import get_app_dir 31 # Don't use wx html renderer on windows. 32 if os.name == 'nt': 33 WX_SUPPORTS_HTML2 = False 32 34 35 logger = logging.getLogger(__name__) 36 37 SPHINX_DOC_ENV = "SASVIEW_DOC_PATH" 38 39 THREAD_STARTED = False 40 def 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 47 def _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() 33 60 34 61 class DocumentationWindow(wx.Frame): … … 68 95 #Note added June 21, 2015 PDB 69 96 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 71 108 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() 84 116 else: 85 logg ing.error("No html2 support, popping up a web browser")117 logger.error("No html2 support, popping up a web browser") 86 118 #For cases that do not build against current version dependency 87 119 # Wx 3.0 we provide a webbrowser call - this is particularly for … … 90 122 webbrowser.open_new_tab(url) 91 123 124 def OnError(self, evt): 125 logger.error("%d: %s", evt.GetInt(), evt.GetString()) 126 92 127 def main(): 93 128 """ 94 129 main loop function if running alone for testing. 95 130 """ 131 url = "index.html" if len(sys.argv) <= 1 else sys.argv[1] 96 132 app = wx.App() 97 DocumentationWindow(None, -1, "index.html", "", "Documentation",)133 DocumentationWindow(None, -1, url, "", "Documentation",) 98 134 app.MainLoop() 99 135
Note: See TracChangeset
for help on using the changeset viewer.