[twisted+wxPython] widgets do not work?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Taki Jeden

    #1

    [twisted+wxPython] widgets do not work?


    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.registe rWxApp(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'
  • Cliff Wells

    #2
    Re: [twisted+wxPytho n] widgets do not work?

    On Tue, 2004-10-12 at 19:58 +0200, Taki Jeden wrote:[color=blue]
    > 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.registe rWxApp(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?[/color]

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

    class SomeTwistedStuf f:
    def fetch(self, ...):
    reactor.startRu nning()
    # do stuff here, i.e. set up Deferreds, etc

    def poll(self):
    if reactor.running :
    reactor.runUnti lCurrent()
    reactor.doItera tion(0)
    return reactor.running

    def pending(self):
    return reactor.running

    class Frame(wx.Frame) :
    def __init__(self, ...):
    ...
    self.twistedthi ng = SomeTwistedStuf f(...)
    self.Bind(wx.EV T_IDLE, self.OnIdle)
    self.twistedthi ng.fetch(...)

    def OnIdle(self, event):
    if self.twistedthi ng.poll():
    event.RequestMo re()
    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 <clifford.wells @comcast.net>

    Comment

    • Taki Jeden

      #3
      Re: [twisted+wxPytho n] widgets do not work?

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

      Works like a charm! Thanks a lot, Cliff.

      Bartek

      --
      #!/usr/bin/env python
      print 'sygnatura'

      Comment

      Working...