.. wxPython Phoenix documentation

   This file was generated by Phoenix's sphinx generator and associated
   tools, do not edit by hand.

   Copyright: (c) 2011-2020 by Total Control Software
   License:   wxWindows License

.. include:: headings.inc



.. _wx.CloseEvent:

==========================================================================================================================================
|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 :meth:`wx.Window.Close`   function. 

You should check whether the application is forcing the deletion of the window using :meth:`wx.CloseEvent.CanVeto` . If this is ``False``, you `must`  destroy the window using :meth:`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 :meth:`wx.CloseEvent.Veto`   to let the calling code know that you did not destroy the window. This allows the :meth:`wx.Window.Close`   function to return ``True`` or ``False`` depending on whether the close instruction was honoured or not. 

Example of a :ref:`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 :meth:`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). 







.. _CloseEvent-events:

|events| Events Emitted by this Class
=====================================

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

Event macros: 

- EVT_CLOSE: Process a  ``wxEVT_CLOSE_WINDOW``   command event, supplying the member function. This event applies to  :ref:`wx.Frame`  and :ref:`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.   








         



.. seealso:: :meth:`wx.Window.Close` , :ref:`Window Deletion <window deletion>`    







|

|class_hierarchy| Class Hierarchy
=================================

.. raw:: html

   <div id="toggleBlock" onclick="return toggleVisibility(this)" class="closed" style="cursor:pointer;">
   <img id="toggleBlock-trigger" src="_static/images/closed.png"/>
   Inheritance diagram for class <strong>CloseEvent</strong>:
   </div>
   <div id="toggleBlock-summary" style="display:block;"></div>
   <div id="toggleBlock-content" style="display:none;">
   <p class="graphviz">
   <center><img src="_static/images/inheritance/wx.CloseEvent_inheritance.png" alt="Inheritance diagram of CloseEvent" usemap="#dummy" class="inheritance"/></center>
   <script type="text/javascript">toggleVisibilityOnLoad(document.getElementById('toggleBlock'))</script>
   <map id="dummy" name="dummy"> <area shape="rect" id="node1" href="wx.CloseEvent.html" title="wx.CloseEvent" alt="" coords="5,160,124,189"/> <area shape="rect" id="node2" href="wx.Event.html" title="wx.Event" alt="" coords="23,83,106,112"/> <area shape="rect" id="node3" href="wx.Object.html" title="wx.Object" alt="" coords="21,5,108,35"/> </map> 
   </p>
   </div>

|


|method_summary| Methods Summary
================================

================================================================================ ================================================================================
:meth:`~wx.CloseEvent.__init__`                                                  Constructor.
:meth:`~wx.CloseEvent.CanVeto`                                                   Returns ``True`` if you can veto a system shutdown or a window close event.
:meth:`~wx.CloseEvent.GetLoggingOff`                                             Returns ``True`` if the user is just logging off or ``False`` if the system is shutting down.
:meth:`~wx.CloseEvent.GetVeto`                                                   Returns whether the Veto flag was set.
:meth:`~wx.CloseEvent.SetCanVeto`                                                Sets the 'can veto' flag.
:meth:`~wx.CloseEvent.SetLoggingOff`                                             Sets the 'logging off' flag.
:meth:`~wx.CloseEvent.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
=====================================

================================================================================ ================================================================================
:attr:`~wx.CloseEvent.LoggingOff`                                                See :meth:`~wx.CloseEvent.GetLoggingOff` and :meth:`~wx.CloseEvent.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.



   .. method:: __init__(self, commandEventType=wxEVT_NULL, id=0)

      Constructor.                  


      :param `commandEventType`: 
      :type `commandEventType`: wx.EventType
      :param `id`: 
      :type `id`: int







   .. method:: 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.                  

      :rtype: `bool`








   .. method:: 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.                  

      :rtype: `bool`








   .. method:: GetVeto(self)

      Returns whether the Veto flag was set.                  

      :rtype: `bool`








   .. method:: SetCanVeto(self, canVeto)

      Sets the 'can veto' flag.                  


      :param `canVeto`: 
      :type `canVeto`: bool







   .. method:: SetLoggingOff(self, loggingOff)

      Sets the 'logging off' flag.                  


      :param `loggingOff`: 
      :type `loggingOff`: bool







   .. method:: 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 :meth:`CanVeto`   returns ``True``.                  


      :param `veto`: 
      :type `veto`: bool







   .. attribute:: LoggingOff

      See :meth:`~wx.CloseEvent.GetLoggingOff` and :meth:`~wx.CloseEvent.SetLoggingOff`

