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
|
.. 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
<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>EventFilter</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.EventFilter_inheritance.png" alt="Inheritance diagram of EventFilter" 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.EventFilter.html" title="wx.EventFilter" alt="" coords="5,5,112,35"/> </map>
</p>
|
|sub_classes| Known Subclasses
==============================
:ref:`wx.AppConsole`
|
|method_summary| Methods Summary
================================
================================================================================ ================================================================================
:meth:`~wx.EventFilter.__init__` Default constructor.
:meth:`~wx.EventFilter.FilterEvent` Override this method to implement event pre-processing.
================================================================================ ================================================================================
|
|api| Class API
===============
.. class:: wx.EventFilter(object)
**Possible constructors**::
EventFilter()
A global event filter for pre-processing all the events generated in
the program.
.. method:: __init__(self)
Default constructor.
Constructor does not register this filter using :meth:`wx.EvtHandler.AddFilter` , it's your responsibility to do it when necessary.
Notice that the objects of this class can't be copied.
.. method:: FilterEvent(self, event)
Override this method to implement event pre-processing.
This method allows to filter all the events processed by the program, so you should try to return quickly from it to avoid slowing down the program to a crawl.
Although the return type of this method is ``int`` , this is only due to backwards compatibility concerns and the actual return value must be one of the ``Event_XXX`` constants defined above:
- Event_Skip to continue processing the event normally (this should be used in most cases).
- Event_Ignore to not process this event at all (this can be used to suppress some events).
- Event_Processed to not process this event normally but indicate that it was already processed by the event filter and so no default processing should take place neither (this should only be used if the filter really did process the event).
:param `event`:
:type `event`: wx.Event
:rtype: `int`
|