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

Skip to content

Added get_status() function to the CheckButtons widget #6018

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/users/whats_new/CheckButtons_widget_get_status.rst
Original file line number Diff line number Diff line change
@@ -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.
14 changes: 14 additions & 0 deletions lib/matplotlib/tests/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
8 changes: 7 additions & 1 deletion lib/matplotlib/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down