.. 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.EventFilter: ========================================================================================================================================== |phoenix_title| **wx.EventFilter** ========================================================================================================================================== A global event filter for pre-processing all the events generated in the program. This is a very simple class which just provides :meth:`~wx.EventFilter.FilterEvent` virtual method to be called by :ref:`wx.EvtHandler` before starting process of any event. Thus, inheriting from this class and overriding :meth:`~wx.EventFilter.FilterEvent` allows to capture and possibly handle or ignore all the events happening in the program. Of course, having event filters adds additional overhead to every event processing and so should not be used lightly and your :meth:`~wx.EventFilter.FilterEvent` code should try to return as quickly as possible, especially for the events it is not interested in. An example of using this class: :: # This class allows to determine the last time the user has worked with # this application: class LastActivityTimeDetector(wx.EventFilter): def __init__(self): wx.EventFilter.__init__(self) wx.EvtHandler.AddFilter(self) self.last = wx.DateTime.Now() def __del__(self): wx.EvtHandler.RemoveFilter(self) def FilterEvent(self, event): # Update the last user activity t = event.GetEventType() if t == wx.EVT_KEY_DOWN.typeId or t == wx.EVT_MOTION.typeId or \ t == wx.EVT_LEFT_DOWN.typeId or t == wx.EVT_RIGHT_DOWN.typeId or \ t == wx.EVT_MIDDLE_DOWN.typeId: self.last = wx.DateTime.Now() # Continue processing the event normally as well. return self.Event_Skip # This function could be called periodically from some timer to # do something (e.g. hide sensitive data or log out from remote # server) if the user has been inactive for some time period. def IsInactiveFor(self, diff): return wx.DateTime.Now() - diff > self.last Notice that :ref:`wx.App` derives from :ref:`wx.EventFilter` and is registered as an event filter during its creation so you may also override :meth:`~wx.EventFilter.FilterEvent` method in your App-derived class and, in fact, this is often the most convenient way to do it. However creating a new class deriving directly from :ref:`wx.EventFilter` allows to isolate the event filtering code in its own separate class and also to have several independent filters, if necessary. .. versionadded:: 2.9.3 | |class_hierarchy| Class Hierarchy ================================= .. raw:: html