************* wx.EvtHandler ************* Inheritance diagram for `wx.EvtHandler`: | .. inheritance-diagram:: wx.EvtHandler | Description =========== A class that can handle events from the windowing system. `wx.Window `_ (and therefore all window classes) are derived from this class. When events are received, `wx.EvtHandler` invokes the method listed in the event table using itself as the object. When using multiple inheritance it is imperative that the `wx.EvtHandler` (-derived) class be the first class inherited such that the "self" pointer for the overall object will be identical to the "self" pointer for the `wx.EvtHandler` portion. Derived From ^^^^^^^^^^^^^ * `wx.Object `_ Known Subclasses ^^^^^^^^^^^^^^^^ `wx.App `_, `wx.BitmapButton `_, `wx.BookCtrlBase`, `wx.Button `_, `wx.CheckBox `_, `wx.CheckListBox `_, `wx.Choice `_, `wx.Choicebook `_, `wx.CollapsiblePane `_, `wx.ColourDialog `_, `wx.ColourPickerCtrl `_, `wx.ComboBox `_, `wx.ContextHelpButton `_, `wx.Control `_, `wx.ControlWithItems `_, `wx.DatePickerCtrl `_, `wx.DatePickerCtrlBase`, `wx.Dialog `_, `wx.DirDialog `_, `wx.DirFilterListCtrl`, `wx.DirPickerCtrl `_, `wx.FileDialog `_, `wx.FilePickerCtrl `_, `wx.FindReplaceDialog `_, `wx.FontDialog `_, `wx.FontPickerCtrl `_, `wx.Frame `_, `wx.Gauge `_, `wx.GenericDatePickerCtrl`, `wx.GenericDirCtrl `_, `wx.HtmlListBox `_, `wx.HyperlinkCtrl `_, `wx.ListBox `_, `wx.ListCtrl `_, `wx.ListView `_, `wx.Listbook `_, `wx.MDIChildFrame `_, `wx.MDIClientWindow `_, `wx.MDIParentFrame `_, `wx.Menu `_, `wx.MenuBar `_, `wx.MessageDialog `_, `wx.MiniFrame `_, `wx.MultiChoiceDialog `_, `wx.Notebook `_, `wx.NotebookPage`, `wx.NumberEntryDialog`, `wx.Panel `_, `wx.PasswordEntryDialog `_, `wx.PickerBase `_, `wx.PopupTransientWindow `_, `wx.PopupWindow `_, `wx.PreviewCanvas `_, `wx.PreviewControlBar `_, `wx.PreviewFrame `_, `wx.Process `_, `wx.ProgressDialog `_, `wx.PyApp `_, `wx.PyAxBaseWindow `_, `wx.PyControl `_, `wx.PyEvtHandler `_, `wx.PyPanel `_, `wx.PyPreviewControlBar `_, `wx.PyPreviewFrame `_, `wx.PyScrolledWindow `_, `wx.PySimpleApp `_, `wx.PyTimer `_, `wx.PyValidator `_, `wx.PyWidgetTester `_, `wx.PyWindow `_, `wx.RadioBox `_, `wx.RadioButton `_, `wx.SashLayoutWindow `_, `wx.SashWindow `_, `wx.ScrollBar `_, `wx.ScrolledWindow `_, `wx.SearchCtrl `_, `wx.SimpleHtmlListBox `_, `wx.SingleChoiceDialog `_, `wx.Slider `_, `wx.SpinButton `_, `wx.SpinCtrl `_, `wx.SplashScreen `_, `wx.SplashScreenWindow`, `wx.SplitterWindow `_, `wx.StaticBitmap `_, `wx.StaticBox `_, `wx.StaticLine `_, `wx.StaticText `_, `wx.StatusBar `_, `wx.TaskBarIcon `_, `wx.TextCtrl `_, `wx.TextEntryDialog `_, `wx.Timer `_, `wx.TipWindow `_, `wx.ToggleButton `_, `wx.ToolBar `_, `wx.ToolBarBase`, `wx.Toolbook `_, `wx.TopLevelWindow `_, `wx.TreeCtrl `_, `wx.Treebook `_, `wx.VListBox `_, `wx.VScrolledWindow `_, `wx.Validator `_, `wx.Window `_ Remarks ^^^^^^^ The difference between sending an event (using the `ProcessEvent <#ProcessEvent>`_ method) and posting it is that in the first case the event is processed before the function returns, while in the second case, the function returns immediately and the event will be processed sometime later (usually during the next event loop iteration). A copy of `event` is made by the function, so the original can be deleted as soon as function returns (it is common that the original is created on the stack). This requires that the `wx.Event.Clone <../Events/wx.Event.html#Clone>`_ method be implemented by `event` so that it can be duplicated and stored until it gets processed. This is also the method to call for inter-thread communication - it will post events safely between different threads which means that this method is thread-safe by using critical sections where needed. In a multi-threaded program, you often need to inform the main GUI thread about the status of other working threads and such notification should be done using this method. This method automatically wakes up idle handling if the underlying window system is currently idle and thus would not send any idle events. (Waking up idle handling is done calling `wx.WakeUpIdle <../wxFunctions.html#WakeUpIdle>`_). The normal order of event table searching is as follows: 1. If the object is disabled (via a call to `SetEvtHandlerEnabled <#SetEvtHandlerEnabled>`_) the function skips to step (6). 2. If the object is a `wx.Window `_, `ProcessEvent <#ProcessEvent>`_ is recursively called on the window's `wx.Validator `_. If this returns ``True``, the function exits. 3. wxWidgets `SearchEventTable` is called for this event handler. If this fails, the base class table is tried, and so on until no more tables exist or an appropriate function was found, in which case the function exits. 4. The search is applied down the entire chain of event handlers (usually the chain has a length of one). If this succeeds, the function exits. 5. If the object is a `wx.Window `_ and the event is a `wx.CommandEvent <../Events/wx.CommandEvent.html>`_, `ProcessEvent <#ProcessEvent>`_ is recursively applied to the parent window's event handler. If this returns ``True``, the function exits. 6. Finally, `ProcessEvent <#ProcessEvent>`_ is called on the `wx.App `_ object. Methods Summary ^^^^^^^^^^^^^^^ * `__init__ <#__init__>`_ * `AddPendingEvent <#AddPendingEvent>`_ * `Bind <#Bind>`_ * `Connect <#Connect>`_ * `Disconnect <#Disconnect>`_ * `GetEvtHandlerEnabled <#GetEvtHandlerEnabled>`_ * `GetNextHandler <#GetNextHandler>`_ * `GetPreviousHandler <#GetPreviousHandler>`_ * `ProcessEvent <#ProcessEvent>`_ * `ProcessPendingEvents <#ProcessPendingEvents>`_ * `SetEvtHandlerEnabled <#SetEvtHandlerEnabled>`_ * `SetNextHandler <#SetNextHandler>`_ * `SetPreviousHandler <#SetPreviousHandler>`_ * `Unbind <#Unbind>`_ Properties Summary ^^^^^^^^^^^^^^^^^^ * `EvtHandlerEnabled <#EvtHandlerEnabled>`_ * `NextHandler <#NextHandler>`_ * `PreviousHandler <#PreviousHandler>`_ Class API ========= Methods ^^^^^^^ .. method:: __init__() `No docstrings found for this method.` -------- .. method:: AddPendingEvent(event) This function posts an event to be processed later. **Parameters:** * `event` (`wx.Event <../Events/wx.Event.html>`_): Event to add to process queue. .. note:: The difference between sending an event (using the `ProcessEvent <#ProcessEvent>`_ method) and posting it is that in the first case the event is processed before the function returns, while in the second case, the function returns immediately and the event will be processed sometime later (usually during the next event loop iteration). -------- .. method:: Bind(event, handler, source=None, id=-1, id2=-1) Bind an event to an event handler. **Parameters:** * `event` (`wx.Event <../Events/wx.Event.html>`_): One of the ``wx.EVT_*`` objects that specifies the type of event to bind, * `handler` (PyObject): A callable object to be invoked when the event is delivered to self. Pass ``None`` to disconnect an event handler. * `source` (`wx.Window `_): Sometimes the event originates from a different window than self, but you still want to catch it in self. (For example, a button event delivered to a frame). By passing the source of the event, the event handling system is able to differentiate between the same event type from different controls. * `id` (int): Used to specify the event source by ID instead of instance. * `id2` (int): Used when it is desirable to bind a handler to a range of IDs, such as with ``wx.EVT_MENU_RANGE``. -------- .. method:: Connect(id, lastId, eventType) Connects the given function dynamically with the event handler, id and event type. This is an alternative to the use of static event tables. **Parameters:** * `id` (int): The identifier (or first of the identifier range) to be associated with the event handler function. For the version not taking this argument, it defaults to ``wx.ID_ANY``. * `lastId` (int): The second part of the identifier range to be associated with the event handler function. * `eventType` (`wx.Object `_): The event type to be associated with this event handler. -------- .. method:: Disconnect(id=wx.EVT_NONE, lastId=None, eventType=None) Disconnects the given function dynamically from the event handler, using the specified parameters as search criteria and returning ``True`` if a matching function has been found and removed. This method can only disconnect functions which have been added using the `Connect <#Connect>`_ method. **Parameters:** * `id` (int): The identifier (or first of the identifier range) associated with the event handler function. * `lastId` (int): The second part of the identifier range associated with the event handler function. * `eventType` (`wx.Object `_): The event type associated with this event handler. | **Returns:** `bool` -------- .. method:: GetEvtHandlerEnabled() Returns ``True`` if the event handler is enabled, ``False`` otherwise. | **Returns:** `bool` .. seealso:: `SetEvtHandlerEnabled <#SetEvtHandlerEnabled>`_ -------- .. method:: GetNextHandler() Gets the pointer to the next handler in the chain. | **Returns:** `wx.EvtHandler `_ .. seealso:: `SetNextHandler <#SetNextHandler>`_, `GetPreviousHandler <#GetPreviousHandler>`_, `SetPreviousHandler <#SetPreviousHandler>`_, `wx.Window.PushEventHandler `_, `wx.Window.PopEventHandler `_ -------- .. method:: GetPreviousHandler() Gets the pointer to the previous handler in the chain. | **Returns:** `wx.EvtHandler `_ .. seealso:: `SetPreviousHandler <#SetPreviousHandler>`_ , `GetNextHandler <#GetNextHandler>`_ , `SetNextHandler <#SetNextHandler>`_ , `wx.Window.PushEventHandler `_ , `wx.Window.PopEventHandler `_ -------- .. method:: ProcessEvent(event) Processes an event, searching event tables and calling zero or more suitable event handler function(s). **Parameters:** * `event` (`wx.Event <../Events/wx.Event.html>`_): Event to process. | **Returns:** `bool` .. note:: Normally, your application would not call this function: it is called in the wxWidgets implementation to dispatch incoming user interface events to the framework (and application). However, you might need to call it if implementing new functionality (such as a new control) where you define new event types, as opposed to allowing the user to override functions. An instance where you might actually override the `ProcessEvent <#ProcessEvent>`_ function is where you want to direct event processing to event handlers not normally noticed by wxWidgets. For example, in the document/view architecture, documents and views are potential event handlers. When an event reaches a frame, `ProcessEvent <#ProcessEvent>`_ will need to be called on the associated document and view in case event handler functions are associated with these objects. The normal order of event table searching is as follows: 1. If the object is disabled (via a call to `SetEvtHandlerEnabled <#SetEvtHandlerEnabled>`_) the function skips to step (6). 2. If the object is a `wx.Window `_, `ProcessEvent <#ProcessEvent>`_ is recursively called on the window's `wx.Validator `_. If this returns ``True``, the function exits. 3. wxWidgets `SearchEventTable` is called for this event handler. If this fails, the base class table is tried, and so on until no more tables exist or an appropriate function was found, in which case the function exits. 4. The search is applied down the entire chain of event handlers (usually the chain has a length of one). If this succeeds, the function exits. 5. If the object is a `wx.Window `_ and the event is a `wx.CommandEvent <../Events/wx.CommandEvent.html>`_, `ProcessEvent <#ProcessEvent>`_ is recursively applied to the parent window's event handler. If this returns ``True``, the function exits. 6. Finally, `ProcessEvent <#ProcessEvent>`_ is called on the `wx.App `_ object. -------- .. method:: ProcessPendingEvents() `No docstrings found for this method.` -------- .. method:: SetEvtHandlerEnabled(enabled) Enables or disables the event handler. **Parameters:** * `enabled` (bool): ``True`` if the event handler is to be enabled, ``False`` if it is to be disabled. .. note:: You can use this function to a having to remove the event handler from the chain, for example when implementing a dialog editor and changing from edit to test mode. .. seealso:: `GetEvtHandlerEnabled <#GetEvtHandlerEnabled>`_ -------- .. method:: SetNextHandler(handler) Sets the pointer to the next handler. **Parameters:** * `handler` (`wx.EvtHandler `_): Event handler to be set as the next handler. .. seealso:: `GetNextHandler <#GetNextHandler>`_, `SetPreviousHandler <#SetPreviousHandler>`_, `GetPreviousHandler <#GetPreviousHandler>`_, `wx.Window.PushEventHandler `_, `wx.Window.PopEventHandler `_ -------- .. method:: SetPreviousHandler(handler) Sets the pointer to the previous handler. **Parameters:** * `handler` (`wx.EvtHandler `_): Event handler to be set as the previous handler. -------- .. method:: Unbind(event, source=None, id=-1, id2=-1) Disconnects the event handler binding for event from self. Returns True if successful. **Parameters:** * `event` (`wx.Event <../Events/wx.Event.html>`_): Event to process. * `source` (`wx.Window `_): Sometimes the event originates from a different window than self, but you still want to catch it in self. (For example, a button event delivered to a frame). By passing the source of the event, the event handling system is able to differentiate between the same event type from different controls. * `id` (int): Used to specify the event source by ID instead of instance. * `id2` (int): Used when it is desirable to bind a handler to a range of IDs, such as with ``wx.EVT_MENU_RANGE``. -------- Properties ^^^^^^^^^^ .. attribute:: EvtHandlerEnabled See `GetEvtHandlerEnabled <#GetEvtHandlerEnabled>`_ and `SetEvtHandlerEnabled <#SetEvtHandlerEnabled>`_ .. attribute:: NextHandler See `GetNextHandler <#GetNextHandler>`_ and `SetNextHandler <#SetNextHandler>`_ .. attribute:: PreviousHandler See `GetPreviousHandler <#GetPreviousHandler>`_ and `SetPreviousHandler <#SetPreviousHandler>`_