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
to be sent, to all function that listen to it.
"""
if self.__class__.__name__ in _listener:
for f, args in _listener[self.__class__.__name__]:
if self.__class__ in _listener:
for f, args in _listener[self.__class__]:
f(self, *args)
@classmethod
def listen(cls, *args):
def wrap(f):
if cls.__name__ not in _listener:
_listener[cls.__name__] = []
_listener[cls.__name__].append((f, args))
if cls not in _listener:
_listener[cls] = []
_listener[cls].append((f, args))
# next step allow us to call the function itself without Event raised
def wrapped_f(*args):