> On May 6, 2015, at 11:04 AM, Kevin Mcintyre <kebi...@gmail.com> wrote:
> 
> '''
> 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.
> '''  

I don't see any import of qt4reactor or Twisted (other than the implied import 
of Deferred) in this code.  Firing a Deferred in this way should be totally 
fine though; you don't actually need the reactor for Deferreds to work (it's 
just important that if it's going to interact with any other Twisted code it 
needs to run on the main thread).

Sorry I don't have a better suggestion, but I don't see much wrong with what 
you're doing here :).

-g

> url = 'http://www.google.com <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)
> 
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python@twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

_______________________________________________
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

Reply via email to