Override shouldInterruptJavaScript in QWebPage with PySide

亡梦爱人 提交于 2019-12-04 06:14:02

问题


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 QWebPage

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?


回答1:


This is now fixed on PySide git master after the release 1.0.6.



来源:https://stackoverflow.com/questions/6868286/override-shouldinterruptjavascript-in-qwebpage-with-pyside

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!