def useNotifyByPubsubMessage(publisher=None, all=True, **kwargs): '''Will cause all of pubsub's notifications of pubsub "actions" (such as new topic created, message sent, listener subscribed, etc) to be sent out as messages. Topic will be 'pubsub' subtopics, such as 'pubsub.newTopic', 'pubsub.delTopic', 'pubsub.sendMessage', etc. The 'all' and kwargs args are the same as pubsub's setNotificationFlags(), except that 'all' defaults to True. The publisher is rarely needed: * The publisher only needs to be specfied if pubsub is not installed on the system search path (ie from pubsub import ... would fail or import wrong pubsub -- such as if pubsub is within wxPython's wx.lib package). Then pbuModule is the pub module to use:: from wx.lib.pubsub import pub from wx.lib.pubsub.utils import notification notification.useNotifyByPubsubMessage() ''' if publisher is None: from intraimport import parentImport pub = parentImport('pub') publisher = pub.getDefaultPublisher() topicMgr = publisher.getTopicMgr() notifHandler = NotifyByPubsubMessage(topicMgr) publisher.addNotificationHandler(notifHandler) publisher.setNotificationFlags(all=all, **kwargs)
def printTreeDocs(rootTopic=None, topicMgr=None, **kwargs): '''Print out the topic tree to a file (or file-like object like a StringIO), starting at rootTopic. If root topic should be root of whole tree, get it from pub.getDefaultTopicTreeRoot(). The treeVisitor is an instance of pub.TopicTreeTraverser. Printing the tree docs would normally involve this:: from pubsub import pub from pubsub.utils.topictreeprinter import TopicTreePrinter traverser = pub.TopicTreeTraverser( TopicTreePrinter(**kwargs) ) traverser.traverse( pub.getDefaultTopicTreeRoot() ) With printTreeDocs, it looks like this:: from pubsub import pub from pubsub.utils import printTreeDocs printTreeDocs() The kwargs are the same as for TopicTreePrinter constructor: extra(None), width(70), indentStep(4), bulletTopic, bulletTopicItem, bulletTopicArg, fileObj(stdout). If fileObj not given, stdout is used.''' if rootTopic is None: if topicMgr is None: from intraimport import parentImport pub = parentImport('pub') topicMgr = pub.getDefaultTopicMgr() rootTopic = topicMgr.getRootTopic() printer = TopicTreePrinter(**kwargs) from core.topictreetraverser import TopicTreeTraverser traverser = TopicTreeTraverser(printer) traverser.traverse(rootTopic)
def useNotifyByPubsubMessage(publisher=None, all=True, **kwargs): '''Will cause all of pubsub's notifications of pubsub "actions" (such as new topic created, message sent, listener subscribed, etc) to be sent out as messages. Topic will be 'pubsub' subtopics, such as 'pubsub.newTopic', 'pubsub.delTopic', 'pubsub.sendMessage', etc. The 'all' and kwargs args are the same as pubsub's setNotificationFlags(), except that 'all' defaults to True. The publisher is rarely needed: * The publisher only needs to be specfied if pubsub is not installed on the system search path (ie from pubsub import ... would fail or import wrong pubsub -- such as if pubsub is within wxPython's wx.lib package). Then pbuModule is the pub module to use:: from wx.lib.pubsub import pub from wx.lib.pubsub.utils import notification notification.useNotifyByPubsubMessage() ''' if publisher is None: from intraimport import parentImport pub = parentImport('pub') publisher = pub.getDefaultPublisher() topicMgr = publisher.getTopicMgr() notifHandler = NotifyByPubsubMessage( topicMgr ) publisher.addNotificationHandler(notifHandler) publisher.setNotificationFlags(all=all, **kwargs)
def useNotifyByWriteFile(fileObj=None, prefix=None, publisher=None, all=True, **kwargs): '''Will cause all pubsub notifications of pubsub "actions" (such as new topic created, message sent, listener died etc) to be written to specified file (or stdout if none given). The fileObj need only provide a 'write(string)' method. The first two arguments are the same as those of NotifyByWriteFile constructor. The 'all' and kwargs arguments are those of pubsub's setNotificationFlags(), except that 'all' defaults to True. See useNotifyByPubsubMessage() for an explanation of pubModule (typically only if pubsub inside wxPython's wx.lib)''' notifHandler = NotifyByWriteFile(fileObj, prefix) if publisher is None: from intraimport import parentImport pub = parentImport('pub') publisher = pub.getDefaultPublisher() publisher.addNotificationHandler(notifHandler) publisher.setNotificationFlags(all=all, **kwargs)