Override shouldInterruptJavaScript in QWebPage with PySide
I would like to override PySide.QtWebKit.QWebPage.shouldInterruptJavaScript() slot to silently ignore JavaScript interrupt requests. I have my own timeout timer setup and I do not need a default message dialog.
Quoting PySide documentation:
Because of binary compatibility constraints, this function is not virtual. If you want to provide your own implementation in a PySide.QtWebKit.QWebPage subclass, reimplement the QWebPage.shouldInterruptJavaScript() slot in your subclass instead. QtWebKit will dynamically detect the slot and call it.
This is an example code I wrote, but my shouldInterruptJavaScript() method is never called. I see the same code used in PhantomJS and webscraping open source projects.
import sys
from PySide import QtCore
from PySide.QtGui import QApplication
from PySide.QtWebKit import QWeb开发者_开发技巧Page
class QWebPageHeadless(QWebPage):
# FIXME: This is not working, the slot is not overriden!
@QtCore.Slot()
def shouldInterruptJavaScript(self):
print "Interrupt javascript request ignored..."
return False
if __name__ == "__main__":
app = QApplication(sys.argv)
page = QWebPageHeadless()
page.mainFrame().setHtml('<script>while(1);</script>')
sys.exit(app.exec_())
I have Python 2.7.1, PySide 1.0.2, Qt 4.7.2. Right now I am building the latest PySide so I can test it, but I can not find anything about shouldInterruptJavaScript in recent release notes or bug reports.
Is there something special how should I reimplement shouldInterruptJavaScript in my subclass?
This is now fixed on PySide git master after the release 1.0.6.
精彩评论