You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
548 B

  1. from collections import defaultdict
  2. __ALL__ = ['pub']
  3. class PubSub(object):
  4. '''
  5. A super simplified clone of Wx.lib.pubsub since it doesn't exist on linux
  6. *grumble grumble* Stupid abandoned wx project... >:( *grumble*
  7. '''
  8. def __init__(self):
  9. self.registry = defaultdict(list)
  10. def subscribe(self, handler, event):
  11. self.registry[event].append(handler)
  12. def send_message(self, event, **kwargs):
  13. for event_handler in self.registry.get(event, []):
  14. event_handler(**kwargs)
  15. pub = PubSub()