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

Nglview works only in the first tab of ipw.Tab() widget #871

Open
yakutovicha opened this issue Mar 3, 2020 · 4 comments
Open

Nglview works only in the first tab of ipw.Tab() widget #871

yakutovicha opened this issue Mar 3, 2020 · 4 comments

Comments

@yakutovicha
Copy link

When I try to use nglivew in ipw.Tab() widget - the only way to make it work is to place it in the very first tab. Placing it in 2, 3... tabs results in not showing the nglview.

Here is the minimal code snippet to reproduce the problem (Jupyter notebook):

class Test(ipw.VBox):
    def __init__(self):
        import nglview
        self.viewer = nglview.NGLWidget()
        self.viewer.add_component('rcsb://1tsu.pdb')
        super().__init__([self.viewer])

class Vwr(ipw.VBox):
    def __init__(self):
        t = Test()
        b = ipw.Button()
        self.tab = ipw.Tab()
        self.tab.children = [b, t]  # Does not work.
        #self.tab.children = [t, b]  # Does work.
        super().__init__([self.tab])

display(Vwr())
  • Version report
    Nglview version is: 2.7.1
    Ipywidgets version is: 7.5.1
@hainm
Copy link
Collaborator

hainm commented Mar 3, 2020

hi @yakutovicha for an unknown reason, the viewer is not resized properly.
Please call handle_resize method

import ipywidgets as ipw

class Test(ipw.VBox):
    def __init__(self):
        import nglview
        self.viewer = nglview.NGLWidget()
        self.viewer.add_component('rcsb://1tsu.pdb')
        super().__init__([self.viewer])

class Vwr(ipw.VBox):
    def __init__(self):
        t = Test()
        b = ipw.Button()
        self.tab = ipw.Tab()
        self.tab.children = [b, t]  # Does not work.
        # self.tab.children = [t, b]  # Does work.
        
        def on_change(change):
            index = change['new']
            if index == 1: # 2nd tab:
                t.viewer.handle_resize()
        
        self.tab.observe(on_change, 'selected_index')
            
            
        super().__init__([self.tab])

v = Vwr()
v

@hainm
Copy link
Collaborator

hainm commented May 24, 2020

Resolved.

@hainm hainm closed this as completed May 24, 2020
@yakutovicha
Copy link
Author

Just to let you know that the problem is still there for 2.7.7, unless you consider adding the code below as the fix

        def on_change(change):
            index = change['new']
            if index == 1: # 2nd tab:
                t.viewer.handle_resize()
        
        self.tab.observe(on_change, 'selected_index')

@hainm hainm reopened this Jul 17, 2020
@hainm
Copy link
Collaborator

hainm commented Jul 17, 2020

reopen

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