glooey.widget.EventDispatcher

class glooey.widget.EventDispatcher[source]

Bases: pyglet.event.EventDispatcher

An extension of pyglet.event.EventDispatcher class that adds support for continuously firing events and relaying events from other dispatchers.

Public Methods:

__init__()

relay_events_from(originator, event_type, ...)

Configure this handler to re-dispatch events from another handler.

start_event(event_type, *args[, dt])

Begin dispatching the given event at the given frequency.

stop_event(event_type)

Stop dispatching the given event.

Inherited from EventDispatcher

register_event_type(name)

Register an event type with the dispatcher.

push_handlers(*args, **kwargs)

Push a level onto the top of the handler stack, then attach zero or more event handlers.

set_handlers(*args, **kwargs)

Attach one or more event handlers to the top level of the handler stack.

set_handler(name, handler)

Attach a single event handler.

pop_handlers()

Pop the top level of event handlers off the stack.

remove_handlers(*args, **kwargs)

Remove event handlers from the event stack.

remove_handler(name, handler)

Remove a single event handler.

dispatch_event(event_type, *args)

Dispatch a single event to the attached handlers.

event(*args)

Function decorator for an event handler.

Private Properties

Inherited from EventDispatcher

_event_stack

Private Methods:

_EventDispatcher__yield_handlers(event_type)

Yield all the handlers registered for the given event type.

Inherited from EventDispatcher

_get_handlers(args, kwargs)

Implement handler matching on arguments for set_handlers and remove_handlers.

_remove_handler(name, handler)

Used internally to remove all handler instances for the given event name.

_raise_dispatch_exception(event_type, args, ...)


__dict__ = mappingproxy({'__module__': 'glooey.widget', '__doc__': '\n    An extension of `pyglet.event.EventDispatcher` class that adds support for \n    continuously firing events and relaying events from other dispatchers.\n    ', '__init__': <function EventDispatcher.__init__>, 'relay_events_from': <function EventDispatcher.relay_events_from>, 'start_event': <function EventDispatcher.start_event>, 'stop_event': <function EventDispatcher.stop_event>, '_EventDispatcher__yield_handlers': <function EventDispatcher.__yield_handlers>, '__annotations__': {}})
__init__()[source]
__module__ = 'glooey.widget'
__weakref__

list of weak references to the object (if defined)

__yield_handlers(event_type)

Yield all the handlers registered for the given event type.

_event_stack = ()
_get_handlers(args, kwargs)[source]

Implement handler matching on arguments for set_handlers and remove_handlers.

static _raise_dispatch_exception(event_type, args, handler, exception)[source]
_remove_handler(name, handler)[source]

Used internally to remove all handler instances for the given event name.

This is normally called from a dead WeakMethod to remove itself from the event stack.

dispatch_event(event_type, *args)[source]

Dispatch a single event to the attached handlers.

The event is propagated to all handlers from from the top of the stack until one returns EVENT_HANDLED. This method should be used only by EventDispatcher implementors; applications should call the dispatch_events method.

Since pyglet 1.2, the method returns EVENT_HANDLED if an event handler returned EVENT_HANDLED or EVENT_UNHANDLED if all events returned EVENT_UNHANDLED. If no matching event handlers are in the stack, False is returned.

Parameters
event_typestr

Name of the event.

argssequence

Arguments to pass to the event handler.

Return type

bool or None

Returns

(Since pyglet 1.2) EVENT_HANDLED if an event handler returned EVENT_HANDLED; EVENT_UNHANDLED if one or more event handlers were invoked but returned only EVENT_UNHANDLED; otherwise False. In pyglet 1.1 and earlier, the return value is always None.

event(*args)[source]

Function decorator for an event handler.

Usage:

win = window.Window()

@win.event
def on_resize(self, width, height):
    # ...

or:

@win.event('on_resize')
def foo(self, width, height):
    # ...
pop_handlers()[source]

Pop the top level of event handlers off the stack.

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

Push a level onto the top of the handler stack, then attach zero or more event handlers.

If keyword arguments are given, they name the event type to attach. Otherwise, a callable’s __name__ attribute will be used. Any other object may also be specified, in which case it will be searched for callables with event names.

classmethod register_event_type(name)[source]

Register an event type with the dispatcher.

Registering event types allows the dispatcher to validate event handler names as they are attached, and to search attached objects for suitable handlers.

Parameters
namestr

Name of the event to register.

relay_events_from(originator, event_type, *more_event_types)[source]

Configure this handler to re-dispatch events from another handler.

This method configures this handler dispatch an event of type event_type whenever originator dispatches events of the same type or any of the types in more_event_types. Any arguments passed to the original event are copied to the new event.

This method is mean to be useful for creating composite widgets that want to present a simple API by making it seem like the events being generated by their children are actually coming from them. See the Composing widgets tutorial for an example.

remove_handler(name, handler)[source]

Remove a single event handler.

The given event handler is removed from the first handler stack frame it appears in. The handler must be the exact same callable as passed to set_handler, set_handlers or push_handlers(); and the name must match the event type it is bound to.

No error is raised if the event handler is not set.

Parameters
namestr

Name of the event type to remove.

handlercallable

Event handler to remove.

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

Remove event handlers from the event stack.

See push_handlers() for the accepted argument types. All handlers are removed from the first stack frame that contains any of the given handlers. No error is raised if any handler does not appear in that frame, or if no stack frame contains any of the given handlers.

If the stack frame is empty after removing the handlers, it is removed from the stack. Note that this interferes with the expected symmetry of push_handlers() and pop_handlers().

set_handler(name, handler)[source]

Attach a single event handler.

Parameters
namestr

Name of the event type to attach to.

handlercallable

Event handler to attach.

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

Attach one or more event handlers to the top level of the handler stack.

See push_handlers() for the accepted argument types.

start_event(event_type, *args, dt=0.016666666666666666)[source]

Begin dispatching the given event at the given frequency.

Calling this method will cause an event of type event_type with arguments args to be dispatched every dt seconds. This will continue until stop_event() is called for the same event.

These continuously firing events are useful if, for example, you want to make a button that scrolls for as long as it’s being held.

stop_event(event_type)[source]

Stop dispatching the given event.

It is not an error to attempt to stop an event that was never started, the request will just be silently ignored.