Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1ca5977

Browse files
committed
Merge pull request #6018 from DanHickstein/check-button-status
Added get_status() function to the CheckButtons widget
2 parents 2b4e698 + 6e24047 commit 1ca5977

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
CheckButtons widget get_status function
2+
---------------------------------------
3+
4+
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.

lib/matplotlib/tests/test_widgets.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,3 +257,17 @@ def test_lasso_selector():
257257
check_lasso_selector()
258258
check_lasso_selector(useblit=False, lineprops=dict(color='red'))
259259
check_lasso_selector(useblit=True, button=1)
260+
261+
262+
@cleanup
263+
def test_CheckButtons():
264+
ax = get_ax()
265+
check = widgets.CheckButtons(ax, ('a', 'b', 'c'), (True, False, True))
266+
assert check.get_status() == [True, False, True]
267+
check.set_active(0)
268+
assert check.get_status() == [False, False, True]
269+
270+
def clicked_function():
271+
pass
272+
cid = check.on_clicked(clicked_function)
273+
check.disconnect(cid)

lib/matplotlib/widgets.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ def reset(self):
474474

475475
class CheckButtons(AxesWidget):
476476
"""
477-
A GUI neutral radio button.
477+
A GUI neutral set of check buttons.
478478
479479
For the check buttons to remain responsive you must keep a
480480
reference to this object.
@@ -603,6 +603,12 @@ def set_active(self, index):
603603
for cid, func in six.iteritems(self.observers):
604604
func(self.labels[index].get_text())
605605

606+
def get_status(self):
607+
"""
608+
returns a tuple of the status (True/False) of all of the check buttons
609+
"""
610+
return [l1.get_visible() for (l1, l2) in self.lines]
611+
606612
def on_clicked(self, func):
607613
"""
608614
When the button is clicked, call *func* with button label

0 commit comments

Comments
 (0)