1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
|
.. wxPython Phoenix documentation
This file was generated by Phoenix's sphinx generator and associated
tools, do not edit by hand.
Copyright: (c) 2011-2018 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>
</div>
<script type="text/javascript">toggleVisibilityOnLoad(document.getElementById('toggleBlock'))</script>
<map id="dummy" name="dummy"> <area shape="rect" id="node1" href="wx.Event.html" title="wx.Event" alt="" coords="22,83,100,112"/> <area shape="rect" id="node3" href="wx.CloseEvent.html" title="wx.CloseEvent" alt="" coords="5,160,117,189"/> <area shape="rect" id="node2" href="wx.Object.html" title="wx.Object" alt="" coords="20,5,101,35"/> </map>
</p>
|
|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`
|