traits.traits_listener Module¶
Defines classes used to implement and manage various trait listener patterns.
- traits.traits_listener.indent(text, first_line=True, n=1, width=4)[source]¶
Indent lines of text.
- Parameters
text (str) – The text to indent.
first_line (bool, optional) – If False, then the first line will not be indented (default: True).
n (int, optional) – The level of indentation (default: 1).
width (int, optional) – The number of spaces in each level of indentation (default: 4).
- Returns
indented
- Return type
str
- class traits.traits_listener.ListenerItem[source]¶
Bases:
traits.traits_listener.ListenerBase- name = Str¶
The name of the trait to listen to:
- metadata_name = Str¶
The name of any metadata that must be present (or not present):
- metadata_defined = Bool(True)¶
Does the specified metadata need to be defined (True) or not defined (False)?
- handler = Any¶
The handler to be called when any listened-to trait is changed:
- wrapped_handler_ref = Any¶
A weakref ‘wrapped’ version of ‘handler’:
- dispatch = Str¶
The dispatch mechanism to use when invoking the handler:
- priority = Bool(False)¶
Does the handler go at the beginning (True) or end (False) of the notification handlers list?
- next = Instance(ListenerBase)¶
The next level (if any) of ListenerBase object to be called when any of this object’s listened-to traits is changed:
- type = Enum(ANY_LISTENER, SRC_LISTENER, DST_LISTENER)¶
The type of handler being used:
- notify = Bool(True)¶
Should changes to this item generate a notification to the handler?
- deferred = Bool(False)¶
Should registering listeners for items reachable from this listener item be deferred until the associated trait is first read or set?
- is_any_trait = Bool(False)¶
Is this an ‘any_trait’ change listener, or does it create explicit listeners for each individual trait?
- is_list_handler = Bool(False)¶
Is the associated handler a special list handler that handles both ‘foo’ and ‘foo_items’ events by receiving a list of ‘deleted’ and ‘added’ items as the ‘old’ and ‘new’ arguments?
- active = Instance(WeakIDKeyDict, ())¶
A dictionary mapping objects to a list of all current active (name, type) listener pairs, where type defines the type of listener, one of: (SIMPLE_LISTENER, LIST_LISTENER, DICT_LISTENER).
- handle_simple(object, name, old, new)[source]¶
Handles a trait change for an intermediate link trait.
- handle_dst(object, name, old, new)[source]¶
Handles a trait change for an intermediate link trait when the notification is for the final destination trait.
- handle_list_items(object, name, old, new)[source]¶
Handles a trait change for items of a list (or set) trait.
- handle_list_items_special(object, name, old, new)[source]¶
Handles a trait change for items of a list (or set) trait with notification.
- class traits.traits_listener.ListenerGroup[source]¶
Bases:
traits.traits_listener.ListenerBase- handler = Property¶
The handler to be called when any listened-to trait is changed
- wrapped_handler_ref = Property¶
A weakref ‘wrapped’ version of ‘handler’:
- dispatch = Property¶
The dispatch mechanism to use when invoking the handler:
- priority = ListProperty¶
Does the handler go at the beginning (True) or end (False) of the notification handlers list?
- next = ListProperty¶
The next level (if any) of ListenerBase object to be called when any of this object’s listened-to traits is changed
- type = ListProperty¶
The type of handler being used:
- notify = ListProperty¶
Should changes to this item generate a notification to the handler?
- deferred = ListProperty¶
Should registering listeners for items reachable from this listener item be deferred until the associated trait is first read or set?
- class traits.traits_listener.ListenerParser(text='', **traits)[source]¶
Bases:
traits.has_traits.HasPrivateTraits- len_text = Int¶
The length of the string being parsed.
- index = Int¶
The current parse index within the string
- next = Property¶
The next character from the string being parsed
- name = Property¶
The next Python attribute name within the string:
- skip_ws = Property¶
The next non-whitespace character
- backspace = Property¶
Backspaces to the last character processed
- listener = Instance(ListenerBase)¶
The ListenerBase object resulting from parsing text
- text = Str¶
The string being parsed