diff --git a/wgpu/gui/base.py b/wgpu/gui/base.py index 8d5d5cc4..d3b07540 100644 --- a/wgpu/gui/base.py +++ b/wgpu/gui/base.py @@ -301,17 +301,19 @@ def handle_event(self, event): callback(event) def add_event_handler(self, *args): - """Register an event handler. + """Register an event handler to receice events. Arguments: - callback (callable): The event handler. Must accept a - single event argument. + callback (callable): The event handler. Must accept a single event argument. *types (list of strings): A list of event types. For the available events, see - https://jupyter-rfb.readthedocs.io/en/stable/events.html + https://jupyter-rfb.readthedocs.io/en/stable/events.html. - Can also be used as a decorator. + The callback is stored, so it can be a lambda or closure. This also + means that if a method is given, a reference to the object is held, + which may cause circular references or prevent the Python GC from + destroying that object. Example: @@ -322,7 +324,7 @@ def my_handler(event): canvas.add_event_handler(my_handler, "pointer_up", "pointer_down") - Decorator usage example: + Can also be used as a decorator: .. code-block:: py