You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The way things are worded make it seem like you should not need to pass in values if the trait being edited is an enumeration, however that does not appear to work as intended. See example below:
from traitsui.api import EnumEditor, UItem, VGroup, View
VALUES = ("ABC", "123", "!@#")
class TestSelect(HasStrictTraits):
selection = Enum(VALUES)
def default_traits_view(self):
return View(
VGroup(
UItem(
"selection",
style="custom",
editor=EnumEditor(
# Commenting out values= ... generates an error, Invalid value for values specified
values={val: f"{i}:{val}" for i, val in enumerate(VALUES)},
cols=1,
),
)
),
buttons=["OK"],
title="Make Selection",
)
if __name__ == "__main__":
s = TestSelect()
s.configure_traits()
print(f"Selected: {s.selection}")
In the above example the code works as intended when the value kwarg for EnumEditor is provided. However if you comment out or remove that line, then the code fails with the following message: traits.trait_errors.TraitError: Invalid value for 'values' specified.
Possibly related issue (though the error message is different): #726
While passing through values to the editor is not difficult, the way the docs are worded it sounds like you should not need to. Additionally, for simple cases such as above where the intent is simply to display a static list of pre-defined values, it results in unnecessary code duplication. The underlying Enum trait already knows about the set of values.
The text was updated successfully, but these errors were encountered:
Actually, on further inspection I think this is just a duplicate of #726.
The error message on that issue matches that shown on this issue if you re-run the code with current traits/traitsui versions. It must have been a different message in prior versions.
The documentation for the
EnumEditor
states that thevalues/name
kwargs are only required if the trait being edited is not "an enumeration". https://docs.enthought.com/traitsui/traitsui_user_manual/factories_basic.html#enumeditorThe way things are worded make it seem like you should not need to pass in
values
if the trait being edited is an enumeration, however that does not appear to work as intended. See example below:In the above example the code works as intended when the
value
kwarg forEnumEditor
is provided. However if you comment out or remove that line, then the code fails with the following message:traits.trait_errors.TraitError: Invalid value for 'values' specified
.Possibly related issue (though the error message is different): #726
While passing through
values
to the editor is not difficult, the way the docs are worded it sounds like you should not need to. Additionally, for simple cases such as above where the intent is simply to display a static list of pre-defined values, it results in unnecessary code duplication. The underlyingEnum
trait already knows about the set ofvalues
.The text was updated successfully, but these errors were encountered: