Modal Frames with Dialogs causing wx to crash

Win 2000
wx 2.4.2.4

When I run the code below I get the following behaviour:
if I open a wxFrame with MakeModal, and after it closes I immediately follow it by opening a wxMessageDialog I am ok, but if I do everything exactly the same except I open a wxDialog I GPF. Is there some style setting on the dialog which will avoid crashing?

from wxPython.wx import *

···

#---------------------------------------------------------------------------

class MyFrame(wxFrame):
     def __init__(self, parent, ID, title, pos=wxDefaultPosition,
                  size=wxDefaultSize, style=wxDEFAULT_FRAME_STYLE, parentclosehandler=None):
         wxFrame.__init__(self, parent, ID, title, pos, size, style)
         panel = wxPanel(self, -1)

         if parentclosehandler:
             EVT_CLOSE(self, parentclosehandler)

         EVT_CLOSE(self, self.OnCloseWindow)
         button = wxButton(panel, 1003, "Close Me")
         button.SetPosition(wxPoint(15, 15))
         EVT_BUTTON(self, 1003, self.OnCloseMe)

         button = wxButton(panel, 1005, "Close with Message Dialog")
         button.SetPosition(wxPoint(15, 65))
         EVT_BUTTON(self, 1005, self.OnNewModalAndMsg)

         button = wxButton(panel, 1006, "Close with regular Dialog")
         button.SetPosition(wxPoint(15, 110))
         EVT_BUTTON(self, 1006, self.OnNewModalAndRegular)

     def OnCloseMe(self, event):
         self.Close(True)

     def OnCloseWindow(self, event):
         self.MakeModal(False)
         self.Destroy()
         event.Skip()

#----------------------------------------------------------------------------------------------------

     def OnNewModalAndMsg(self, evt):
         f = MyFrame(self,-1,"We are Modal now", size=(350,350),parentclosehandler=self.OnChildModalCloseWithMsgDlg)
         f.MakeModal(True)
         f.Show(True)

     def OnChildModalCloseWithMsgDlg(self, evt):
         self.MakeModal(True)
         evt.Skip()

         dlg = wxMessageDialog(self, 'Close me and everything dies:',
                           'A Message Box', wxOK | wxICON_INFORMATION)
         dlg.ShowModal()

#----------------------------------------------------------------------------------------------------

     def OnNewModalAndRegular(self, evt):
         f = MyFrame(self,-1,"We are Modal now", size=(350,350),parentclosehandler=self.OnChildModalCloseWithDlg)
         f.MakeModal(True)
         f.Show(True)

     def OnChildModalCloseWithDlg(self, evt):
         self.MakeModal(True)
         evt.Skip()
         dlg = wxDialog(self, -1, "Close me and everything dies: ", size=wxSize(350, 100), style=wxDEFAULT_FRAME_STYLE)
         dlg.ShowModal()

#---------------------------------------------------------------------------

def runTest(frame, nb, log):
     win = MyFrame(frame, -1, "This is a wxFrame", size=(350, 200),
                   style = wxDEFAULT_FRAME_STYLE)# | wxFRAME_TOOL_WINDOW )
     frame.otherWin = win
     win.Show(True)

#---------------------------------------------------------------------------

if __name__ == '__main__':

     import sys
     app = wxPySimpleApp()
     frame = MyFrame(None, -1,"The Title")
     frame.Show(true)
     app.MainLoop()

Michael Beaulieu wrote:

Win 2000
wx 2.4.2.4

When I run the code below I get the following behaviour:
if I open a wxFrame with MakeModal, and after it closes I immediately follow it by opening a wxMessageDialog I am ok, but if I do everything exactly the same except I open a wxDialog I GPF. Is there some style setting on the dialog which will avoid crashing?

You are binding two handlers to EVT_CLOSE. The first one calls self.Destroy() and then evt.Skip() allowing the second one to be called, which also does evt.Skip() which allows the default handler to run which calls Destroy again. Remove your call to Destroy and this program should work without problems.

···

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