diff --git a/doc/users/whats_new/CheckButtons_widget_get_status.rst b/doc/users/whats_new/CheckButtons_widget_get_status.rst new file mode 100644 index 000000000000..84a2baa68a02 --- /dev/null +++ b/doc/users/whats_new/CheckButtons_widget_get_status.rst @@ -0,0 +1,4 @@ +CheckButtons widget get_status function +--------------------------------------- + +A :func:`get_status` function has been added the the :class:`matplotlib.widgets.CheckButtons` class. This :func:`get_status` function allows user to query the status (True/False) of all of the buttons in the CheckButtons object. \ No newline at end of file diff --git a/lib/matplotlib/tests/test_widgets.py b/lib/matplotlib/tests/test_widgets.py index c954355eb1e4..2555037828f1 100644 --- a/lib/matplotlib/tests/test_widgets.py +++ b/lib/matplotlib/tests/test_widgets.py @@ -257,3 +257,17 @@ def test_lasso_selector(): check_lasso_selector() check_lasso_selector(useblit=False, lineprops=dict(color='red')) check_lasso_selector(useblit=True, button=1) + + +@cleanup +def test_CheckButtons(): + ax = get_ax() + check = widgets.CheckButtons(ax, ('a', 'b', 'c'), (True, False, True)) + assert check.get_status() == [True, False, True] + check.set_active(0) + assert check.get_status() == [False, False, True] + + def clicked_function(): + pass + cid = check.on_clicked(clicked_function) + check.disconnect(cid) diff --git a/lib/matplotlib/widgets.py b/lib/matplotlib/widgets.py index ad008c4f0d70..112494b59359 100644 --- a/lib/matplotlib/widgets.py +++ b/lib/matplotlib/widgets.py @@ -474,7 +474,7 @@ def reset(self): class CheckButtons(AxesWidget): """ - A GUI neutral radio button. + A GUI neutral set of check buttons. For the check buttons to remain responsive you must keep a reference to this object. @@ -603,6 +603,12 @@ def set_active(self, index): for cid, func in six.iteritems(self.observers): func(self.labels[index].get_text()) + def get_status(self): + """ + returns a tuple of the status (True/False) of all of the check buttons + """ + return [l1.get_visible() for (l1, l2) in self.lines] + def on_clicked(self, func): """ When the button is clicked, call *func* with button label