Re: EventFilter Example Fails

Scott Talbert <[email protected]>
Newsgroups gmane.comp.python.wxpython.devel
Message-ID <[email protected]>
On Mon, 4 Apr 2016, [email protected] wrote:

> I tried a simplified version of the event filter example found
> at http://wxpython.org/Phoenix/docs/html/EventFilter.html
> 
> class KeyEventFilter(wx.EventFilter):
>     def __init__(self):
>         wx.EventFilter.__init__(self)
>         wx.EvtHandler.AddFilter(self)
> 
>     def __del__(self):
>         wx.EvtHandler.RemoveFilter(self)
> 
>     def FilterEvent(self, event):
>         t = event.GetEventType()
>         if t == wx.EVT_KEY_DOWN:
>             print "key down"
>         event.Skip()
> 
> When I try to instantiate the class
> 
>         filter = KeyEventFilter()
> 
> I get the following error message:
> 
> TypeError: wx._core.EventFilter cannot be instantiated or sub-classed
> 
> Is this example know to work?

It appears to be a bug.  This should fix it:
https://github.com/wxWidgets/Phoenix/pull/61

Also, the example documentation has some problems too.  Updated it in the 
PR.

In your sample, replace:

wx.EVT_KEY_DOWN -> wx.EVT_KEY_DOWN.typeId
event.Skip() -> self.Event_Skip

Scott
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.