phoenix_title wx.lib.pubsub.core.topicobj.Topic

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).


class_hierarchy Class Hierarchy

Inheritance diagram for class Topic:

method_summary Methods Summary

__init__

Create a topic. Should only be called by TopicManager via its

filterMsgArgs

Get the MDS docstrings for each of the specified kwargs.

getArgDescriptions

Get a map of keyword names to docstrings: documents each MDS element.

getArgs

Returns a pair (reqdArgs, optArgs) where reqdArgs is tuple

getDescription

Return the ‘docstring’ of topic

getListeners

Get a copy of list of listeners subscribed to this topic. Safe to iterate over while listeners

getListenersIter

Get an iterator over listeners subscribed to this topic. Do not use if listeners can be

getName

Return dotted form of full topic name

getNameTuple

Return tuple form of full topic name

getNodeName

Return the last part of the topic name (has no dots)

getNumListeners

Return number of listeners currently subscribed to topic. This is

getParent

Get Topic object that is parent of self (i.e. self is a subtopic

getSubtopic

Get the specified subtopic object. The relName can be a valid

getSubtopics

Get a list of Topic instances that are subtopics of self.

hasListener

Return true if listener is subscribed to this topic.

hasListeners

Return true if there are any listeners subscribed to

hasMDS

Return true if this topic has a message data specification (MDS).

hasSubtopic

Return true only if name is a subtopic of self. If name not

isAll

Returns true if this topic is the ‘all topics’ topic. All root

isRoot

Returns true if this is a “root” topic, false otherwise. A

isValid

Return True only if listener could be subscribed to this topic,

setArgDescriptions

Set the docstring for each MDS datum.

setDescription

Set the ‘docstring’ of topic

setMsgArgSpec

Specify the message data for topic messages.

subscribe

Subscribe listener to this topic. Returns a pair

unsubscribe

Unsubscribe the specified listener from this topic. Returns

unsubscribeAllListeners

Clears list of subscribed listeners. If filter is given, it must

validate

Checks whether listener could be subscribed to this topic


api Class API

class 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).


Methods

__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).

Parameters
  • 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

Raises

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().