Phoenix Logo

phoenix_title wx.CloseEvent

This event class contains information about window and session close events.

The handler function for EVT_CLOSE is called when the user has tried to close a a frame or dialog box using the window manager (X) or system menu (Windows). It can also be invoked by the application itself programmatically, for example by calling the wx.Window.Close function.

You should check whether the application is forcing the deletion of the window using wx.CloseEvent.CanVeto . If this is False, you must destroy the window using wx.Window.Destroy .

If the return value is True, it is up to you whether you respond by destroying the window.

If you don’t destroy the window, you should call wx.CloseEvent.Veto to let the calling code know that you did not destroy the window. This allows the wx.Window.Close function to return True or False depending on whether the close instruction was honoured or not.

Example of a wx.CloseEvent handler:

def OnClose(self, event):

    if event.CanVeto() and self.fileNotSaved:

        if wx.MessageBox("The file has not been saved... continue closing?",
                         "Please confirm",
                         wx.ICON_QUESTION | wx.YES_NO) != wx.YES:

            event.Veto()
            return

    self.Destroy()  # you may also do:  event.Skip()
                    # since the default event handler does call Destroy(), too

The EVT_END_SESSION event is slightly different as it is sent by the system when the user session is ending (e.g. because of log out or shutdown) and so all windows are being forcefully closed. At least under MSW, after the handler for this event is executed the program is simply killed by the system. Because of this, the default handler for this event provided by wxWidgets calls all the usual cleanup code (including wx.App.OnExit ) so that it could still be executed and exit()s the process itself, without waiting for being killed. If this behaviour is for some reason undesirable, make sure that you define a handler for this event in your App-derived class and do not call event.Skip() in it (but be aware that the system will still kill your application).

events Events Emitted by this Class

Handlers bound for the following event types will receive a wx.CloseEvent parameter.

  • EVT_CLOSE: Process a wxEVT_CLOSE_WINDOW command event, supplying the member function. This event applies to wx.Frame and wx.Dialog classes.
  • EVT_QUERY_END_SESSION: Process a wxEVT_QUERY_END_SESSION session event, supplying the member function. This event can be handled in App-derived class only.
  • EVT_END_SESSION: Process a wxEVT_END_SESSION session event, supplying the member function. This event can be handled in App-derived class only.

class_hierarchy Class Hierarchy

Inheritance diagram for class CloseEvent:


method_summary Methods Summary

__init__ Constructor.
CanVeto Returns True if you can veto a system shutdown or a window close event.
GetLoggingOff Returns True if the user is just logging off or False if the system is shutting down.
GetVeto Returns whether the Veto flag was set.
SetCanVeto Sets the ‘can veto’ flag.
SetLoggingOff Sets the ‘logging off’ flag.
Veto Call this from your event handler to veto a system shutdown or to signal to the calling application that a window close did not happen.

property_summary Properties Summary

LoggingOff See GetLoggingOff and SetLoggingOff

api Class API



class wx.CloseEvent(Event)

Possible constructors:

CloseEvent(commandEventType=wxEVT_NULL, id=0)

This event class contains information about window and session close events.


Methods



__init__(self, commandEventType=wxEVT_NULL, id=0)

Constructor.

Parameters:
  • commandEventType (wx.EventType) –
  • id (int) –


CanVeto(self)

Returns True if you can veto a system shutdown or a window close event.

Vetoing a window close event is not possible if the calling code wishes to force the application to exit, and so this function must be called to check this.

Return type:bool


GetLoggingOff(self)

Returns True if the user is just logging off or False if the system is shutting down.

This method can only be called for end session and query end session events, it doesn’t make sense for close window event.

Return type:bool


GetVeto(self)

Returns whether the Veto flag was set.

Return type:bool


SetCanVeto(self, canVeto)

Sets the ‘can veto’ flag.

Parameters:canVeto (bool) –


SetLoggingOff(self, loggingOff)

Sets the ‘logging off’ flag.

Parameters:loggingOff (bool) –


Veto(self, veto=True)

Call this from your event handler to veto a system shutdown or to signal to the calling application that a window close did not happen.

You can only veto a shutdown if CanVeto returns True.

Parameters:veto (bool) –

Properties



LoggingOff

See GetLoggingOff and SetLoggingOff