watson.events.collections

class watson.events.collections.Listener[source]

A list of listeners to be used in an EventDispatcher.

A Listener Collection is a list of callbacks that are to be triggered by an event dispatcher. Each item in the list contains the callback, a priority, and whether or not the callback should only be triggered once.

add(callback, priority=1, only_once=False)[source]

Adds a new callback to the collection.

Parameters:
  • callback (callable) – the function to be triggered
  • priority (int) – how important the callback is in relation to others
  • only_once (bool) – the callback should only be fired once and then removed
Raises:

TypeError if non-callable is added.

remove(callback)[source]

Removes all callbacks matching callback from the collection.

Parameters:callback (callable) – the callback to be removed.
sort_priority()[source]

Sort the collection based on the priority of the callbacks.

watson.events.collections.ListenerDefinition

alias of Listener

class watson.events.collections.Result[source]

A list of responses from a EventDispatcher.trigger call.

A result collection contains all the resulting output from an event that has been triggered from an event dispatcher. It provides some convenience methods to deal with the results.

first(default=None)[source]

Return the first result from the list.

Parameters:default (mixed) – The value to return if the index doesn’t exist
Returns:The first result
Return type:mixed
last(default=None)[source]

Return the last result from the list.

Parameters:default (mixed) – The value to return if the index doesn’t exist
Returns:The first result
Return type:mixed