Class: Wx::CloseEvent
Overview
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 Window#close function. You should check whether the application is forcing the deletion of the window using #can_veto. If this is false, you must destroy the window using 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 #veto to let the calling code know that you did not destroy the window. This allows the Window#close function to return true or false depending on whether the close instruction was honoured or not. Example of a CloseEvent handler:
def on_close(event)
if event.can_veto? && @file_not_saved
if Wx.message_box("The file has not been saved... continue closing?",
"Please confirm",
Wx::ICON_QUESTION | Wx::YES_NO) != Wx::YES)
event.veto
return
end
end
destroy # you may also do: event.skip
# since the default event handler does call #destroy too
end
See also samples/dialogs
for a full example of interrupting closing an application when there are e.g. unsaved files. 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 App#on_exit) 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 using this class
The following event-handler methods redirect the events to member method or handler blocks for CloseEvent events. Event handler methods:
-
EvtHandler#evt_close(meth = nil, &block): Process a EVT_CLOSE_WINDOW command event, supplying the member function. This event applies to Frame and Dialog classes.
-
EvtHandler#evt_query_end_session(meth = nil, &block): Process a EVT_QUERY_END_SESSION session event, supplying the member function. This event can be handled in App-derived class only.
-
EvtHandler#evt_end_session(meth = nil, &block): Process a EVT_END_SESSION session event, supplying the member function. This event can be handled in App-derived class only.
Category: Events
Instance Method Summary collapse
-
#can_veto ⇒ Boolean
(also: #can_veto?)
Returns true if you can veto a system shutdown or a window close event.
-
#get_logging_off ⇒ Boolean
(also: #logging_off)
Returns true if the user is just logging off or false if the system is shutting down.
-
#get_veto ⇒ Boolean
Returns whether the Veto flag was set.
-
#initialize(commandEventType = Wx::EVT_NULL, id = 0) ⇒ Wx::CloseEvent
constructor
Constructor.
-
#set_can_veto(canVeto) ⇒ void
(also: #can_veto=)
Sets the ‘can veto’ flag.
-
#set_logging_off(loggingOff) ⇒ void
(also: #logging_off=)
Sets the ‘logging off’ flag.
-
#veto(veto = true) ⇒ void
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.
Methods inherited from Event
#clone, #get_event_category, #get_event_object, #get_event_type, #get_id, #get_skipped, #get_timestamp, #is_command_event, #resume_propagation, #set_event_object, #set_event_type, #set_id, #set_timestamp, #should_propagate, #skip, #stop_propagation
Methods inherited from Object
#clone, #dup, #is_same_as, #un_share
Constructor Details
#initialize(commandEventType = Wx::EVT_NULL, id = 0) ⇒ Wx::CloseEvent
Constructor.
1780 |
# File 'lib/wx/doc/gen/events.rb', line 1780 def initialize(commandEventType=Wx::EVT_NULL, id=0) end |
Instance Method Details
#can_veto ⇒ Boolean Also known as: can_veto?
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.
1786 |
# File 'lib/wx/doc/gen/events.rb', line 1786 def can_veto; end |
#get_logging_off ⇒ Boolean Also known as: logging_off
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.
1793 |
# File 'lib/wx/doc/gen/events.rb', line 1793 def get_logging_off; end |
#get_veto ⇒ Boolean
Returns whether the Veto flag was set.
1817 |
# File 'lib/wx/doc/gen/events.rb', line 1817 def get_veto; end |
#set_can_veto(canVeto) ⇒ void Also known as: can_veto=
This method returns an undefined value.
Sets the ‘can veto’ flag.
1799 |
# File 'lib/wx/doc/gen/events.rb', line 1799 def set_can_veto(canVeto) end |
#set_logging_off(loggingOff) ⇒ void Also known as: logging_off=
This method returns an undefined value.
Sets the ‘logging off’ flag.
1805 |
# File 'lib/wx/doc/gen/events.rb', line 1805 def set_logging_off(loggingOff) end |
#veto(veto = true) ⇒ void
This method returns an undefined value.
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 #can_veto returns true.
1813 |
# File 'lib/wx/doc/gen/events.rb', line 1813 def veto(veto=true) end |