[wxPython] Odd problem under GTK?

Hello, I have the following code, and I was wondering if anyone had this behavior occur.

WIth a wxDialog, if I hit the window manager’s close button on the dialog, it is properly disposed of, and mainloop is exited. However, if I hit the escape key, the dialog disappears, but the mainloop still remains. Can anyone tell me what is wrong?

Thanks!

from wxPython.wx import *

``

class MyApp(wxApp):

def OnInit(self):

maindlg = mywxDialog(NULL, -1, "Hello from wxPython", (-1,-1), (60,120))

maindlg.Show(true)

self.SetTopWindow(maindlg)

mainsizer = wxBoxSizer(wxHORIZONTAL)

b1 = wxButton(maindlg, -1, "OK", (15,30), (-1,-1), 0)

mainsizer.Add(b1, 1, wxALL, 3)

maindlg.SetAutoLayout(true)

maindlg.SetSizer(mainsizer)

mainsizer.Fit

mainsizer.SetSizeHints(maindlg)

EVT_END_SESSION(self,self.OnCloseWindow)

return true

def OnCloseWindow(self, event):

print "foo, test"

b1.Destroy()

mainsizer.Destroy()

maindlg.Destroy()

class mywxDialog(wxDialog):

def __init__(self, parent, id, title, *rest):

wxDialog.__init__(self, parent, id, title, *rest)

EVT_CLOSE(self, self.OnCloseWindow)

EVT_CHAR(self, self.OnChar)

def OnCloseWindow(self, event):

print "OnCloseWindow"

self.Destroy()

def OnChar(self, event):

print "OnChar"

print event.GetKeyCode()

``

class myLog(wxLog):

def OnLog(level, message):

print level + ":" + message

``

app = MyApp(0)

app.MainLoop()

``

Jon-Pierre Gentil wrote:

Hello, I have the following code, and I was wondering if anyone had this behavior occur.

WIth a wxDialog, if I hit the window manager's close button on the dialog, it is properly disposed of, and mainloop is exited. However, if I hit the escape key, the dialog disappears, but the mainloop still remains. Can anyone tell me what is wrong?

Thanks!

from wxPython.wx import *

class MyApp(wxApp):
    def OnInit(self):
        maindlg = mywxDialog(NULL, -1, "Hello from wxPython", (-1,-1), (60,120))
        maindlg.Show(true)
        self.SetTopWindow(maindlg)
        mainsizer = wxBoxSizer(wxHORIZONTAL)
        b1 = wxButton(maindlg, -1, "OK", (15,30), (-1,-1), 0)

IMHO you need self.maindlg and self.b1

HTH
Niki Spahiev

Hello, I have the following code, and I was wondering if anyone had this
behavior occur.

WIth a wxDialog, if I hit the window manager's close button on the
dialog, it is properly disposed of, and mainloop is exited. However, if
I hit the escape key, the dialog disappears, but the mainloop still
remains. Can anyone tell me what is wrong?

Pressing ESC on a dialog does not close the window, only hides it, so your
EVT_CLOSE is not being called, so the dialog is not Destoy()'d. For dialogs
you usually want to call ShowModal instead of just Show and then when
ShowModal returns you can call Destroy and be done with it.

···

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

Pressing ESC on a dialog does not close the window, only hides it, so your
EVT_CLOSE is not being called, so the dialog is not Destoy()'d.
For dialogs
you usually want to call ShowModal instead of just Show and then when
ShowModal returns you can call Destroy and be done with it.

So, assuming you use ShowModal, but want to get input from the ESC key in a
control in the dialog, what do you override to prevent Escape from closing
the dialog? I have a field that I allow the user to type a key combination
to create the shortcut for a menu item and right now it isn't possible to
add Esc.

ka