diff --git a/doc/api/next_api_changes/behavior/18226-ES.rst b/doc/api/next_api_changes/behavior/18226-ES.rst deleted file mode 100644 index c6247737f662..000000000000 --- a/doc/api/next_api_changes/behavior/18226-ES.rst +++ /dev/null @@ -1,10 +0,0 @@ -Widgets use ``CallbackRegistry`` to save callbacks -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -`.Widget`\s with event observers now use a `.CallbackRegistry` for storing -callbacks. This is consistent with canvas event callbacks, and fixes some bugs -in widget callback handling. - -Due to this change, callback methods are now stored as weak references, which -means you must keep a reference to the associated object. Otherwise it may be -garbage collected. diff --git a/lib/matplotlib/widgets.py b/lib/matplotlib/widgets.py index 967ef30f1771..788865d98d86 100644 --- a/lib/matplotlib/widgets.py +++ b/lib/matplotlib/widgets.py @@ -222,7 +222,7 @@ def on_clicked(self, func): Returns a connection id, which can be used to disconnect the callback. """ - return self._observers.connect('clicked', func) + return self._observers.connect('clicked', lambda event: func(event)) def disconnect(self, cid): """Remove the callback function with connection id *cid*.""" @@ -483,7 +483,7 @@ def on_changed(self, func): int Connection id (which can be used to disconnect *func*) """ - return self._observers.connect('changed', func) + return self._observers.connect('changed', lambda val: func(val)) def disconnect(self, cid): """ @@ -646,7 +646,7 @@ def on_clicked(self, func): Returns a connection id, which can be used to disconnect the callback. """ - return self._observers.connect('clicked', func) + return self._observers.connect('clicked', lambda text: func(text)) def disconnect(self, cid): """Remove the observer with connection id *cid*.""" @@ -897,7 +897,7 @@ def on_text_change(self, func): A connection id is returned which can be used to disconnect. """ - return self._observers.connect('change', func) + return self._observers.connect('change', lambda text: func(text)) def on_submit(self, func): """ @@ -906,7 +906,7 @@ def on_submit(self, func): A connection id is returned which can be used to disconnect. """ - return self._observers.connect('submit', func) + return self._observers.connect('submit', lambda text: func(text)) def disconnect(self, cid): """Remove the observer with connection id *cid*."""