Represent topics in pubsub. Contains information about a topic, including topic’s message data specification (MDS), the list of subscribed listeners, docstring for the topic. It allows Python-like access to subtopics (e.g. A.B is subtopic B of topic A).
wx.lib.pubsub.core.publishermixin.PublisherMixin
Create a topic. Should only be called by TopicManager via its |
|
Get the MDS docstrings for each of the specified kwargs. |
|
Get a map of keyword names to docstrings: documents each MDS element. |
|
Returns a pair (reqdArgs, optArgs) where reqdArgs is tuple |
|
Return the ‘docstring’ of topic |
|
Get a copy of list of listeners subscribed to this topic. Safe to iterate over while listeners |
|
Get an iterator over listeners subscribed to this topic. Do not use if listeners can be |
|
Return dotted form of full topic name |
|
Return tuple form of full topic name |
|
Return the last part of the topic name (has no dots) |
|
Return number of listeners currently subscribed to topic. This is |
|
Get Topic object that is parent of self (i.e. self is a subtopic |
|
Get the specified subtopic object. The relName can be a valid |
|
Get a list of Topic instances that are subtopics of self. |
|
Return true if listener is subscribed to this topic. |
|
Return true if there are any listeners subscribed to |
|
Return true if this topic has a message data specification (MDS). |
|
Return true only if name is a subtopic of self. If name not |
|
Returns true if this topic is the ‘all topics’ topic. All root |
|
Returns true if this is a “root” topic, false otherwise. A |
|
Return |
|
Set the docstring for each MDS datum. |
|
Set the ‘docstring’ of topic |
|
Specify the message data for topic messages. |
|
Subscribe listener to this topic. Returns a pair |
|
Unsubscribe the specified listener from this topic. Returns |
|
Clears list of subscribed listeners. If filter is given, it must |
|
Checks whether listener could be subscribed to this topic |
Topic
(PublisherMixin)¶Represent topics in pubsub. Contains information about a topic, including topic’s message data specification (MDS), the list of subscribed listeners, docstring for the topic. It allows Python-like access to subtopics (e.g. A.B is subtopic B of topic A).
__init__
(self, treeConfig, nameTuple, description, msgArgsInfo, parent=None)¶Create a topic. Should only be called by TopicManager via its getOrCreateTopic() method (which gets called in several places in pubsub, such as sendMessage, subscribe, and newTopic).
treeConfig – topic tree configuration settings
nameTuple – topic name, in tuple format (no dots)
description – “docstring” for topic
msgArgsInfo (ArgsInfo) – object that defines MDS for topic
parent – parent of topic
ValueError – invalid topic name
filterMsgArgs
(self, msgKwargs, check=False)¶Get the MDS docstrings for each of the specified kwargs.
getArgDescriptions
(self)¶Get a map of keyword names to docstrings: documents each MDS element.
getArgs
(self)¶Returns a pair (reqdArgs, optArgs) where reqdArgs is tuple of names of required message arguments, optArgs is tuple of names for optional arguments. If topic args not specified yet, returns (None, None).
getDescription
(self)¶Return the ‘docstring’ of topic
getListeners
(self)¶Get a copy of list of listeners subscribed to this topic. Safe to iterate over while listeners get un/subscribed from this topics (such as while sending a message).
getListenersIter
(self)¶Get an iterator over listeners subscribed to this topic. Do not use if listeners can be un/subscribed while iterating.
getName
(self)¶Return dotted form of full topic name
getNameTuple
(self)¶Return tuple form of full topic name
getNodeName
(self)¶Return the last part of the topic name (has no dots)
getNumListeners
(self)¶Return number of listeners currently subscribed to topic. This is different from number of listeners that will get notified since more general topics up the topic tree may have listeners.
getParent
(self)¶Get Topic object that is parent of self (i.e. self is a subtopic of parent). Return none if self is the “all topics” topic.
getSubtopic
(self, relName)¶Get the specified subtopic object. The relName can be a valid subtopic name, a dotted-name string, or a tuple.
getSubtopics
(self)¶Get a list of Topic instances that are subtopics of self.
hasListener
(self, listener)¶Return true if listener is subscribed to this topic.
hasListeners
(self)¶Return true if there are any listeners subscribed to this topic, false otherwise.
hasMDS
(self)¶Return true if this topic has a message data specification (MDS).
hasSubtopic
(self, name=None)¶Return true only if name is a subtopic of self. If name not specified, return true only if self has at least one subtopic.
isAll
(self)¶Returns true if this topic is the ‘all topics’ topic. All root topics behave as though they are child of that topic.
isRoot
(self)¶Returns true if this is a “root” topic, false otherwise. A root topic is a topic whose name contains no dots and which has pub.ALL_TOPICS as parent.
isValid
(self, listener)¶Return True
only if listener could be subscribed to this topic,
otherwise returns False. Note that method raises TopicDefnError
if self not hasMDS().
setArgDescriptions
(self, **docs)¶Set the docstring for each MDS datum.
setDescription
(self, desc)¶Set the ‘docstring’ of topic
setMsgArgSpec
(self, argsDocs, required=())¶Specify the message data for topic messages. :param argsDocs: a dictionary of keyword names (message data name) and data ‘docstring’; cannot be None :param required: a list of those keyword names, appearing in argsDocs, which are required (all others are assumed optional)
Can only be called if this info has not been already set at construction or in a previous call. :raise RuntimeError: if MDS already set at construction or previous call.
subscribe
(self, listener)¶Subscribe listener to this topic. Returns a pair (pub.Listener, success). The success is true only if listener was not already subscribed and is now subscribed.
unsubscribe
(self, listener)¶Unsubscribe the specified listener from this topic. Returns
the pub.Listener object associated with the listener that was
unsubscribed, or None if the specified listener was not
subscribed to this topic. Note that this method calls
notifyUnsubscribe(listener, self)
on all registered notification
handlers (see pub.addNotificationHandler).
unsubscribeAllListeners
(self, filter=None)¶Clears list of subscribed listeners. If filter is given, it must be a function that takes a listener and returns true if the listener should be unsubscribed. Returns the list of Listener for listeners that were unsubscribed.
validate
(self, listener)¶Checks whether listener could be subscribed to this topic: if yes, just returns; if not, raises ListenerMismatchError. Note that method raises TopicDefnError if self not hasMDS().