~brian-sidebotham/wxwidgets-cmake/wxpython-2.9.4

« back to all changes in this revision

Viewing changes to wxPython/samples/pubsub/advanced/kwargs_listeners.py

  • Committer: Brian Sidebotham
  • Date: 2013-08-03 14:30:08 UTC
  • Revision ID: brian.sidebotham@gmail.com-20130803143008-c7806tkych1tp6fc
Initial import into Bazaar

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
'''
 
2
 
 
3
:copyright: Copyright 2006-2009 by Oliver Schoenborn, all rights reserved.
 
4
:license: BSD, see LICENSE.txt for details.
 
5
'''
 
6
 
 
7
from pubsub import pub
 
8
 
 
9
# ------------ create some listeners --------------
 
10
 
 
11
class Listener:
 
12
    def onTopic11(self, msg, msg2, extra=None):
 
13
        print 'Method Listener.onTopic11 received: ', `msg`, `msg2`, `extra`
 
14
 
 
15
    def onTopic1(self, msg, topic=pub.AUTO_TOPIC):
 
16
        info = 'Method Listener.onTopic1 received "%s" message: %s'
 
17
        print info % (topic.getName(), `msg`)
 
18
 
 
19
    def __call__(self, **kwargs):
 
20
        print 'Listener instance received: ', kwargs
 
21
 
 
22
listenerObj = Listener()
 
23
 
 
24
 
 
25
def listenerFn(msg, msg2, extra=None):
 
26
    print 'Function listenerFn received: ', `msg`, `msg2`, `extra`
 
27
 
 
28
# ------------ subscribe listeners ------------------
 
29
 
 
30
pub.subscribe(listenerObj, pub.ALL_TOPICS) # via its __call__
 
31
 
 
32
pub.subscribe(listenerFn, 'topic_1.subtopic_11')
 
33
pub.subscribe(listenerObj.onTopic11, 'topic_1.subtopic_11')
 
34
 
 
35
pub.subscribe(listenerObj.onTopic1, 'topic_1')
 
36