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

Layout properly taken into account only the second time I display nglview widget #865

Open
yakutovicha opened this issue Jan 7, 2020 · 9 comments

Comments

@yakutovicha
Copy link

I am using nglview 2.7.1 and I encountered the following problem:

Screenshot_2020-01-07 Untitled1

any idea why the protein is centred properly only the second time I display the nglview widget? Is there a quick fix for that?

@yakutovicha
Copy link
Author

This may help. If I do view.n_components = 1 before displaying the widget for the first time - it works without a problem.

@hainm
Copy link
Collaborator

hainm commented Jan 7, 2020

Hi, please use attribute to set the widget.

import nglview as nv

view = nv.demo()
view.layout.width = '50%'
view

@yakutovicha
Copy link
Author

yakutovicha commented Jan 7, 2020

Thanks, @hainm, with setting attribute it works.

I was just wondering: is it expected behaviour? I had the impression that nglview's interface is very much in line with jupyter widgets, where both approaches do work.

@hainm
Copy link
Collaborator

hainm commented Jan 7, 2020

is it expected behaviour?

yes, that's expected behavior. The feature is not implemented yet.
Currently a widget only watches for the changes in its layout's attributes. not the layout change itself.

https://github.com/arose/nglview/blob/0ad4c4ed69cca28c117ff5ee177ad2f3c64051e0/nglview/widget.py#L271-L279

I had the impression that nglview's interface is very much in line with jupyter widgets, where both approaches do work.

yeah, almost.

@hainm
Copy link
Collaborator

hainm commented Jan 7, 2020

If you still want to use view.layout = {'width': '50%'}, please call view.handle_resize() explicitly after that.

view = nv.demo()
view.layout = {'width': '50%'}
view.handle_resize()
view

@yakutovicha
Copy link
Author

Alright, thanks for the explanation. Nice package by the way!

@yakutovicha
Copy link
Author

Just discovered another issue: if I use view.layout.width = '50%' , as you suggested, everything works fine until I use the fullscreen. If I click on the fullscreen button and then return back to the notebook - the widget's height changes:
before fullscreen:
Screenshot_2020-01-07 Untitled1(1)
after fullscreen:
Screenshot_2020-01-07 Untitled1(2)

@yakutovicha
Copy link
Author

yakutovicha commented Jan 7, 2020

However, with this approach:

view = nv.demo()
view.layout = {'width': '50%'}
view.handle_resize()
view

Everything seems to work fine.

@hainm
Copy link
Collaborator

hainm commented Jan 7, 2020

thanks for your report. yeah, there are still many minor issues here and there and we will keep this in mind. cheers.

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