[wxPython] Exiting dialog

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[wxPython] Exiting dialog

Przemysław G. Gawroński
Here is a quick test of exiting a dialog.

If you close the dialog by the close button everything goes well and
under Windows, the console window is also destroyed, but if you exit by
hitting the ESC key, the dialog window closes (greate), but the console
windows stays :-(

What do I have to do to make the console window close also (besides just
closing it)

Thanks

Przemek

--
Przemyslaw G. Gawronski UIN:8358522
mailto:[hidden email]
mailto:[hidden email]


## import all of the wxPython GUI package
from wxPython.wx import *


## Create a new frame class, derived from the wxPython Frame.
class Dialog(wxDialog):

        def __init__(self, parent, title):
                # First, call the base class' __init__ method to create the frame
                wxDialog.__init__( self, parent, -1, title, wxDefaultPosition, wxDefaultSize )

                self.Centre( wxBOTH )
               

        # This method is called automatically when the CLOSE event is
        # sent to this window
        def OnCloseWindow(self, event):
                self.Destroy()

        #def OnCloseMe(self, event):
                #self.Close(true)


if __name__ == '__main__':
        # Every wxWindows application must have a class derived from wxApp
        class App(wxApp):

                # wxWindows calls this method to initialize the application
                def OnInit(self):

                        # Create an instance of our customized Frame class
                        dialog = Dialog( NULL, 'test' )
                        dialog.ShowModal()

                        # Tell wxWindows that this is our main window
                        # Return a success flag
                        return true

        app = App(0) # Create an instance of the application class
        app.MainLoop() # Tell it to start processing events
Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] Exiting dialog

Robin Dunn
>
> If you close the dialog by the close button everything goes well and
> under Windows, the console window is also destroyed, but if you exit by
> hitting the ESC key, the dialog window closes (greate), but the console
> windows stays :-(
>
> What do I have to do to make the console window close also (besides just
> closing it)
>

The window still exists so the application hasn't exited.

The call to dialog.ShowModal() doesn't return until you complete a dialog
with ESC, or clicking on a button with wxID_OK or wxID_CANCEL ID's, so it is
at this point that you want to call Destroy().


def OnInit(self):
   dialog = Dialog( NULL, 'test' )
   dialog.ShowModal()
   dialog.Destroy()
   return true

The OnCloseWindow event handler is not necessary because the ShowModal() is
teminated at that time too and so Destroy() is now called in either case.

--
Robin Dunn
Software Craftsman
[hidden email]
http://AllDunn.com/robin/
http://AllDunn.com/wxPython/  Check it out!



_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] Exiting dialog

Robin Dunn
> >
> > If you close the dialog by the close button everything goes well and
> > under Windows, the console window is also destroyed, but if you exit by
> > hitting the ESC key, the dialog window closes (greate), but the console
> > windows stays :-(
> >
> > What do I have to do to make the console window close also (besides just
> > closing it)
> >
>
> The window still exists so the application hasn't exited.
>
> The call to dialog.ShowModal() doesn't return until you complete a dialog
> with ESC, or clicking on a button with wxID_OK or wxID_CANCEL ID's, so it
is
> at this point that you want to call Destroy().
>
>

Oops!  I've just proved myself wrong.  There is a bug in MSW wxDialog that is
causing this, but only for the ESC key.  Using buttons with an ID of wxID_OK
or wxID_CANCEL works as expected.  I'll get it fixed but I'm not sure what to
do for a workaround...


--
Robin Dunn
Software Craftsman
[hidden email]
http://AllDunn.com/robin/
http://AllDunn.com/wxPython/  Check it out!



_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users