]> git.saurik.com Git - wxWidgets.git/commitdiff
Publisher is now able to parse a dotted notation string
authorRobin Dunn <robin@alldunn.com>
Mon, 6 Mar 2006 20:17:20 +0000 (20:17 +0000)
committerRobin Dunn <robin@alldunn.com>
Mon, 6 Mar 2006 20:17:20 +0000 (20:17 +0000)
into a topic tuple.  For example: subscribing to "timer.clock.seconds"
is the same as subscribing to ("timer", "clock", "seconds").

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@37831 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

wxPython/wx/lib/pubsub.py

index ba36e70cd2df431c444492acffd1c397c500b190..05a180a362d3c14fabd0901688b32b3e23e9b570 100644 (file)
@@ -39,7 +39,7 @@ Ideally, _TopicTreeNode would be a generic _TreeNode with named
 subnodes, and _TopicTreeRoot would be a generic _Tree with named
 nodes, and Publisher would store listeners in each node and a topic
 tuple would be converted to a path in the tree.  This would lead to a
-much cleaner separation of concerns. But time is over, tim to move on.
+much cleaner separation of concerns. But time is over, time to move on.
 
 """
 #---------------------------------------------------------------------------
@@ -90,9 +90,11 @@ def _paramMinCount(callableObject):
 def _tupleize(items):
     """Convert items to tuple if not already one, 
     so items must be a list, tuple or non-sequence"""
-    if isinstance(items, type([])):
+    if isinstance(items, list):
         raise TypeError, 'Not allowed to tuple-ize a list'
-    elif not isinstance(items, type(())):
+    elif isinstance(items, (str, unicode)) and items.find('.') != -1:
+        items = tuple(items.split('.'))
+    elif not isinstance(items, tuple):
         items = (items,)
     return items
 
@@ -561,10 +563,11 @@ class Publisher:
       with only one argument. In every case, the parameter 'a' will contain
       the message. 
 
-    - topic: a single word or tuple of words (though word could probably 
-      be any kind of object, not just a string, but this has not been 
-      tested). A tuple denotes a hierarchy of topics from most general
-      to least. For example, a listener of this topic::
+    - topic: a single word, a tuple of words, or a string containing a
+      set of words separated by dots, for example: 'sports.baseball'.
+      A tuple or a dotted notation string denotes a hierarchy of
+      topics from most general to least. For example, a listener of
+      this topic::
 
           ('sports','baseball')
 
@@ -614,11 +617,11 @@ class Publisher:
         listener will be subscribed for all topics (that listener will 
         receive a Message for any topic for which a message is generated). 
         
-        This method may be
-        called multiple times for one listener, registering it with
-        many topics.  It can also be invoked many times for a
-        particular topic, each time with a different listener.
-        See the class doc for requirements on listener and topic.
+        This method may be called multiple times for one listener,
+        registering it with many topics.  It can also be invoked many
+        times for a particular topic, each time with a different
+        listener.  See the class doc for requirements on listener and
+        topic.
 
         :note: Calling 
         this method for the same listener, with two topics in the same 
@@ -691,7 +694,7 @@ class Publisher:
             return
         
         # make sure every topics are in tuple form
-        if isinstance(topics, type([])):
+        if isinstance(topics, list):
             topicList = [_tupleize(x) for x in topics]
         else:
             topicList = [_tupleize(topics)]