Skip to content

Commit

Permalink
Use PySide6 to render model docs with -html/-help option
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Kienzle committed Jan 22, 2024
1 parent 59f5bae commit df93f83
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 32 deletions.
2 changes: 1 addition & 1 deletion sasmodels/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -1566,7 +1566,7 @@ def show_docs(opts):
html = make_html(info)
path = os.path.dirname(info.filename)
url = "file://" + path.replace("\\", "/")[2:] + "/"
rst2html.view_html_wxapp(html, url)
rst2html.view_html(html, url)

def explore(opts):
# type: (Dict[str, Any]) -> None
Expand Down
44 changes: 13 additions & 31 deletions sasmodels/rst2html.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,11 @@ def view_url_wxapp(url):
app.MainLoop()

def qtview(html, url=""):
# type: (str, str) -> "QWebView"
# type: (str, str) -> "QWebEngineView"
"""View HTML in a Qt dialog"""
try:
from PyQt5.QtWebKitWidgets import QWebView
from PyQt5.QtCore import QUrl
except ImportError:
from PyQt4.QtWebKit import QWebView
from PyQt4.QtCore import QUrl
helpView = QWebView()
from PySide6.QtWebEngineWidgets import QWebEngineView
from PySide6.QtCore import QUrl
helpView = QWebEngineView()
helpView.setHtml(html, QUrl(url))
helpView.show()
return helpView
Expand All @@ -205,10 +201,7 @@ def view_html_qtapp(html, url=""):
# type: (str, str) -> None
"""HTML viewer app in Qt"""
import sys
try:
from PyQt5.QtWidgets import QApplication
except ImportError:
from PyQt4.QtGui import QApplication
from PySide6.QtWidgets import QApplication
app = QApplication([])
frame = qtview(html, url) # pylint: disable=unused-variable
sys.exit(app.exec_())
Expand All @@ -217,18 +210,11 @@ def view_url_qtapp(url):
# type: (str) -> None
"""URL viewer app in Qt"""
import sys
try:
from PyQt5.QtWidgets import QApplication
except ImportError:
from PyQt4.QtGui import QApplication
from PySide6.QtGui import QApplication
from PySide6.QtWebEngineWidgets import QWebEngineView
from PySide6.QtCore import QUrl
app = QApplication([])
try:
from PyQt5.QtWebKitWidgets import QWebView
from PyQt5.QtCore import QUrl
except ImportError:
from PyQt4.QtWebKit import QWebView
from PyQt4.QtCore import QUrl
frame = QWebView()
frame = QWebEngineView()
frame.load(QUrl(url))
frame.show()
sys.exit(app.exec_())
Expand All @@ -239,19 +225,15 @@ def view_url_qtapp(url):
def can_use_qt():
# type: () -> bool
"""
Return True if QWebView exists.
Return True if QWebEngineView exists.
Checks first in PyQt5 then in PyQt4
"""
try:
from PyQt5.QtWebKitWidgets import QWebView # pylint: disable=unused-import
from PySide6.QtWebEngineWidgets import QWebEngineView
return True
except ImportError:
try:
from PyQt4.QtWebKit import QWebView # pylint: disable=unused-import
return True
except ImportError:
return False
return False

def view_help(filename, qt=False):
# type: (str, bool) -> None
Expand All @@ -278,7 +260,7 @@ def main():
# type: () -> None
"""Command line interface to rst or html viewer."""
import sys
view_help(sys.argv[1], qt=False)
view_help(sys.argv[1], qt=True)

if __name__ == "__main__":
main()

0 comments on commit df93f83

Please sign in to comment.