How can I capture the close event when the application is suddenly terminated, such as when a user clicks the X in the upper-right corner?
(The purpose: ask the user if he wants to save his changes, and prevent the application from terminating if the user indicates so.)
Thanks.
Brian
Hi Brian,
See the Veto methods described here:
http://www.wxpython.org/docs/api/wx.CloseEvent-class.html
---Phil
Friday, May 18, 2007, 11:49:38 AM, you wrote:
···
How can I capture the close event when the application is suddenly
terminated, such as when a user clicks the X in the upper-right corner?
(The purpose: ask the user if he wants to save his changes, and prevent
the application from terminating if the user indicates so.)
Thanks.
Brian
---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail:
wxPython-users-help@lists.wxwidgets.org
Brian Wolf wrote:
How can I capture the close event when the application is suddenly
terminated, such as when a user clicks the X in the upper-right corner?
(The purpose: ask the user if he wants to save his changes, and prevent
the application from terminating if the user indicates so.)
catch the wx.EVT_CLOSE event of the frame
Christian
I did look at that online documentation and tried it, but app.CanVeto() causes an error.
Brian
Phillip Stevens wrote:
···
Hi Brian,
See the Veto methods described here:
wxPython API Documentation — wxPython Phoenix 4.2.2 documentation
---Phil
Friday, May 18, 2007, 11:49:38 AM, you wrote:
How can I capture the close event when the application is suddenly terminated, such as when a user clicks the X in the upper-right corner?
(The purpose: ask the user if he wants to save his changes, and prevent
the application from terminating if the user indicates so.)
Thanks.
Brian
---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail:
wxPython-users-help@lists.wxwidgets.org
---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org
Brian Wolf wrote:
I did look at that online documentation and tried it, but app.CanVeto()
causes an error.
I don't think you can veto a EVT_CLOSE event, but as far as I remember, if you
dont't all evt.Skip() in the handler, the frame will not be closed and you can
do anything you want in the event handler.
Christian
Hi Brian,
I think that you need to use event.CanVeto() rather than
app.CanVeto().
See the example (in C) which you will need to translate into Python:
http://www.wxwidgets.org/manuals/stable/wx_windowdeletionoverview.html
Friday, May 18, 2007, 12:01:45 PM, you wrote:
···
I did look at that online documentation and tried it, but app.CanVeto()
causes an error.
Brian
Phillip Stevens wrote:
Hi Brian,
See the Veto methods described here:
wxPython API Documentation — wxPython Phoenix 4.2.2 documentation
---Phil
Friday, May 18, 2007, 11:49:38 AM, you wrote:
How can I capture the close event when the application is suddenly
terminated, such as when a user clicks the X in the upper-right corner?
(The purpose: ask the user if he wants to save his changes, and prevent
the application from terminating if the user indicates so.)
Thanks.
Brian
---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail:
wxPython-users-help@lists.wxwidgets.org
---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org
---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail:
wxPython-users-help@lists.wxwidgets.org
Actually, turns out that a command event does *not* have CanVeto method. If you bind EVT_CLOSE and EVT_MENU to the same handler (to catch both a sudden application termination and a "normal" menu event), you could do something like this:
def OnClose(self, event):
msg = _('Close') + '.....'
buttons = wx.YES_NO | wx.CANCEL | wx.ICON_INFORMATION
dialog = wx.MessageDialog(self, msg, _('Close'), buttons)
rtncode = dialog.ShowModal()
dialog.Destroy()
if rtncode == wx.ID_YES:
### save data here ###
self.Destroy()
elif rtncode == wx.ID_NO:
self.Destroy()
elif rtncode == wx.ID_CANCEL:
if not event.IsCommandEvent():
if event.CanVeto():
event.Veto(True)
else:
self.Destroy()
Brian
Phillip Stevens wrote:
···
Hi Brian,
I think that you need to use event.CanVeto() rather than
app.CanVeto().
See the example (in C) which you will need to translate into Python:
http://www.wxwidgets.org/manuals/stable/wx_windowdeletionoverview.html
Friday, May 18, 2007, 12:01:45 PM, you wrote:
I did look at that online documentation and tried it, but app.CanVeto()
causes an error.
Brian
Phillip Stevens wrote:
Hi Brian,
See the Veto methods described here:
wxPython API Documentation — wxPython Phoenix 4.2.2 documentation
---Phil
Friday, May 18, 2007, 11:49:38 AM, you wrote:
How can I capture the close event when the application is suddenly terminated, such as when a user clicks the X in the upper-right corner?
(The purpose: ask the user if he wants to save his changes, and prevent
the application from terminating if the user indicates so.)
Thanks.
Brian
---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail:
wxPython-users-help@lists.wxwidgets.org
---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org
---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail:
wxPython-users-help@lists.wxwidgets.org
---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org