API Documentation

Import this module to make event handling a little simpler.

class evenz.events.Args[source]

Bases: tuple

Extend this named tuple to provide easy-to-understand arguments for your events.

property sender

the originator of the event

class evenz.events.Event(f: Callable, sender: Any = None)[source]

Bases: object

An event object wraps a function and notifies a set of handlers when the function is called.

__init__(f: Callable, sender: Any = None)[source]
Parameters
  • f – the function that triggers the event

  • sender – the sender of the event

property handlers

Get the handlers for this function.

Returns

an iteration of the handlers.

subscribe(handler: Callable)[source]

Subscribe a handler function to this event.

Parameters

handler – the handler

Note

You can also use the += operator.

trigger(*args, **kwargs)[source]

Trigger the event.

unsubscribe(handler: Callable)[source]

Unsubscribe a handler function from this event.

Parameters

handler – the handler

Note

You can also use the -= operator.

evenz.events.event(f: Callable) → evenz.events.Event[source]

Decorate a function or method to create an Event.

Parameters

f – the function.

Returns

the event

See also

If you are decorating a method within a class, you’ll need to use the observable() class decorator on the class as well.

evenz.events.observable(cls)[source]

Use this decorator to mark a class that exposes events.

Parameters

cls – the class

Returns

the class

See also

If you are using this decorator, you probably also want to use event() on some of the methods.