wx.EvtHandler

Inheritance diagram for 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

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 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 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).

The normal order of event table searching is as follows:

  1. If the object is disabled (via a call to SetEvtHandlerEnabled) the function skips to step (6).
  2. If the object is a wx.Window, 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, ProcessEvent is recursively applied to the parent window’s event handler. If this returns True, the function exits.
  6. Finally, ProcessEvent is called on the wx.App object.

Class API

Methods

__init__()
No docstrings found for this method.

AddPendingEvent(event)

This function posts an event to be processed later.

Parameters:

  • event (wx.Event): Event to add to process queue.

Note

The difference between sending an event (using the 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).


Bind(event, handler, source=None, id=-1, id2=-1)

Bind an event to an event handler.

Parameters:

  • event (wx.Event): 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.

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.

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 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


GetEvtHandlerEnabled()

Returns True if the event handler is enabled, False otherwise.


Returns:

bool


GetNextHandler()

Gets the pointer to the next handler in the chain.


Returns:

wx.EvtHandler


GetPreviousHandler()

Gets the pointer to the previous handler in the chain.


Returns:

wx.EvtHandler


ProcessEvent(event)

Processes an event, searching event tables and calling zero or more suitable event handler function(s).

Parameters:


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 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 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) the function skips to step (6).
  2. If the object is a wx.Window, 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, ProcessEvent is recursively applied to the parent window’s event handler. If this returns True, the function exits.
  6. Finally, ProcessEvent is called on the wx.App object.

ProcessPendingEvents()
No docstrings found for this 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.


SetNextHandler(handler)

Sets the pointer to the next handler.

Parameters:

  • handler (wx.EvtHandler): Event handler to be set as the next handler.

SetPreviousHandler(handler)

Sets the pointer to the previous handler.

Parameters:

  • handler (wx.EvtHandler): Event handler to be set as the previous handler.

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): 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

EvtHandlerEnabled
See GetEvtHandlerEnabled and SetEvtHandlerEnabled
NextHandler
See GetNextHandler and SetNextHandler
PreviousHandler
See GetPreviousHandler and SetPreviousHandler