I would like to catch the EVT_CLOSE event in a derived wx.Dialog class to be able to perform some actions prior the dialog is effectively closed, for example saving data to disk, etc.
For this I mapped the event using “self.Bind(wx.EVT_CLOSE, self.OnClose)”. The event gets called when I click either ‘OK’ or ‘Cancel’ buttons, but when I close the dialog using ALT+F4 or the little cross (X) on the upper-right corner, the event gets fired twice…
Now if I comment ‘dlg.Close()’ (line #67 in my sample app), the event is called only once when using ALT+F4 or (X), but do not gets called when ‘OK’ or ‘Cancel’ are pressed.
Any idea how to get the EVT_CLOSE event only fired once, whatever the method used to close the window (ALT+F4, (X), 'OK or ‘Cancel’) ?
Please find a sample attached.
I am on Windows XP, I tried both wxPython 2.8.12.1 and 2.9.4.0… it does the same
I changed it a bit but still see the same problem as you, as per doc
the EVT_CLOSE should fire with the “X” and with buttons with id’s
wx.ID_CANCEL and wx.ID_OK, but …
A work around would be to call your clean up action based on the
return value you get from ShowModal - see attached.
My tests are with 2.9.5.0.b20121231 msw (classic)
Werner
P.S.
PySimpleApp is deprecated in 2.9, I use the WIT all the time as it
is a very useful debug tool -
I would like to catch the EVT_CLOSE event in a derived
wx.Dialog class to be able to perform some actions prior the
dialog is effectively closed, for example saving data to disk,
etc.
For this I mapped the event
using “self.Bind(wx.EVT_CLOSE, self.OnClose)”. The event gets
called when I click either ‘OK’ or ‘Cancel’ buttons, but when
I close the dialog using ALT+F4 or the little cross (X) on the
upper-right corner, the event gets fired twice…
Now if I comment ’ dlg.Close()’ (line #67 in my sample
app), the event is called only once when using ALT+F4 or (X),
but do not gets called when ‘OK’ or ‘Cancel’ are pressed.
Any idea how to get the EVT_CLOSE
event only fired once, whatever the method used to close the
window (ALT+F4, (X), 'OK or ‘Cancel’) ?
Please find a sample attached.
I am on Windows XP, I tried both wxPython 2.8.12.1 and