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

Cannot create a widget whose initial state is visible=False #674

Closed
mwcraig opened this issue Jul 18, 2016 · 25 comments
Closed

Cannot create a widget whose initial state is visible=False #674

mwcraig opened this issue Jul 18, 2016 · 25 comments
Labels
bug resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion.
Milestone

Comments

@mwcraig
Copy link
Contributor

mwcraig commented Jul 18, 2016

In ipywidgets 5.2.2 the code below produces a widget that is visible:

check = Checkbox(description="A box", visible=False)
check

In ipywidgets 4, the checkbox wouldn't be displayed until I later set check.visible = True.

While this minimal example is pretty silly, I do rely heavily on being able to construct a widget with some components not visible until the user interacts with other elements.

A workaround or fix would be great.

@SylvainCorlay
Copy link
Member

The top-level widget styling attributes are deprecated. Instead, one should use the "layout" attribute.

check.layout.visibility = 'hidden'

or

check.layout.display = 'none'

depending on whether you want the invisible widget to take its place in the layout or not.

Regarding the visible attribute, we are aware of the behavior that you are observing. The deprecated top-level visible attribute is only a property that rebinds to the property of layout, but since there are then two things that modify the same css property, we decided that the new 'layout' method should win!

@SylvainCorlay
Copy link
Member

You can check out the example notebook

https://github.com/ipython/ipywidgets/blob/master/docs/source/examples/Widget%20Styling.ipynb

for more information about the use of layout.

@mwcraig
Copy link
Contributor Author

mwcraig commented Jul 19, 2016

Ah, that makes sense, sorry for the noise. It might be worth backporting that style notebook back to 5.x because the one currently there doesn't mention layout at all: https://github.com/ipython/ipywidgets/blob/5.x/docs/source/examples/Widget%20Styling.ipynb

@SylvainCorlay
Copy link
Member

good point, and this is not noise!

@mwcraig
Copy link
Contributor Author

mwcraig commented Jul 19, 2016

Actually, I think there is a bug here. Shouldn't the visible keyword in the constructor produce the desired result by (behind the scenes) setting visibility on layout, or emit a deprecation warning?

@SylvainCorlay
Copy link
Member

Deprecation warnings actually are not enabled by default.

Regarding the behavior, the problem is that the css property is read from
layout. I am not sure that there is a nice way to resolve the conflict. Do
you have something in mind?
On Jul 19, 2016 8:06 PM, "Matt Craig" notifications@github.com wrote:

Actually, I think there is a bug here. Shouldn't the visible keyword in
the constructor produce the desired result by (behind the scenes) setting
visibility on layout, or emit a deprecation warning?


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#674 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ACSXFnKqe0d-8acorphZpvwZ81lXXcQrks5qXRI-gaJpZM4JOZy1
.

@hainm
Copy link

hainm commented Jul 20, 2016

@SylvainCorlay

  • where can I find doc for visibility?

The website does not have anything: http://ipywidgets.readthedocs.io/en/latest/search.html?q=visibility&check_keywords=yes&area=default

if setting button.layout.visibility = 'hidden' will hide the button. How can I show it?
button.layout.visibility = 'shown' does not work (neither 'True', 'display', ...)

  • shouldn't be visibility enum rather Unicode?

@mwcraig
Copy link
Contributor Author

mwcraig commented Jul 21, 2016

This example also doesn't generate an invisible checkbox:

check = Checkbox(description="A box", visibility='hidden')
check

@hainm -- looks like setting visibility to 'visible' brings it back.

@mwcraig
Copy link
Contributor Author

mwcraig commented Jul 21, 2016

@SylvainCorlay -- I'd suggest two things (both of which may be impractical, I'm really not familiar with the codebase):

  1. The .visible attribute should accurately reflect whether the widget is visible. Right now setting .visibility='hidden' leaves visible set to True.
  2. If a user sets visible=False in the function call then I'd expect something like this in the constructor:
visible = kwd.pop('visible', True)
if visible:
     some_widget.layout.visibility = 'visible'
else:
     some_widget.layout.visibility = 'hidden'

It is unfortunate that DeprecationWarnings get hidden by default...

@SylvainCorlay
Copy link
Member

ok, I can try something like this - although beware that visible is not even there in master anymore. So this would be an ipywidgets 5.x only thing.

@hainm
Copy link

hainm commented Jul 21, 2016

although beware that visible is not even there in master anymore. So this would be an ipywidgets 5.x only thing.

I will wait for 6.x.

@mwcraig
Copy link
Contributor Author

mwcraig commented Jul 21, 2016

If it will be gone in master I wouldn't worry too much about it...if I get a chance maybe I'll try to flesh out the wiki page with some more details.

@SylvainCorlay
Copy link
Member

One thing that we should do is consolidate

  • the "widget styling" which is the tutorial about styling widget and use of the layout
  • the "widget layout" which essentially tests that natural sizes of widgets work well together in arrangements of vboxes and hboxes.

@jasongrout
Copy link
Member

Closing as fixed in master and will be in 6.0.

@mwcraig
Copy link
Contributor Author

mwcraig commented Nov 12, 2016

Just to make sure I understand, the visible property is gone in 6.0, right?

@SylvainCorlay
Copy link
Member

That is right!

Only layout.visibility.

On Nov 12, 2016 11:59 AM, "Matt Craig" notifications@github.com wrote:

Just to make sure I understand, the visible property is gone in 6.0,
right?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#674 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ACSXFo3DgwX7SoBPtCHS91V5QYs5LFxFks5q9hqvgaJpZM4JOZy1
.

@jasongrout jasongrout modified the milestone: 6.0 Mar 1, 2017
@dvm-shlee
Copy link

dvm-shlee commented Apr 12, 2017

I just found we can also use .close() methods in case you want to remove it from your notebook

@jasongrout
Copy link
Member

You can also use layout.display='none' to hide the widget.

@maver1ck
Copy link

Could you tell me why you remove visible property ?
aplavin/ipy-progressbar#3

@jasongrout
Copy link
Member

Rather than conflating the visibility with hiding, we now just simply expose the separate css properties as part of a unified way of handling the css for the widget as a whole, in the .layout attribute. Is that the explanation you are asking?

You can still do everything you used to - just using .layout.visibility and .layout.display.

@martinloland
Copy link

martinloland commented Jul 3, 2017

I have multiple Box objects inside one container Box object. When I set the visibility of one of the smaller boxes to 'hidden' everything disappears. Is there a way to set only one Box object to be hidden? This problem seems to only happen if I try to set the property after it has been created.

@jasongrout
Copy link
Member

Can you post some code reproducing this?

@martinloland
Copy link

from ipywidgets import Layout, Label, SelectMultiple, Box
from IPython.display import display
box_layout = Layout(flex='auto', width='auto')
container_layout = Layout(display='flex', flex_flow='column', width='50%',)

title = Label(value='title text', layout=box_layout)
select = SelectMultiple(layout=box_layout)

box1 = Box(children=[title, select], layout=container_layout)
box2 = Box(children=[title, select], layout=container_layout)
main_container = Box(children=[box1, box2], layout=container_layout)
display(main_container)
box1.children[0].layout.visibility = 'hidden'

Here I am only trying to hide the title of the first box, but everything disappears.

The version of the notebook server is 5.0.0 and is running on:
Python 2.7.12 |Anaconda custom (64-bit)| (default, Jun 29 2016, 11:07:13) [MSC v.1500 64 bit (AMD64)]

I am making the interface for people using this version of anaconda. Thanks!

@vidartf
Copy link
Member

vidartf commented Jul 4, 2017

Both title and select use the same instance of Layout, and both widgets are used twice (it shows the same Label and SelectMultiple twice, not copies). In short, all the (non-box) widgets have the exact same instance of box_layout. Try creating one layout for each widget (and probably multiple value widgets).

@martinloland
Copy link

Thanks @vidartf, didn't consider that.

@github-actions github-actions bot added the resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion. label Feb 12, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion.
Projects
None yet
Development

No branches or pull requests

8 participants