User:JeevesMkII/capturebot-http-diff
Jump to navigation
Jump to search
--- webkit2png.py.old 2014-04-01 18:33:58.000000000 +0100
+++ webkit2png.py 2014-04-01 18:33:10.000000000 +0100
@@ -44,6 +44,7 @@
self._page = QWebPage()
self.connect(self._page, SIGNAL("loadFinished(bool)"), self.__on_load_finished)
self.connect(self._page, SIGNAL("loadStarted()"), self.__on_load_started)
+ self.connect(self._page.networkAccessManager(), SIGNAL("finished(QNetworkReply *)"), self.__on_http_finished)
# The way we will use this, it seems to be unesseccary to have Scrollbars enabled
self._page.mainFrame().setScrollBarPolicy(Qt.Horizontal, Qt.ScrollBarAlwaysOff)
@@ -52,6 +53,7 @@
# Helper for multithreaded communication through signals
self.__loading = False
self.__loading_result = False
+ self.__http_ok = False;
# Loads "url" and renders it.
# Returns QImage-object on success.
@@ -75,7 +77,7 @@
logging.debug("Processing result")
- if self.__loading_result == False:
+ if !self.__loading_result || !self.__http_ok:
# raise RuntimeError("Failed to load %s" % url)
print "Failed to load %s" % url
return None
@@ -138,6 +140,11 @@
def __on_load_started(self):
logging.debug("loading started")
self.__loading = True
+
+ def __on_http_finished(self, reply):
+ logging.debug("HTTP response recieved with status code %d", reply.error())
+ self.__http_ok = (reply.error() == QNetworkReply.NoError)
+
# Eventhandler for "loadFinished(bool)" signal
def __on_load_finished(self, result):