Created
March 8, 2012 17:12
-
-
Save Nooby/2002126 to your computer and use it in GitHub Desktop.
Simple Events for Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EventHook(object): | |
def __init__(self): | |
self.__handlers = [] | |
def __iadd__(self, handler): | |
self.__handlers.append(handler) | |
return self | |
def __isub__(self, handler): | |
self.__handlers.remove(handler) | |
return self | |
def fire(self, *args, **keywargs): | |
for handler in self.__handlers: | |
handler(*args, **keywargs) | |
def clearObjectHandlers(self, inObject): | |
for theHandler in self.__handlers: | |
if theHandler.im_self == inObject: | |
self -= theHandler |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment