Skip to content

Commit

Permalink
allow label to be alias for text in button widgets (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
tlambert03 committed Feb 10, 2021
1 parent aaa4eb9 commit c41462f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
8 changes: 8 additions & 0 deletions magicgui/widgets/_bases/button_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ class ButtonWidget(ValueWidget):
changed: EventEmitter

def __init__(self, text: Optional[str] = None, **kwargs):
if text and kwargs.get("label"):
from warnings import warn

warn(
"'text' and 'label' are synonymous for button widgets. To suppress this"
" warning, only provide one of the two kwargs."
)
text = text or kwargs.get("label")
super().__init__(**kwargs)
self.text = text or self.name

Expand Down
18 changes: 18 additions & 0 deletions tests/test_magicgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,3 +645,21 @@ def f():
...

f.show()


def test_boolean_label():
"""Test that label can be used to set the text of a button widget."""

@magicgui(check={"label": "ABC"})
def test(check: bool, x=1):
pass

assert test.check.text == "ABC"

with pytest.warns(UserWarning) as record:

@magicgui(check={"text": "ABC", "label": "BCD"})
def test2(check: bool, x=1):
pass

assert "'text' and 'label' are synonymous for button widgets" in str(record[0])

0 comments on commit c41462f

Please sign in to comment.