By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,230 Members | 1,403 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,230 IT Pros & Developers. It's quick & easy.

[twisted+wxPython] widgets do not work?

P: n/a

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

--
#!/usr/bin/env python
print 'sygnatura'
Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Tue, 2004-10-12 at 19:58 +0200, Taki Jeden wrote:
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

--
Cliff Wells <cl************@comcast.net>

Jul 18 '05 #2

P: n/a
Cliff Wells wrote:
On Tue, 2004-10-12 at 19:58 +0200, Taki Jeden wrote:
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.
The method I use to mix the two is to poll Twisted during wxPython's
idle event:


Works like a charm! Thanks a lot, Cliff.

Bartek

--
#!/usr/bin/env python
print 'sygnatura'
Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.