[Twisted-Python] wxreactor ShowModal problem

mail at ortling.com mail at ortling.com
Wed Jul 12 04:43:00 EDT 2006


Hi everyone,

I have a problem with a modal dialog blocking wxreactor. If ShowDialog () is called from within a deferred callback which has been started by reactor.callLater everything twisted comes to a halt and continues only after the modal dialog has been closed. The sample script below should demonstrate the problem. I'm using twisted 2.2 for python2.4.

Help! and thanks in advance
Simon

import sys, os
from twisted.internet import wxreactor
wxreactor.install ()
from twisted.internet import reactor, defer
import wx

class Frame (wx.Frame):
    def __init__ (self, parent, id, title):
        wx.Frame.__init__ (self, parent, id, title)

        btn_dlg = wx.Button (self, -1, "Press", size=(240, 180))
        btn_dlg.Bind (wx.EVT_BUTTON, self.click)

    def click (self, event):
        d = defer.Deferred ()
        self.prepare (d)

    def prepare (self, d):
        """
        uncomment reactor.callLater or d.callback to test
        """
        d.addCallback (self.show)
        reactor.callLater (1.0, d.callback, 1) # this will fail
        #d.callback (1) # this will work
        
    def show (self, val):
        for i in range (20):
            reactor.callLater (i*0.2, self.dosth, i) # these will be printed _after_ dialog has been closed
        dlg = wx.MessageDialog (self, "I am a dialog", "Dialog", style=wx.OK|wx.CANCEL)
        ruckgabe = dlg.ShowModal ()
        dlg.Destroy ()
        if ruckgabe == wx.ID_OK:
            print "okay"
        else:
            print "not okay"

    def dosth (self, idx):
        print "doing something nr", idx 

class App (wx.App):
    def OnInit (self):
        self.frame = Frame (None, -1, "Test")
        self.frame.Show (1)
        self.SetTopWindow (self.frame)
        return True

if __name__ == "__main__":
    app = App ()
    reactor.registerWxApp (app)
    reactor.run ()




More information about the Twisted-Python mailing list