def testNotifications(): capture = io.StringIO() logger = notification.useNotifyByWriteFile(capture) from pubsub import pub def block(): def listener(): pass pub.subscribe(listener, 'testNotifications') block()
def testNotifications(): capture = io.StringIO() logger = notification.useNotifyByWriteFile(capture) from pubsub import pub def block(): def listener(): pass pub.subscribe(listener, 'testNotifications') block()
:copyright: Copyright since 2006 by Oliver Schoenborn, all rights reserved. :license: BSD, see LICENSE.txt for details. """ import wx from pubsub import pub from pubsub.py2and3 import print_ print_('pubsub API version', pub.VERSION_API) # notification from pubsub.utils.notification import useNotifyByWriteFile import sys useNotifyByWriteFile(sys.stdout) # the following two modules don't know about each other yet will # exchange data via pubsub: from wx_win1 import View from wx_win2 import ChangerWidget class Model: def __init__(self): self.myMoney = 0 def addMoney(self, value): self.myMoney += value #now tell anyone who cares that the value has been changed
""" :copyright: Copyright since 2006 by Oliver Schoenborn, all rights reserved. :license: BSD, see LICENSE.txt for details. """ import sys from pubsub import pub from pubsub.utils.notification import useNotifyByWriteFile, IgnoreNotificationsMixin # create one special notification handler that ignores all except # one type of notification class MyPubsubNotifHandler(IgnoreNotificationsMixin): def notifySubscribe(self, pubListener, topicObj, newSub): newSubMsg = '' if not newSub: newSubMsg = ' was already' msg = 'MyPubsubNotifHandler: listener %s%s subscribed to %s' print(msg % (pubListener.name(), newSubMsg, topicObj.getName())) pub.addNotificationHandler(MyPubsubNotifHandler()) # print(all notifications to stdout) useNotifyByWriteFile(sys.stdout, prefix='NotifyByWriteFile:')
def captureStdout(): capture = io.StringIO() useNotifyByWriteFile( fileObj = capture ) return capture
def captureStdout(): capture = io.StringIO() useNotifyByWriteFile(fileObj=capture) return capture