Skip to content

Commit f7ae56e

Browse files
committed
Use lambdas to prevent gc'ing and deduplication of widget callbacks.
This makes the behavior of widget callbacks more consistent with the old behavior (of using strong refs), and also more consistent with other widgets which don't rely on CallbackRegistry at all, such as SpanSelector and Lasso.
1 parent 1ed5c91 commit f7ae56e

File tree

2 files changed

+5
-15
lines changed

2 files changed

+5
-15
lines changed

doc/api/next_api_changes/behavior/18226-ES.rst

-10
This file was deleted.

lib/matplotlib/widgets.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def on_clicked(self, func):
222222
223223
Returns a connection id, which can be used to disconnect the callback.
224224
"""
225-
return self._observers.connect('clicked', func)
225+
return self._observers.connect('clicked', lambda event: func(event))
226226

227227
def disconnect(self, cid):
228228
"""Remove the callback function with connection id *cid*."""
@@ -483,7 +483,7 @@ def on_changed(self, func):
483483
int
484484
Connection id (which can be used to disconnect *func*)
485485
"""
486-
return self._observers.connect('changed', func)
486+
return self._observers.connect('changed', lambda val: func(val))
487487

488488
def disconnect(self, cid):
489489
"""
@@ -646,7 +646,7 @@ def on_clicked(self, func):
646646
647647
Returns a connection id, which can be used to disconnect the callback.
648648
"""
649-
return self._observers.connect('clicked', func)
649+
return self._observers.connect('clicked', lambda text: func(text))
650650

651651
def disconnect(self, cid):
652652
"""Remove the observer with connection id *cid*."""
@@ -897,7 +897,7 @@ def on_text_change(self, func):
897897
898898
A connection id is returned which can be used to disconnect.
899899
"""
900-
return self._observers.connect('change', func)
900+
return self._observers.connect('change', lambda text: func(text))
901901

902902
def on_submit(self, func):
903903
"""
@@ -906,7 +906,7 @@ def on_submit(self, func):
906906
907907
A connection id is returned which can be used to disconnect.
908908
"""
909-
return self._observers.connect('submit', func)
909+
return self._observers.connect('submit', lambda text: func(text))
910910

911911
def disconnect(self, cid):
912912
"""Remove the observer with connection id *cid*."""

0 commit comments

Comments
 (0)