Changes in src/sas/sasgui/guiframe/documentation_window.py [9d566b2:959eb01] in sasview
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/guiframe/documentation_window.py
r9d566b2 r959eb01 16 16 import os 17 17 import logging 18 import wx 18 19 import webbrowser 19 20 import urllib 20 21 import sys 21 22 22 import wx23 try:24 import wx.html2 as html25 WX_SUPPORTS_HTML2 = True26 except ImportError:27 WX_SUPPORTS_HTML2 = False28 29 from .gui_manager import get_app_dir30 31 23 logger = logging.getLogger(__name__) 32 24 33 25 SPHINX_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 34 31 35 THREAD_STARTED = False36 def start_documentation_server(doc_root, port):37 import thread38 global THREAD_STARTED39 if not THREAD_STARTED:40 thread.start_new_thread(_documentation_server, (doc_root, port))41 THREAD_STARTED = True42 32 43 def _documentation_server(doc_root, port): 44 from SimpleHTTPServer import SimpleHTTPRequestHandler 45 from SocketServer import TCPServer 33 from gui_manager import get_app_dir 46 34 47 os.chdir(doc_root)48 httpd = TCPServer(("127.0.0.1", port), SimpleHTTPRequestHandler, bind_and_activate=False)49 httpd.allow_reuse_address = True50 try:51 httpd.server_bind()52 httpd.server_activate()53 httpd.serve_forever()54 finally:55 httpd.server_close()56 35 57 36 class DocumentationWindow(wx.Frame): … … 91 70 #Note added June 21, 2015 PDB 92 71 file_path = os.path.join(docs_path, path) 93 if path.startswith('http'): 94 url = path 95 elif not os.path.exists(file_path): 96 url = "index.html" 72 url = "file:///" + urllib.quote(file_path, r'/\:')+ url_instruction 73 74 if not os.path.exists(file_path): 97 75 logger.error("Could not find Sphinx documentation at %s \ 98 76 -- has it been built?", file_path) 99 elif True: 100 start_documentation_server(docs_path, port=7999) 101 url = "http://localhost:7999/" + path.replace('\\', '/') + url_instruction 102 else: 103 url = "file:///" + urllib.quote(file_path, r'/\:')+ url_instruction 104 105 logger.info("showing url " + url) 106 if WX_SUPPORTS_HTML2: 77 elif WX_SUPPORTS_HTML2: 107 78 # Complete HTML/CSS support! 108 79 self.view = html.WebView.New(self) 109 80 self.view.LoadURL(url) 110 self.Bind(html.EVT_WEBVIEW_ERROR, self.OnError, self.view)111 81 self.Show() 112 82 else: … … 118 88 webbrowser.open_new_tab(url) 119 89 120 def OnError(self, evt):121 logger.error("%d: %s", evt.GetInt(), evt.GetString())122 123 90 def main(): 124 91 """ 125 92 main loop function if running alone for testing. 126 93 """ 127 url = "index.html" if len(sys.argv) <= 1 else sys.argv[1]128 94 app = wx.App() 129 DocumentationWindow(None, -1, url, "", "Documentation",)95 DocumentationWindow(None, -1, "index.html", "", "Documentation",) 130 96 app.MainLoop() 131 97
Note: See TracChangeset
for help on using the changeset viewer.