.. wxPython Phoenix documentation This file was generated by Phoenix's sphinx generator and associated tools, do not edit by hand. Copyright: (c) 2011-2020 by Total Control Software License: wxWindows License .. include:: headings.inc .. currentmodule:: wx.lib.pubsub.core.topicobj .. highlight:: python .. _wx.lib.pubsub.core.topicobj.Topic: ========================================================================================================================================== |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 ================================= .. raw:: html
Inheritance diagram for class Topic:
| |super_classes| Known Superclasses ================================== :class:`wx.lib.pubsub.core.publishermixin.PublisherMixin` | |method_summary| Methods Summary ================================ ================================================================================ ================================================================================ :meth:`~wx.lib.pubsub.core.topicobj.Topic.__init__` Create a topic. Should only be called by TopicManager via its :meth:`~wx.lib.pubsub.core.topicobj.Topic.filterMsgArgs` Get the MDS docstrings for each of the specified kwargs. :meth:`~wx.lib.pubsub.core.topicobj.Topic.getArgDescriptions` Get a map of keyword names to docstrings: documents each MDS element. :meth:`~wx.lib.pubsub.core.topicobj.Topic.getArgs` Returns a pair (reqdArgs, optArgs) where reqdArgs is tuple :meth:`~wx.lib.pubsub.core.topicobj.Topic.getDescription` Return the 'docstring' of topic :meth:`~wx.lib.pubsub.core.topicobj.Topic.getListeners` Get a copy of list of listeners subscribed to this topic. Safe to iterate over while listeners :meth:`~wx.lib.pubsub.core.topicobj.Topic.getListenersIter` Get an iterator over listeners subscribed to this topic. Do not use if listeners can be :meth:`~wx.lib.pubsub.core.topicobj.Topic.getName` Return dotted form of full topic name :meth:`~wx.lib.pubsub.core.topicobj.Topic.getNameTuple` Return tuple form of full topic name :meth:`~wx.lib.pubsub.core.topicobj.Topic.getNodeName` Return the last part of the topic name (has no dots) :meth:`~wx.lib.pubsub.core.topicobj.Topic.getNumListeners` Return number of listeners currently subscribed to topic. This is :meth:`~wx.lib.pubsub.core.topicobj.Topic.getParent` Get Topic object that is parent of self (i.e. self is a subtopic :meth:`~wx.lib.pubsub.core.topicobj.Topic.getSubtopic` Get the specified subtopic object. The relName can be a valid :meth:`~wx.lib.pubsub.core.topicobj.Topic.getSubtopics` Get a list of Topic instances that are subtopics of self. :meth:`~wx.lib.pubsub.core.topicobj.Topic.hasListener` Return true if listener is subscribed to this topic. :meth:`~wx.lib.pubsub.core.topicobj.Topic.hasListeners` Return true if there are any listeners subscribed to :meth:`~wx.lib.pubsub.core.topicobj.Topic.hasMDS` Return true if this topic has a message data specification (MDS). :meth:`~wx.lib.pubsub.core.topicobj.Topic.hasSubtopic` Return true only if name is a subtopic of self. If name not :meth:`~wx.lib.pubsub.core.topicobj.Topic.isAll` Returns true if this topic is the 'all topics' topic. All root :meth:`~wx.lib.pubsub.core.topicobj.Topic.isRoot` Returns true if this is a "root" topic, false otherwise. A :meth:`~wx.lib.pubsub.core.topicobj.Topic.isValid` Return ``True`` only if listener could be subscribed to this topic, :meth:`~wx.lib.pubsub.core.topicobj.Topic.setArgDescriptions` Set the docstring for each MDS datum. :meth:`~wx.lib.pubsub.core.topicobj.Topic.setDescription` Set the 'docstring' of topic :meth:`~wx.lib.pubsub.core.topicobj.Topic.setMsgArgSpec` Specify the message data for topic messages. :meth:`~wx.lib.pubsub.core.topicobj.Topic.subscribe` Subscribe listener to this topic. Returns a pair :meth:`~wx.lib.pubsub.core.topicobj.Topic.unsubscribe` Unsubscribe the specified listener from this topic. Returns :meth:`~wx.lib.pubsub.core.topicobj.Topic.unsubscribeAllListeners` Clears list of subscribed listeners. If filter is given, it must :meth:`~wx.lib.pubsub.core.topicobj.Topic.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). .. method:: __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). :param treeConfig: topic tree configuration settings :param nameTuple: topic name, in tuple format (no dots) :param description: "docstring" for topic :param ArgsInfo msgArgsInfo: object that defines MDS for topic :param parent: parent of topic :raises ValueError: invalid topic name .. method:: filterMsgArgs(self, msgKwargs, check=False) Get the MDS docstrings for each of the specified kwargs. .. method:: getArgDescriptions(self) Get a map of keyword names to docstrings: documents each MDS element. .. method:: 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). .. method:: getDescription(self) Return the 'docstring' of topic .. method:: 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). .. method:: getListenersIter(self) Get an iterator over listeners subscribed to this topic. Do not use if listeners can be un/subscribed while iterating. .. method:: getName(self) Return dotted form of full topic name .. method:: getNameTuple(self) Return tuple form of full topic name .. method:: getNodeName(self) Return the last part of the topic name (has no dots) .. method:: 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. .. method:: 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. .. method:: getSubtopic(self, relName) Get the specified subtopic object. The relName can be a valid subtopic name, a dotted-name string, or a tuple. .. method:: getSubtopics(self) Get a list of Topic instances that are subtopics of self. .. method:: hasListener(self, listener) Return true if listener is subscribed to this topic. .. method:: hasListeners(self) Return true if there are any listeners subscribed to this topic, false otherwise. .. method:: hasMDS(self) Return true if this topic has a message data specification (MDS). .. method:: 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. .. method:: isAll(self) Returns true if this topic is the 'all topics' topic. All root topics behave as though they are child of that topic. .. method:: 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. .. method:: 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(). .. method:: setArgDescriptions(self, \*\*docs) Set the docstring for each MDS datum. .. method:: setDescription(self, desc) Set the 'docstring' of topic .. method:: 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. .. method:: 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. .. method:: 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). .. method:: 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. .. method:: 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().