Last active
July 30, 2017 14:34
-
-
Save nbassler/00976e3696d70d25a2fce5e36224367c to your computer and use it in GitHub Desktop.
pubsub example
This file contains hidden or 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
# first line below is necessary only in wxPython 2.8.11.0 since default | |
# API in this wxPython is pubsub version 1 (expect later versions | |
# of wxPython to use the kwargs API by default) | |
from wx.lib.pubsub import setupkwargs | |
# regular pubsub import | |
from wx.lib.pubsub import pub | |
class SomeReceiver(object): | |
def __init__(self): | |
pub.subscribe(self.__onObjectAdded, 'object.added') | |
def __onObjectAdded(self, data, extra1, extra2=None): | |
# no longer need to access data through message.data. | |
print('Object', repr(data), 'is added') | |
print(extra1) | |
if extra2: | |
print(extra2) | |
a = SomeReceiver() | |
pub.sendMessage('object.added', data=42, extra1='hello!') | |
pub.sendMessage('object.added', data=42, extra1='hello!', extra2=[2, 3, 5, 7, 11, 13, 17, 19, 23]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment