Skip to content

Commit

Permalink
added pyqt5
Browse files Browse the repository at this point in the history
  • Loading branch information
pohmelie committed Dec 31, 2014
1 parent 1a72744 commit e0c829b
Showing 1 changed file with 39 additions and 11 deletions.
50 changes: 39 additions & 11 deletions ghost/ghost.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
long = int


bindings = ["PySide", "PyQt4"]
bindings = ["PySide", "PyQt4", "PyQt5"]
binding = None


for name in bindings:
try:
binding = __import__(name)
if name == 'PyQt4':
if name.startswith('PyQt'):
import sip
sip.setapi('QVariant', 2)

Expand Down Expand Up @@ -66,14 +66,33 @@ def _import(name):
QtDebugMsg = QtCore.QtDebugMsg
QtFatalMsg = QtCore.QtFatalMsg
QtWarningMsg = QtCore.QtWarningMsg
qInstallMsgHandler = QtCore.qInstallMsgHandler
if name == "PyQt5":

qInstallMsgHandler = QtCore.qInstallMessageHandler

else:

qInstallMsgHandler = QtCore.qInstallMsgHandler

QtGui = _import("QtGui")
QApplication = QtGui.QApplication
QImage = QtGui.QImage
QPainter = QtGui.QPainter
QPrinter = QtGui.QPrinter
QRegion = QtGui.QRegion
if name == "PyQt5":

QtWidgets = _import("QtWidgets")
QtPrintSupport = _import("QtPrintSupport")

QApplication = QtWidgets.QApplication
QImage = QtGui.QImage
QPainter = QtGui.QPainter
QPrinter = QtPrintSupport.QPrinter
QRegion = QtGui.QRegion

else:

QApplication = QtGui.QApplication
QImage = QtGui.QImage
QPainter = QtGui.QPainter
QPrinter = QtGui.QPrinter
QRegion = QtGui.QRegion

QtNetwork = _import("QtNetwork")
QNetworkRequest = QtNetwork.QNetworkRequest
Expand All @@ -85,7 +104,16 @@ def _import(name):
QSsl = QtNetwork.QSsl

QtWebKit = _import('QtWebKit')
if name == "PyQt5":

QtWebKitWidgets = _import("QtWebKitWidgets")
QWebPage = QtWebKitWidgets.QWebPage
QWebView = QtWebKitWidgets.QWebView

else:

QWebPage = QtWebKit.QWebPage
QWebView = QtWebKit.QWebView

default_user_agent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.2 " +\
"(KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2"
Expand Down Expand Up @@ -115,7 +143,7 @@ def __call__(self, msgType, msg):
getattr(self.logger, levels[msgType])(msg)


class GhostWebPage(QtWebKit.QWebPage):
class GhostWebPage(QWebPage):
"""Overrides QtWebKit.QWebPage in order to intercept some graphical
behaviours like alert(), confirm().
Also intercepts client side console.log().
Expand Down Expand Up @@ -419,7 +447,7 @@ def __init__(

self.main_frame = self.page.mainFrame()

class GhostQWebView(QtWebKit.QWebView):
class GhostQWebView(QWebView):
def sizeHint(self):
return QSize(*viewport_size)

Expand Down Expand Up @@ -572,7 +600,7 @@ def print_to_pdf(
printer.setFullPage(True)
printer.setOutputFileName(path)
if self.webview is None:
self.webview = QtWebKit.QWebView()
self.webview = QWebView()
self.webview.setPage(self.page)
self.webview.setZoomFactor(zoom_factor)
self.webview.print_(printer)
Expand Down

0 comments on commit e0c829b

Please sign in to comment.