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 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
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__': {}})¶
- __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.
- _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 byEventDispatcher
implementors; applications should call thedispatch_events
method.Since pyglet 1.2, the method returns
EVENT_HANDLED
if an event handler returnedEVENT_HANDLED
orEVENT_UNHANDLED
if all events returnedEVENT_UNHANDLED
. If no matching event handlers are in the stack,False
is returned.- Parameters
event_type
strName of the event.
args
sequenceArguments to pass to the event handler.
- Return type
bool or None
- Returns
(Since pyglet 1.2)
EVENT_HANDLED
if an event handler returnedEVENT_HANDLED
;EVENT_UNHANDLED
if one or more event handlers were invoked but returned onlyEVENT_UNHANDLED
; otherwiseFalse
. In pyglet 1.1 and earlier, the return value is alwaysNone
.
- 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): # ...
- 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
name
strName 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
orpush_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
name
strName of the event type to remove.
handler
callableEvent 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()
andpop_handlers()
.
- set_handler(name, handler)[source]¶
Attach a single event handler.
- Parameters
name
strName of the event type to attach to.
handler
callableEvent 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.