[twisted+wxPython] widgets do not work?

T

Taki Jeden

Hi

Anybody used wxPython with twisted?

I started putting together a Twisted-based app with wx GUI, and the widgets
just don't work - some controls do not show up etc. - at least on my
system.

For example, if I just take the wxdemo.py shipped with Twisted, and add to
it a static text, it doesn't show - while if I change
reactor.registerWxApp(app)
reactor.run(0)
into
app.MainLoop(0)
the text is there. What the heck is wrong with this? Or am I doing something
wrong? Does the same work at yours?

Bartek
 
C

Cliff Wells

Hi

Anybody used wxPython with twisted?

I started putting together a Twisted-based app with wx GUI, and the widgets
just don't work - some controls do not show up etc. - at least on my
system.

For example, if I just take the wxdemo.py shipped with Twisted, and add to
it a static text, it doesn't show - while if I change
reactor.registerWxApp(app)
reactor.run(0)
into
app.MainLoop(0)
the text is there. What the heck is wrong with this? Or am I doing something
wrong? Does the same work at yours?

The method I use to mix the two is to poll Twisted during wxPython's
idle event:

class SomeTwistedStuff:
def fetch(self, ...):
reactor.startRunning()
# do stuff here, i.e. set up Deferreds, etc

def poll(self):
if reactor.running:
reactor.runUntilCurrent()
reactor.doIteration(0)
return reactor.running

def pending(self):
return reactor.running

class Frame(wx.Frame):
def __init__(self, ...):
...
self.twistedthing = SomeTwistedStuff(...)
self.Bind(wx.EVT_IDLE, self.OnIdle)
self.twistedthing.fetch(...)

def OnIdle(self, event):
if self.twistedthing.poll():
event.RequestMore()
event.Skip()


I yanked this out of a working app, so hopefully I didn't omit anything
important. You'll of course probably want to pass callbacks/errbacks
from your wxPython portion of the app to the Twisted portion so that the
GUI can be synchronized with the Twisted backend.

I've also seen examples of doing the polling using a wx.Timer, but this
does a lot of unnecessary polling if Twisted doesn't have anything
available. Probably not a lot of overhead, but certainly unnecessary
overhead in most cases.

Note that I tried using the wxPython reactor but found that so much time
was spent in Twisted that the GUI became unacceptably slow.

Regards,
Cliff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top