Skip to content

Instantly share code, notes, and snippets.

@emptypage
Created August 16, 2014 16:18
Show Gist options
  • Save emptypage/70b5dc97e4499f825d11 to your computer and use it in GitHub Desktop.
Save emptypage/70b5dc97e4499f825d11 to your computer and use it in GitHub Desktop.
Sample for event.py (simple) http://emptypage.jp/notes/pyevent.en.html
#!/usr/bin/env python
"""Sample script which uses event.py (simple). """
import event
class Publisher(object):
def __init__(self):
# Set event object
self.evt_foo = event.Event()
def foo(self):
# Call event object with self as a sender
self.evt_foo(self)
# 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