Package Editra :: Package src :: Package extern :: Module pubsub
[hide private]

Module pubsub

source code

This module provides a publish-subscribe component that allows listeners to subcribe to messages of a given topic. Contrary to the original wxPython.lib.pubsub module (which it is based on), it uses weak referencing to the subscribers so the lifetime of subscribers is not affected by Publisher. Also, callable objects can be used in addition to functions and bound methods. See Publisher class docs for more details.

Thanks to Robb Shecter and Robin Dunn for having provided the basis for this module (which now shares most of the concepts but very little design or implementation with the original wxPython.lib.pubsub).

The publisher is a singleton instance of the PublisherClass class. You access the instance via the Publisher object available from the module:

   from wx.lib.pubsub import Publisher
   Publisher().subscribe(...)
   Publisher().sendMessage(...)
   ...

:Author: Oliver Schoenborn :Since: Apr 2004 :Version: $Id: pubsub.py 51098 2008-01-08 08:29:23Z CJP $ :Copyright: \(c) 2004 Oliver Schoenborn :License: wxWidgets

Classes [hide private]
  _WeakMethod
Represent a weak bound method, i.e.
  _NodeCallback
Encapsulate a weak reference to a method of a TopicTreeNode in such a way that the method can be called, if the node is still alive, but the callback does not *keep* the node alive.
  _TopicTreeNode
A node in the topic tree.
  _TopicTreeRoot
The root of the tree knows how to access other node of the tree and is the gateway of the tree user to the tree nodes.
  _SingletonKey
  PublisherClass
The publish/subscribe manager.
  Message
A simple container object for the two components of a message: the topic and the user data.
Functions [hide private]
 
_isbound(method)
Return true if method is a bound method, false otherwise
source code
 
_paramMinCountFunc(function)
Given a function, return pair (min,d) where min is minimum # of args required, and d is number of default arguments.
source code
 
_paramMinCount(callableObject)
Given a callable object (function, method or callable instance), return pair (min,d) where min is minimum # of args required, and d is number of default arguments.
source code
 
_tupleize(items)
Convert items to tuple if not already one, so items must be a list, tuple or non-sequence
source code
 
_getCallableName(callable)
Get name for a callable, ie function, bound method or callable instance
source code
 
_removeItem(item, fromList)
Attempt to remove item from fromList, return true if successful, false otherwise.
source code
 
_getWeakRef(obj, notifyDead=None)
Get a weak reference to obj.
source code
 
getStrAllTopics()
Function to call if, for whatever reason, you need to know explicitely what is the string to use to indicate 'all topics'.
source code
 
test() source code
Variables [hide private]
  _implNotes = '\nImplementation notes\n--------------------\n\n...
  ALL_TOPICS = ''
  _key = _SingletonKey()
  Publisher = PublisherClass(_key)
Function Details [hide private]

_paramMinCount(callableObject)

source code 

Given a callable object (function, method or callable instance), return pair (min,d) where min is minimum # of args required, and d is number of default arguments. The 'self' parameter, in the case of methods, is not counted.

_getWeakRef(obj, notifyDead=None)

source code 

Get a weak reference to obj. If obj is a bound method, a _WeakMethod object, that behaves like a WeakRef, is returned, if it is anything else a WeakRef is returned. If obj is an unbound method, a ValueError will be raised.


Variables Details [hide private]

_implNotes

Value:
'''
Implementation notes
--------------------

In class Publisher, I represent the topics-listener set as a tree
where each node is a topic, and contains a list of listeners of that
topic, and a dictionary of subtopics of that topic. When the Publisher
is told to send a message for a given topic, it traverses the tree
...