From 7a96a82c9425562da3c5f02bc16ba9884fd8d823 Mon Sep 17 00:00:00 2001 From: danhickstein Date: Wed, 17 Feb 2016 16:47:39 -0700 Subject: [PATCH 1/4] added get_status() function to the CheckButtons widget --- lib/matplotlib/widgets.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/widgets.py b/lib/matplotlib/widgets.py index ad008c4f0d70..58214796f685 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. @@ -602,6 +602,12 @@ def set_active(self, index): return 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): """ From 0d81f8bfa357b7dd9ead4acf07d7220e3a30dbc6 Mon Sep 17 00:00:00 2001 From: danhickstein Date: Wed, 17 Feb 2016 17:33:20 -0700 Subject: [PATCH 2/4] added space after comma in widgets.CheckButtons.get_status() --- lib/matplotlib/widgets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/widgets.py b/lib/matplotlib/widgets.py index 58214796f685..bfb1f08ad2b8 100644 --- a/lib/matplotlib/widgets.py +++ b/lib/matplotlib/widgets.py @@ -607,7 +607,7 @@ 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] + return [l1.get_visible() for (l1, l2) in self.lines] def on_clicked(self, func): """ From 316fdbfca86954a8fc3627578fd7a77f2fbb3b98 Mon Sep 17 00:00:00 2001 From: DanHickstein Date: Thu, 18 Feb 2016 09:00:16 -0700 Subject: [PATCH 3/4] CheckButtons: added "whats_new" and unit test Added a basic unit test for the CheckButtons class to lib/matplotlib/tests/test_widgets.py Also, added a description of the new `get_status` function to `doc/users/whats_new/CheckButtons_widget_get_status.rst` --- .../whats_new/CheckButtons_widget_get_status.rst | 4 ++++ lib/matplotlib/tests/test_widgets.py | 12 ++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 doc/users/whats_new/CheckButtons_widget_get_status.rst 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..a22c50255235 100644 --- a/lib/matplotlib/tests/test_widgets.py +++ b/lib/matplotlib/tests/test_widgets.py @@ -257,3 +257,15 @@ 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) \ No newline at end of file From 6e24047bdcdc0f35d282c27d62324e52fa7a7afb Mon Sep 17 00:00:00 2001 From: danhickstein Date: Mon, 22 Feb 2016 11:41:36 -0700 Subject: [PATCH 4/4] made changes to widgets.CheckButtons.get_status() conform to pep8 --- lib/matplotlib/tests/test_widgets.py | 10 ++++++---- lib/matplotlib/widgets.py | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/matplotlib/tests/test_widgets.py b/lib/matplotlib/tests/test_widgets.py index a22c50255235..2555037828f1 100644 --- a/lib/matplotlib/tests/test_widgets.py +++ b/lib/matplotlib/tests/test_widgets.py @@ -258,14 +258,16 @@ def test_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 = 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] + assert check.get_status() == [False, False, True] + def clicked_function(): pass cid = check.on_clicked(clicked_function) - check.disconnect(cid) \ No newline at end of file + check.disconnect(cid) diff --git a/lib/matplotlib/widgets.py b/lib/matplotlib/widgets.py index bfb1f08ad2b8..112494b59359 100644 --- a/lib/matplotlib/widgets.py +++ b/lib/matplotlib/widgets.py @@ -602,7 +602,7 @@ def set_active(self, index): return 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