pygfx.objects.EventTarget
- class pygfx.objects.EventTarget(*args, **kwargs)
Bases:
object
Targetable object mixin.
Mixin class that enables event handlers to be attached to objects of the mixed-in class.
- Parameters:
args (Any) – Arguments are forwarded to allow multiple inheritance.
kwargs (Any) – Kwargs are forwarded to allow multiple inheritance.
- add_event_handler(*args)
Register an event handler.
- Parameters:
callback (callable) – The event handler. Must accept a single event argument.
*types (list of strings) – A list of event types.
For the available event types, see https://jupyter-rfb.readthedocs.io/en/stable/events.html
Can also be used as a decorator.
Example:
def my_handler(event): print(event) obj.add_event_handler(my_handler, "pointer_up", "pointer_down")
Decorator usage example:
@obj.add_event_handler("pointer_up", "pointer_down") def my_handler(event): print(event)
- remove_event_handler(callback, *types)
Unregister an event handler.
- Parameters:
callback (callable) – The event handler.
*types (list of strings) – A list of event types.
- set_pointer_capture(pointer_id, event_root)
Register this object to capture any other pointer events, until
release_pointer_capture
is called or anpointer_up
event is encountered.- Parameters:
pointer_id – id of pointer to capture (mouse, touch, etc.)
event_root – the event root that this pointer is captured on
- release_pointer_capture(pointer_id)
Release the pointer capture for the object that was registered to the given pointer_id.
- Parameters:
pointer_id – id of pointer to release (mouse, touch, etc.)