[twisted+wxPython] widgets do not work?

Taki Jeden bartekgorny at interia.pl
Wed Oct 13 11:37:10 CEST 2004


exarkun at divmod.com wrote:

> On Tue, 12 Oct 2004 19:58:38 +0200, Taki Jeden <bartekgorny at interia.pl>
> 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?
>> 
>> Bartek
>> 
> 
>   There are several known problems with Twisted/wxPython integration, but
>   this doesn't sound like one of them.  Could you include your modified
>   wxdemo.py?

Yes, sure - here it is. In two versions - one is the same wxdemo with a
statictext added, the other is still the same but app.MainLoop instead of
the reactor. The second one works, the first does not.

Version 1:

from wxPython.wx import *

from twisted.internet import wxreactor
wxreactor.install()
from twisted.internet import reactor

# set up so that "hello, world" is printed once a second
def helloWorld():
    print "hello, world"
    reactor.callLater(1, helloWorld)
reactor.callLater(1, helloWorld)

def twoSecondsPassed():
    print "two seconds passed"

reactor.callLater(2, twoSecondsPassed)

ID_EXIT  = 101

class MyFrame(wxFrame):
    def __init__(self, parent, ID, title):
        wxFrame.__init__(self, parent, ID, title, wxDefaultPosition,
wxSize(300, 200))
        menu = wxMenu()
        menu.Append(ID_EXIT, "E&xit", "Terminate the program")
        menuBar = wxMenuBar()
        menuBar.Append(menu, "&File");
        self.x=wxStaticText(self,-1,'dupadupa')
        self.SetMenuBar(menuBar)
        EVT_MENU(self, ID_EXIT,  self.DoExit)

    def DoExit(self, event):
        self.Close(true)
        reactor.stop()

class MyApp(wxApp):

    def OnInit(self):
        frame = MyFrame(NULL, -1, "Hello, world")
        frame.Show(true)
        self.SetTopWindow(frame)
        return true

def demo():
    app = MyApp(0)
    reactor.registerWxApp(app)
    reactor.run(0)

if __name__ == '__main__':
    demo()


Version 2:


from wxPython.wx import *

from twisted.internet import wxreactor
wxreactor.install()
from twisted.internet import reactor

# set up so that "hello, world" is printed once a second
def helloWorld():
    print "hello, world"
    #reactor.callLater(1, helloWorld)
#reactor.callLater(1, helloWorld)

def twoSecondsPassed():
    print "two seconds passed"

#reactor.callLater(2, twoSecondsPassed)

ID_EXIT  = 101

class MyFrame(wxFrame):
    def __init__(self, parent, ID, title):
        wxFrame.__init__(self, parent, ID, title, wxDefaultPosition,
wxSize(300, 200))
        menu = wxMenu()
        menu.Append(ID_EXIT, "E&xit", "Terminate the program")
        menuBar = wxMenuBar()
        menuBar.Append(menu, "&File");
        self.x=wxStaticText(self,-1,'dupadupa')
        self.SetMenuBar(menuBar)
        EVT_MENU(self, ID_EXIT,  self.DoExit)

    def DoExit(self, event):
        self.Close(true)
        reactor.stop()

class MyApp(wxApp):

    def OnInit(self):
        frame = MyFrame(NULL, -1, "Hello, world")
        frame.Show(true)
        self.SetTopWindow(frame)
        return true

def demo():
    app = MyApp(0)
    app.MainLoop()
    #reactor.registerWxApp(app)
    #reactor.run(0)

if __name__ == '__main__':
    demo()


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



More information about the Python-list mailing list