wx.CallAfter, Main Thread, and ShowModal

Robert Cadena wrote:

hello,

i have a question regarding the CallAfter and bringing up modal dialog boxes. i think maybe i misunderstood callafter or something.

i have a thread and i want to show a modal dialog from within this thread. So i create my dlg:
   dlg = wx.Dialog( mainframe, -1, "Thread Dialog", size=(400,400) )
   dlg.CentreOnScreen()
then i do:
   wx.CallAfter(dlg.ShowModal)

the dialog never shows up but the mainframe behaves as if there is a modal dialog. just to double check what thread is calling dlg.ShowModal i separated the showmodal into a function:

def helper():
   print "FROM:", threading.currentThread()
   dlg.ShowModal()

i do:
   wx.CallAfter(helper)
and the printout is
   print "FROM: MainThread <blah>"

i have to be honest, i just picked up wxpython in the last few months and haven't worked with threading silly. i looked at the wiki and long running tasks but i thought what they were talking about had confirmed my thought that wx.CallAFter would issue the call withint he main thread and thus properly show the dialog.

Since the dialog was created in the thread Windows will only deliver its messages to that thread's message queue. Since wxWidgets only pulls from the message queue on the main thread then no events at all are beign delivered to the dialog, including the one that tells it to show itself.

Change things so you also create the dialog in the helper and it should start working.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!