events.py more clean

This commit is contained in:
Jonathan Grizou 2013-07-04 00:05:59 +02:00
parent 4a91c4953c
commit fa836aaad9

View File

@ -9,16 +9,16 @@ class Event(object):
""" This function sends the instance of the class, i.e. the event """ This function sends the instance of the class, i.e. the event
to be sent, to all function that listen to it. to be sent, to all function that listen to it.
""" """
if self.__class__.__name__ in _listener: if self.__class__ in _listener:
for f, args in _listener[self.__class__.__name__]: for f, args in _listener[self.__class__]:
f(self, *args) f(self, *args)
@classmethod @classmethod
def listen(cls, *args): def listen(cls, *args):
def wrap(f): def wrap(f):
if cls.__name__ not in _listener: if cls not in _listener:
_listener[cls.__name__] = [] _listener[cls] = []
_listener[cls.__name__].append((f, args)) _listener[cls].append((f, args))
# next step allow us to call the function itself without Event raised # next step allow us to call the function itself without Event raised
def wrapped_f(*args): def wrapped_f(*args):