pytilities.event.dispatcher_ — Pytilities v1.0.0 documentation

### Navigation

- index
- modules |
- next |
- previous |
- Pytilities v1.0.0 documentation »
- API documentation »
- pytilities »
- pytilities.event »

# pytilities.event.dispatcher_

exception `pytilities.event.dispatcher_.` `UnsupportedEventError`(event_name)

  Tried to access an unregistered event

  `__init__`(event_name)
  `__weakref__`

    list of weak references to the object (if defined)

class `pytilities.event.dispatcher_.` `Dispatcher`

  Utility class for dispatching events to handlers.

  Events have to be registered before they can be dispatched or have handlers added to them.

  Handlers can have an owner associated with them, usually you’ll use the reference of the listener. This allows you to remove all the handlers of a specific owner, which should save you some work.

  Class invariants:
  | For every (owner, event), there can be only 0 or 1 handlers

  `_Dispatcher__remove_handlers`(event, owner)

    Remove handlers of single event, optionally with particular owner

  `__init__`()
  `add_handler`()

    Add handler for an event, optionally with an owner.

    Parameters: | event_name (string) – name of the event to add the handler to handler (callable) – the handler to call when the event is dispatched owner – owner of the handler. Use this reference to easily remove all your handlers from the dispatcher (e.g. remove all handlers with the same owner). Default: None
    Raises UnsupportedEventError:
    | when event_name doesn’t exist

  `dispatch`()

    Dispatch an event to its handlers.

    The handlers are executed in a random order.

    Parameters: | event_name (string) – name of the event to dispatch args – arguments to pass to the handlers keyword_args – keyword arguments to pass to the handlers
    Raises UnsupportedEventError:
    | if event_name doesn’t exist

  `event`()

    Register the decorated as a handler of event_name

    Parameters: | event_name (string) – name of the event owner – owner of the handler. Use this reference to easily remove all your handlers from the dispatcher (e.g. remove all handlers with the same owner). Default: None

  `has_event`()

    Checks if event_name is supported

    Parameters: | event_name (string) – name of the event
    Returns: | True if the dispatcher has the event

  `register_events`()

    Register events.

    Parameters: | event_names ((string...)) – names of events to support

  `remove_handler`()

    Remove a handler from an event. It is an error to try to remove a handler from an event that doesn’t have this handler attached to it.

    Parameters: | event_name (callable) – name of the event to which the handler belongs handler – the handler that is attached to the event owner – owner of the handler. Default: None
    Preconditions : | handler is attached to event_name
    Raises UnsupportedEventError:
    | when event_name doesn’t exist

  `remove_handlers`()

    Remove all or some handlers of the dispatcher.

    event_name and owner act as filters of what to remove.

    If no handler matched the criterea, the method will return silently.

    Parameters: | event_name (string) – the event of which to remove the handlers. None means any. Default: None owner – the owner of which to remove the handlers. None means any. Default: None

  `__weakref__`

    list of weak references to the object (if defined)

  `events`

    Read-only, set of all supported events

    Return type: | frozenset(string...)

### Navigation

- index
- modules |
- next |
- previous |
- Pytilities v1.0.0 documentation »
- API documentation »
- pytilities »
- pytilities.event »