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

visible_when=False in Vgroup Tabbed still visible #758

Open
fred4ets opened this issue Mar 9, 2020 · 4 comments · May be fixed by #1705
Open

visible_when=False in Vgroup Tabbed still visible #758

fred4ets opened this issue Mar 9, 2020 · 4 comments · May be fixed by #1705
Milestone

Comments

@fred4ets
Copy link

fred4ets commented Mar 9, 2020

Hi there,

I'm facing the following issue.

If i set 2 traits items and set one of them to be not visible, it is stil visible.

I join a CME to be more explicit : Tab #1 should be not visible.

What am I doing wrong?

Thanks in advance.

Regards

PS : Debian 10 x86_64 / Python 3.7.3, with Traits libs from git source (Traits 6.1.0 dev1414 & TraitsUI 6.2.0 dev123)

#! /usr/bin/env python3

from traits.api import Int, Float, HasTraits
from traitsui.api import (Group, HGroup, Item, Tabbed, VGroup, View)

class Foo(HasTraits):

    a = Int
    b = Float

    view = View(Tabbed(VGroup(HGroup(Item('a')),
                              label='Tab #1',
                              visible_when='False'),
                       VGroup(HGroup(Item('b')),
                              label='Tab #2',
                              visible_when='True')))

if (__name__ == '__main__'):
    foo = Foo()
    foo.configure_traits()
@fred4ets
Copy link
Author

fred4ets commented Apr 23, 2021

Hello,

Any news about this issue?

Ok, I fix a few typo:

#! /usr/bin/env python3

from traits.api import Int, Float, HasTraits
from traitsui.api import (Group, HGroup, Item, Tabbed, VGroup, View)

class Foo(HasTraits):

    a = Int
    b = Float
    
    view = View(Tabbed(VGroup(HGroup(Item('a')),
                              label='Tab #1',
                              visible_when='False'),
                       VGroup(HGroup(Item('b')),
                              label='Tab #2',
                       visible_when='True')))

if (__name__ == '__main__'):
    foo = Foo()
    foo.configure_traits()
    

PS: It works fine with wx, this is only with qt4 I have this issue.

@aaronayres35 aaronayres35 added this to To be considered in Enthought OSS Q2 2021 Apr 23, 2021
@rahulporuri
Copy link
Contributor

@fred4ets thanks for providing a way to reproduce the issue. I can reproduce this issue on windows + python 3.6 + pyqt5 5.14.2 and qt 5.12.6

@aaronayres35
Copy link
Contributor

aaronayres35 commented Jun 24, 2021

This appears to be relevant:
https://doc.qt.io/qt-5/qtabwidget.html#setTabVisible
but is new in Qt 5.15
It seems the old way of hiding / showing tabs is to entirely remove the tab while keeping a ref to it / its index, and then adding it back later with the https://doc.qt.io/qt-5/qtabwidget.html#removeTab and https://doc.qt.io/qt-5/qtabwidget.html#addTab methods

Also, I believe relevant traitsUI code is:

elif group.layout in ("tabbed", "fold"):
# Create the TabWidget or ToolBox.
if group.layout == "tabbed":
sub = QtGui.QTabWidget()
else:
sub = QtGui.QToolBox()
# Give tab/tool widget stretch factor equivalent to default stretch
# factory for a resizeable item. See end of '_add_items'.
policy = sub.sizePolicy()
policy.setHorizontalStretch(50)
policy.setVerticalStretch(50)
sub.setSizePolicy(policy)
_fill_panel(sub, content, self.ui, self._add_page_item)
if outer is None:
outer = sub
else:
inner.addWidget(sub)
# Create an editor.
editor = TabbedFoldGroupEditor(container=sub, control=outer, ui=ui)
self._setup_editor(group, editor)

and specifically _fill_panel:
def _fill_panel(panel, content, ui, item_handler=None):
"""Fill a page based container panel with content.
"""
active = 0
for index, item in enumerate(content):
page_name = item.get_label(ui)
if page_name == "":
page_name = "Page %d" % index
if isinstance(item, Group):
if item.selected:
active = index
gp = _GroupPanel(item, ui, suppress_label=True)
page = gp.control
sub_page = gp.sub_control
# If the result is the same type with only one page, collapse it
# down into just the page.
if isinstance(sub_page, type(panel)) and sub_page.count() == 1:
new = sub_page.widget(0)
if isinstance(panel, QtGui.QTabWidget):
sub_page.removeTab(0)
else:
sub_page.removeItem(0)
elif isinstance(page, QtGui.QWidget):
new = page
else:
new = QtGui.QWidget()
new.setLayout(page)
layout = new.layout()
if layout is not None:
layout.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop)
else:
new = QtGui.QWidget()
layout = QtGui.QVBoxLayout(new)
layout.setContentsMargins(0, 0, 0, 0)
item_handler(item, layout)
# Add the content.
if isinstance(panel, QtGui.QTabWidget):
panel.addTab(new, page_name)
else:
panel.addItem(new, page_name)
panel.setCurrentIndex(active)

Doing some debugging, I am seeing that the UI is getting the visible_when string added to _visible with an appropriate corresponding GroupEditor... I also verified that even if cond_value is False here:

cond_value = eval(when, globals(), context)

the tab remains visible.

It seems to me the TabbedFoldGroupEditor or its container which is a QTabWidget needs to be responsible for seeing if any of the wrapped GroupEditors have visible == False, and update accordingly.

Unfortunately, we don't end up keeping track of the wrapped GroupEditor for the tab:

self._setup_editor(group, GroupEditor(control=outer))
(although a reference to it is kept in the _visible list on the UI). This makes it tricky, as I don't know who should be charged with listening to when {add/remove}Tab should be called...

In summary I don't think this is a simple quick fix 😞 but I will see if I can get something working

@aaronayres35
Copy link
Contributor

Also, when you first launch the tab is empty (as we correctly listen to visible_when):
Screen Shot 2021-06-24 at 3 54 13 PM
but the tab itself is still visible even if its contents aren't and that is what we really want to not be visible. Also, clicking to the other tab and back, the content of tab 1 is then visible and will never become not visible again.

TThere is a disconnect between what traitsUI is trying to do and Qt below.

@aaronayres35 aaronayres35 moved this from To be considered to Sprint 6+ : 28, 29, 30 June 2021 in Enthought OSS Q2 2021 Jun 29, 2021
@aaronayres35 aaronayres35 moved this from Sprint 6+ : 28, 29, 30 June 2021 to In progress in Enthought OSS Q2 2021 Jun 29, 2021
@rahulporuri rahulporuri removed this from In progress in Enthought OSS Q2 2021 Jul 2, 2021
@corranwebster corranwebster added this to the Release 7.3.0 milestone Feb 1, 2022
@mdickinson mdickinson changed the title visible_when=False in Vgroup Tabbed stiil visible visible_when=False in Vgroup Tabbed still visible Feb 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants