Skip to content

Commit

Permalink
Warn about refs in add_event_handler (#398)
Browse files Browse the repository at this point in the history
* Warn about refs in add_event_handler

* Update wgpu/gui/base.py

---------

Co-authored-by: Korijn van Golen <[email protected]>
  • Loading branch information
almarklein and Korijn authored Oct 25, 2023
1 parent 4026cd5 commit 2f2495d
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions wgpu/gui/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,17 +305,19 @@ def handle_event(self, event):
callback(event)

def add_event_handler(self, *args):
"""Register an event handler.
"""Register an event handler to receive 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:
Expand All @@ -326,7 +328,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
Expand Down

0 comments on commit 2f2495d

Please sign in to comment.