Skip to content

Commit 02af61b

Browse files
authored
Merge pull request #18923 from anntzer/wcb
Use lambdas to prevent gc'ing and deduplication of widget callbacks.
2 parents 1eb3d80 + f7ae56e commit 02af61b

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)