Skip to content
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

Label option for boolean parameters has no effect #109

Closed
HagaiHargil opened this issue Jan 19, 2021 · 15 comments · Fixed by #150
Closed

Label option for boolean parameters has no effect #109

HagaiHargil opened this issue Jan 19, 2021 · 15 comments · Fixed by #150
Labels
bug Something isn't working

Comments

@HagaiHargil
Copy link
Contributor

Describe the bug
When setting a custom label attribute for a boolean parameter in a magicgui decorated function, the label of the object in the GUI doesn't update accordingly.

To Reproduce

from magicgui import magicgui

@magicgui(check={'label': 'ABC'})
def test(check: bool):
    pass


if __name__ == '__main__':
    test.show(run=True)  # the label is 'check', not 'ABC'.

Expected behavior
The shown label should be 'ABC'.

Environment (please complete the following information):

  • OS: Linux
  • backend: Qt
  • magicgui version: 0.2.6
@HagaiHargil HagaiHargil added the bug Something isn't working label Jan 19, 2021
@tlambert03
Copy link
Member

Do you want the text on the button itself to say ABC? Or actually have a label next to the button?

If the former, use the "text" parameter for buttons: https://napari.org/magicgui/_autosummary/magicgui.widgets.PushButton.html#magicgui.widgets.PushButton

If the latter, that would indeed require a change, I originally felt like buttons with text didn't need additional labels

@tlambert03
Copy link
Member

(I see the special case is confusing though, so maybe label should be an alias for text on buttons?)

@jni
Copy link
Contributor

jni commented Jan 19, 2021

@tlambert03 why are you mentioning push buttons? This is a label next to a tick mark? Or am I getting confused with the terminology?

@jni
Copy link
Contributor

jni commented Jan 19, 2021

Screen Shot 2021-01-20 at 12 08 41 am

This is what the above code produces 👆

@tlambert03
Copy link
Member

tlambert03 commented Jan 19, 2021

@tlambert03 why are you mentioning push buttons? This is a label next to a tick mark? Or am I getting confused with the terminology?

lol ... no sorry... was just waking up. In any case, the same point applies, because all ButtonWidgets (of which CheckBox is a subclass) already have their own text property (unlike other widgets like SpinBox, LineEdit, etc...), they didn't seem to require an extra label widget. As mentioned, I see that the terminology is confusing. But all the widgets were first made without the possibility of a linked label widget, (and that's when the buttons gained "text"). Later, when labeling got added, I didn't think it necessary to "label again things that already had text". This is what I meant when I said "so maybe label should be an alias for text on buttons?"

@tlambert03
Copy link
Member

In case I'm still being confusing. The following works:

from magicgui import magicgui

@magicgui(check={'text': 'ABC'})
def test(check: bool):
    pass

if it's still confusing consider the case when @magicgui(labels=False) is used... Pushbuttons and checkboxes still have text without the need for an additional label, that's why this was a slightly tricky case. but we can make label and text synonymous on those widgets

@HagaiHargil
Copy link
Contributor Author

Hmm, I guess that making them synonymous seems currently to be the best idea. Perhaps some warning should be shown which recommends the user to use the text field? Or is that unnecessary?

@tlambert03
Copy link
Member

Hmm, I guess that making them synonymous seems currently to be the best idea.

👍

Or is that unnecessary?

I think it's necessary until we can make it less confusing! 😂
Let me think about this a bit, maybe we just remove text from ButtonWidgets, and use label instead. I feel like that makes the most intuitive sense (even if what it's technically doing behind the scenes is a little different for ButtonWidgets)

thanks for raising the issue

@haesleinhuepf
Copy link
Contributor

Hey @tlambert03 ,

I just had a similar issue with labels of checkboxes. From within a magicgui annotated function a, I was doing this:

@magicgui
def a(parameter : bool = True)
    a.parameter.label='test'

and it didn't show any effect. However, when doing

@magicgui
def a(parameter : bool = True)
    a.parameter.text='test'

it works.

Full code here. If you want to reproduce it in more detail, I'm happy to write a more detailed example. But maybe the bug is obvious?

Thanks!

@tlambert03
Copy link
Member

What version are you using? That should have been fixed in #150, released in 0.2.7

@tlambert03
Copy link
Member

Ohhh sorry, that will only work during instantiation. Yeah, technically "text" is just the correct thing to use here, not label. "Label" is reserved to mean when there is an additional widget that labels the primary widget. But ButtonWidgets have their own text IN the widget. I see that that is a bit confusing, but it's two separate bits of text... will think about how to clarify

@haesleinhuepf
Copy link
Contributor

ButtonWidgets have their own text

I my case it's a checkbox.

I'm now updating both parameters, it works and it doesn't throw any error or warning. So I'm fine. I'm just not sure if this should be simplified.

@tlambert03
Copy link
Member

I'm just not sure if this should be simplified.

there's no need to update both parameters. text is the thing to the right of the checkbox (or, on a button, on the button itself). label is the thing to the left of a widget, that describes what a widget is. All widgets can have a label (whose visibility can be altered), but only some widgets (like CheckBox and Button) can have text as part of the widget. In this case, the label is not visible by default (just the text). So, it's not two different words for the same thing, it's different words for different things, you're just using text.

@haesleinhuepf
Copy link
Contributor

text is the thing to the right of the checkbox (or, on a button, on the button itself). label is the thing to the left of a widget

Ahh, now I get it :-) Thanks for the explanation.

@tlambert03
Copy link
Member

yeah, it's not awesome 😂 sorry... i do need to be able to represent both things, but I also need to make it less confusing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants