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

vbox behaves like hbox #198

Closed
korsbo opened this issue Dec 6, 2017 · 3 comments
Closed

vbox behaves like hbox #198

korsbo opened this issue Dec 6, 2017 · 3 comments

Comments

@korsbo
Copy link
Contributor

korsbo commented Dec 6, 2017

For some reason, vbox() has started outputting a row (not column) of widgets.

using Interact
sliders = fill(slider(1:10), 3)
display(vbox(sliders...))

This is now the same behaviour as hbox():

screen shot 2017-12-06 at 16 30 47

Combinations of hbox( vbox(), vbox() ) used to generate nice arrays of widgets, but now it just generates a long horizontal line.

I am guessing that this may be related to #197.

This is happening for me on a mac, using ipywidgets 7.0.1.

@JobJob
Copy link
Member

JobJob commented Dec 6, 2017

Sad news.

The hbox, vbox code was cobbled together quickly and without a deep understanding of IPywidgets layout system, so it's a bit of a shambles.

If anyone wants to have a bash at cleaning it up, it would be great, and I'd try to help.

Having said that, this may just be some minor compatibility issue with IPywidgets 7 - I notice I'm getting errors in the javascript console.

Alternately, you could try https://github.com/JuliaGizmos/InteractNext.jl (follow the install instructions there), it uses obs(slider) instead of signal(slider), but otherwise the API is quite similar. It may work better.

We're really hoping to get WebIO/InteractNext to a proper release before the end of the year.

Unfortunately, it seems we've been a bit swamped with other stuff recently.

@korsbo
Copy link
Contributor Author

korsbo commented Jan 25, 2018

I have found a hack for this problem.

in Interact/src/IJulia/setup.jl, replace

widget_class(::Box) = "Box"

with

widget_class(b::Box) = b.vert ? "VBox" : "Box"

This fixes the issue at hand, but a deeper problem remains.

The issue is that none of the attributes which Interact.jl are trying to pass to ipywigets FlexBox are actually registered by ipywidgets. I have not really been able to figure out precisely how Interact.jl deals with the python objects, but I think that I know where the problem lies.

Interact.jl creates an ipywidget Layout object. I can't spot any errors in its creation and this object should contain the output of

statedict(l::Layout) = begin
   state = Dict{Symbol, Any}(:display => "flex", :align_items => "stretch")
   l.box.vert && (state[:flex_flow] = "column")
   state
end

The resulting Layout python object is supposed to be passed to ipywidgets Box, as specified by

viewdict(b::Box) = begin
   Dict{Symbol, Any}(:layout => "IPY_MODEL_"*widget_comms[b.layout].id)
end

Hovewer, I do not think that this is done properly. If I replace this function with a dummy

viewdict(b::Box) = begin
   Dict{Symbol, Any}()
end

or

viewdict(b::Box) = begin
   Dict{Symbol, Any}(:layout=>"dummy")
end

it does not alter the behaviour at all.

In python one would write

import ipywidgets as widgets
from IPython.display import display

s = widgets.IntSlider(description="my slider")

my_layout_object = widgets.Layout(display="flex", align_items="stretch", flex_flow="column")
box = widgets.Box([s,s,s], layout=my_layout_object)
display(box)

and I believe that the point of failure for Interact.jl lies in the layout = my_layout_object assignment.
However, I do not know how to fix this, and the discovery of my hacky solution reduces my motivation to keep digging (especially if InteractNext.jl is supposed to take over soon).

@korsbo
Copy link
Contributor Author

korsbo commented Mar 6, 2018

Fixed by #201, closing.

@korsbo korsbo closed this as completed Mar 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants