EnumEditor does not pickup values from Enum trait as suggested in documentation
Opened this issue · 1 comments
The documentation for the EnumEditor
states that the values/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#enumeditor
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
.