Last active
August 29, 2015 14:05
-
-
Save emptypage/289e2adacee94703b1c7 to your computer and use it in GitHub Desktop.
Sample for event.py (improved) http://emptypage.jp/notes/pyevent.en.html
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
#!/usr/bin/env python | |
"""Sample script which uses event.py (improved). """ | |
import event | |
class Publisher(object): | |
# Set event object in class declaration. | |
evt_foo = event.Event('here comes foo') | |
def foo(self): | |
# Do some actions and fire event. | |
self.evt_foo() | |
# Event handler may be a function or a instance method etc. | |
# Every handler must accept two arguments; a sender and an event-specific | |
# parameter. | |
def handle_foo(sender, earg): | |
print 'foo!' | |
if __name__ == '__main__': | |
pub = Publisher() | |
# Add event handler | |
pub.evt_foo += handle_foo | |
# This will cause Publiser.evt_foo event. | |
pub.foo() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment