Show HTML in GUI window with Python and PyQt4/PySide.

"""
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>''')