enthought/encore — Issue #2: Can't use the same listener with different filters
Author: corranwebster
Created: 2012-01-03 21:11:12+00:00
State: open

In the events API you can't bind the same function callback to the same class with different filters. The actual behaviour is somewhat surprising:

from encore.events.api import EventManager, BaseEvent
em = EventManager()

def listener(event):
print event.source

em.connect(BaseEvent, listener, filter={'source': 1})
em.emit(BaseEvent(source=1)) # prints 1
em.emit(BaseEvent(source=2)) # doesn't fire
em.connect(BaseEvent, listener, filter={'source': 2})
em.emit(BaseEvent(source=1)) # doesn't fire
em.emit(BaseEvent(source=2)) # fires twice, printing 2 each time

I think it is reasonable to have the same callback bound with two different filters; however even if it isn't then binding the same function with a different filter should probably remove the old function.