Provides utility functions and classes that are not required for using pubsub but are likely to be very useful.
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.
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 must 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()
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)
Derive your Notifications handler from this class if your handler just wants to be notified of one or two types of pubsub events. Then just override the desired methods. The rest of the notifications will automatically be ignored.
Example exception handler that simply publishes the exception traceback as a message of topic name given by topicUncaughtExc.
Must be called only after pubsub has been imported since this handler creates a pubsub topic.