Skip to content

visible_when on Label doesn't implicitly take the boolean of the specified trait #1768

@nicolasap-dm

Description

@nicolasap-dm

Consider this code:

from traits.api import HasTraits, Str
from traitsui.api import View, Item, Label, UItem

class Foo(HasTraits):

    a_string = Str()
    fixed_string = Str("a_string is true (according to UItem)")

    traits_view = View(
        Item("a_string"),
        Label("a_string is true (according to Label)", visible_when="a_string"),
        UItem("fixed_string", style="readonly", visible_when="a_string"),
        Label("len(a_string) is nonzero (according to Label)", visible_when="len(a_string)"),
        width=420, height=200
    )

Foo().configure_traits()

When a_string is the empty string (therefore False):

  • the Label(visible_when="a_string") does not get hidden
  • for comparison, the UItem with the same visible_when, and the Label(visible_when="len(a_string)"), correctly do get hidden

Peek 2021-11-01 11-13

Tried on main with pyside2.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions