[Twisted-Python] can QtWebKit fire a twisted deferred?

Kevin Mcintyre kebin70 at gmail.com
Wed May 6 12:04:45 MDT 2015


'''

I know this is meant for pyqt but I've had little luck this that board.


The short answer is yes, but it's a total hack...and I'm wondering if
anybody has a more elegant solution.


Specifically I would like to be able to fire a defer from the javascript
instead of having to call alert.


Below is an example of how I currently gain access...not necessarily a
working version.

'''


url = 'http://www.google.com'


mo = """

    var observer = new MutationObserver(function(mutations) {

        for (var x = 0; x < mutations.length; x++) {

            if (mutations[x].addedNodes.length > 0) {

                alert('add nodes')

            }

        }

    });

    var config = { attributes: true, childList: true, characterData: false }

    var nti = document.querySelector('document.body')

    observer.observe(nti, config);

"""


page = QWebPage()

def alarmAction(qframe, msg):

    print 'deferred action', qframe, msg

def mutationHook():

    d = defer.Deferred()

    d.addCallback(alarmAction)

    page.javaScriptAlert = d.callback

    page.mainFrame().documentElement().evaluateJavaScript(mo)



page.loadFinished(mutationHook)

page.mainFrame().setUrl(url)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://twistedmatrix.com/pipermail/twisted-python/attachments/20150506/df2789a0/attachment.html>


More information about the Twisted-Python mailing list