Package pytilities :: Package event :: Module decorators
[hide private]
[frames] | no frames]

Module decorators

source code


Various decorators to ease event dispatching.

Functions [hide private]
 
dispatcher(*event_names)
Installs a `Dispatcher` on an `AttributeCollectionBase`.
source code
 
dispatcher_switch(cls)
Installs a `DispatcherSwitch` on an `AttributeCollectionBase`.
source code
Variables [hide private]
  __package__ = 'pytilities.event'
Function Details [hide private]

dispatcher(*event_names)

source code 

Installs a `Dispatcher` on an `AttributeCollectionBase`.

This class decorator does the following:
    - create a `Dispatcher` and store it in `self.__dispatcher`
    - delegate to all methods of the dispatcher's public delegation profile
    - add a `self.__dispatch` method that delegates to
      `self.__dispatcher.dispatch`
    - register the `event_names` on the dispatcher

Note on ctor usage: though `self.__dispatcher` already exists, the delegation
to it is not yet installed. You can use `self.__dispatcher`, but you can't
yet e.g. call `self.add_handler`, write `self.__dispatcher.add_handler`
instead.

Parameters:
    event_names :: (::string...)
        collection of events to register on the dispatcher

dispatcher_switch(cls)

source code 

Installs a `DispatcherSwitch` on an `AttributeCollectionBase`.

This class decorator does the following:
    - create a `DispatcherSwitch` and store it in self.__dispatcher_switch
    - delegate to all methods of the switch's public delegation profile
    - add a `self.__dispatch` method that delegates to
      `self.__dispatcher.dispatch`

Note on ctor usage: though `self.__dispatcher_switch` already exists, the
delegation to it is not yet installed. You can use
`self.__dispatcher_switch`, but you can't yet e.g. call `self.add_handler`,
write `self.__dispatcher_switch.add_handler` instead.