enthought / enthought/traitsui
EnumEditor does not pickup values from Enum trait as suggested in documentation
- Dominant language
- Python
- Stars
- 306
- Forks
- 99
- PR merge metrics
- No merged PRs in 30d
Description
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 traits.api import Enum, HasStrictTraits
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): https://github.com/enthought/traitsui/issues/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`.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.