nucleic / enaml

Declarative User Interfaces for Python
http://enaml.readthedocs.io/en/latest/
Other
1.53k stars 130 forks source link

InsertTab places a new tab in the incorrect dock tab widget #385

Closed e-calder closed 4 years ago

e-calder commented 4 years ago

Bug:

If you have a nested dock area which contains a single dock item, and wish to add a new tab to that nested dock area via InsertTab, the docking framework will actually insert it into the wrong tab widget.

The method QDockContainer dockTabBarWidget() should return None in the case of the tab widget not existing yet, but it will actually return the tab widget of the outer DockArea.

Below is a small standalone example enaml file which you can run simply with

enaml_run [filename].enaml

from enaml.layout.api import InsertTab, TabLayout, vbox

enamldef Main(Window):
    Container:
        constraints = [vbox(*widgets()), width >= 600]
        PushButton:
            text = 'Click Me'
            clicked::
                dock_item = DockItem(inner, name='Inner2', title='Inner2')
                op = InsertTab( item=dock_item.name,
                                target='Inner1',
                                tab_position='top')
                inner.update_layout(op)
        DockArea: outer:
            layout = TabLayout('Outer1', 'Outer2')
            DockItem:
                name = 'Outer1'
                title = name
                Container:
                    DockArea: inner:
                        layout = TabLayout('Inner1')
                        DockItem:
                            name = 'Inner1'
                            title = name
            DockItem:
                name = 'Outer2'
                title = name

Potential fix... maybe?

One potential fix could be to change QDockContainer.dockTabBarWidget() such that this function will only return the found QDockTabWidget if the parent dock area of that QDockTabWidget equals the parent dock area of the current QDockContainer. Open to suggestions...

MatthieuDartiailh commented 4 years ago

Thanks for the detailed report !!! very helpful.

I agree with your diagnosis and put together a PR (#386) that fixed the issue. Let me know if you agree it fixes the issue.

e-calder commented 4 years ago

No problem, I know how annoying it can be to receive half baked bug reports without enough information!

Thanks for the quick fix, I can confirm it works and that it fixes my issue. Cheers!