>>
>> This will only work if this is the only top level frame in the
>> application (wx automatically exits when there are no more top level
>> windows unless you tell the wx.App not to). For an unconditional exit,
>> call wx.App.ExitMainLoop()
>>
>
>er, wx.GetApp().ExitMainLoop() that is - you want to call it on your
>wx.App object, not on the class.
>
The program again:
import wx
import time
class CountDialog(wx.Dialog):
def __init__(self, parent, ID, title, modus):
wx.Dialog.__init__(self, None, ID, title, style = wx.THICK_FRAME)
self.label = wx.StaticText(self, -1, "Beginn counting seconds!", style = wx.ALIGN_CENTRE)
self.seconds = 0
self.Bind(wx.EVT_TIMER, self.OnTimer)
self.timer = wx.Timer(self)
self.timer.Start (1000)
def OnTimer(self, event):
self.seconds += 1
self.label.SetTitle (str(self.seconds) + " seconds")
if self.seconds == 3:
#self.timer.Stop()
wx.GetApp().ExitMainLoop()
#self.Close()
app = wx.App(0)
dialog = CountDialog(None, -1, "", "")
dialog.ShowModal()
dialog.Destroy()
app.MainLoop()
But this will not end the program, the dialog counts further,
as nothing happened before.
Bizarre, and you're right. It's got somethign to do with the modal
event loop - if you replace the ShowModal() call with just Show() it
works fine. Calling EndModal() by itself doesn't fix it, though. I'm
not sure whats going on, really, but ExitMainLoop just plain isn't
working when you've got a modal dialog around (even if EndModal has
been called). I'm pretty sure this has something to do with the
multiple wxEventLoop objects that get created for modal event loops
and it's a problem in the C++ wxWidgets.
Delaying the call to exit by a second (or two) so that the dialog can
call Destroy() and finish killing itself does work. But before
ExitMainLoop() works, you must have called EndModal and the dialog you
called it on must be Destroyed().
This code works (sort of - it's non-determenistic and hackish, but it
points to the problem)
if self.seconds == 3:
print "closing"
wx.FutureCall(1000, wx.GetApp().ExitMainLoop)
self.EndModal(0)
self.Destroy()
I wouldn't reccommend this technique in production code, obviously.
···
On 4/27/06, Franz Steinhaeusler <franz.steinhaeusler@gmx.at> wrote:
On Thu, 27 Apr 2006 08:58:00 -0500, "Chris Mellon" <arkanes@gmail.com> wrote:
--
Franz Steinhaeusler