Changeset f2f5413 in sasmodels


Ignore:
Timestamp:
Apr 14, 2017 8:48:18 AM (7 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
3a45c2c, 630156b
Parents:
63a7fe8
Message:

allow viewing of rst or html files with qt/wx

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/rst2html.py

    rc4e3215 rf2f5413  
    155155    return frame 
    156156 
     157def view_html_wxapp(html, url=""): 
     158    import wx  # type: ignore 
     159    app = wx.App() 
     160    frame = wxview(html, url) 
     161    app.MainLoop() 
     162 
     163def view_url_wxapp(url): 
     164    import wx  # type: ignore 
     165    from wx.html2 import WebView 
     166    app = wx.App() 
     167    frame = wx.Frame(None, -1, size=(850, 540)) 
     168    view = WebView.New(frame) 
     169    view.LoadURL(url) 
     170    frame.Show() 
     171    app.MainLoop() 
     172 
    157173def qtview(html, url=""): 
    158174    try: 
     
    167183    return helpView 
    168184 
    169 def view_html_wxapp(html, url=""): 
    170     import wx  # type: ignore 
    171     app = wx.App() 
    172     frame = wxview(html, url) 
    173     app.MainLoop() 
    174  
    175185def view_html_qtapp(html, url=""): 
    176186    import sys 
     
    183193    sys.exit(app.exec_()) 
    184194 
    185 def view_rst_app(filename, qt=False): 
     195def view_url_qtapp(url): 
     196    import sys 
     197    try: 
     198        from PyQt5.QtWidgets import QApplication 
     199    except ImportError: 
     200        from PyQt4.QtGui import QApplication 
     201    app = QApplication([]) 
     202    try: 
     203        from PyQt5.QtWebKitWidgets import QWebView 
     204        from PyQt5.QtCore import QUrl 
     205    except ImportError: 
     206        from PyQt4.QtWebkit import QWebView 
     207        from PyQt4.QtCore import QUrl 
     208    frame = QWebView() 
     209    frame.load(QUrl(url)) 
     210    frame.show() 
     211    sys.exit(app.exec_()) 
     212 
     213def view_help(filename, qt=False): 
    186214    import os 
    187     html = load_rst_as_html(filename) 
    188     url="file://"+os.path.abspath(filename)+"/" 
    189     if qt: 
    190         view_html_qtapp(html, url) 
     215    url="file:///"+os.path.abspath(filename).replace("\\","/") 
     216    if filename.endswith('.rst'): 
     217        html = load_rst_as_html(filename) 
     218        if qt: 
     219            view_html_qtapp(html, url) 
     220        else: 
     221            view_html_wxapp(html, url) 
    191222    else: 
    192         view_html_wxapp(html, url) 
     223        if qt: 
     224            view_url_qtapp(url) 
     225        else: 
     226            view_url_wxapp(url) 
    193227 
    194228if __name__ == "__main__": 
    195229    import sys 
    196     view_rst_app(sys.argv[1], qt=True) 
    197  
     230    view_help(sys.argv[1], qt=True) 
     231 
Note: See TracChangeset for help on using the changeset viewer.