Last active
October 27, 2023 10:33
-
-
Save techtonik/d02baae340d1cd5f8682 to your computer and use it in GitHub Desktop.
View HTML content in Python with PySide
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Placed into public domain by | |
anatoly techtonik <techtonik@gmail.com> | |
Show HTML in GUI window through PyQt4/PySide. | |
[ ] position window at the center of the screen | |
(right now it is middle bottom) | |
[ ] implement lazy loading for PyQt4/PySide | |
""" | |
import sys | |
try: | |
from PySide import QtGui, QtWebKit | |
except ImportError: | |
try: | |
from PyQt4 import QtGui, QtWebKit | |
except ImportError: | |
sys.stderr.write("WebView requires PySide or PyQt4 for GUI window") | |
def viewhtml(html): | |
app = QtGui.QApplication([]) | |
view = QtWebKit.QWebView() | |
view.setHtml(html) | |
view.show() | |
app.exec_() | |
def viewurl(url): | |
app = QtGui.QApplication([]) | |
view = QtWebKit.QWebView() | |
view.load(url) | |
view.show() | |
app.exec_() | |
viewhtml('''<b>WebView Public Gist</b>''') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment