enthought / enthought/traitsui

EnumEditor unable to deduce allowed values from Enum trait

Open
#726 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
306
Forks
99
PR merge metrics
No merged PRs in 30d

Description

To reproduce:
```
from traits.api import HasTraits, Enum

from traitsui.api import Item, View, EnumEditor

class EnumEditorDemo(HasTraits):
""" Defines the main EnumEditor demo class. """

name_list = Enum('A-495', 'A-498', 'R-1226', 'TS-17', 'TS-18',
'Foo', 12345, (11, 7), None)

def default_traits_view(self):
return View(
Item(
'name_list', style='simple',
editor=EnumEditor(),
label='Simple'
),
)

if __name__ == '__main__':
EnumEditorDemo().configure_traits()
```

We get this error:
```
Traceback (most recent call last):
File "examples/demo/Standard_Editors/dummy.py", line 31, in
demo.configure_traits()
File "/Users/kchoi/ETS/traits/traits/has_traits.py", line 2083, in configure_traits
args,
File "/Users/kchoi/ETS/traitsui/traitsui/qt4/toolkit.py", line 233, in view_application
context, view, kind, handler, id, scrollable, args
File "/Users/kchoi/ETS/traitsui/traitsui/qt4/view_application.py", line 85, in view_application
context, view, kind, handler, id, scrollable, args
File "/Users/kchoi/ETS/traitsui/traitsui/qt4/view_application.py", line 127, in __init__
args=self.args,
File "/Users/kchoi/ETS/traitsui/traitsui/view.py", line 463, in ui
ui.ui(parent, kind)
File "/Users/kchoi/ETS/traitsui/traitsui/ui.py", line 247, in ui
self.rebuild(self, parent)
File "/Users/kchoi/ETS/traitsui/traitsui/qt4/toolkit.py", line 163, in ui_live
ui_live.ui_live(ui, parent)
File "/Users/kchoi/ETS/traitsui/traitsui/qt4/ui_live.py", line 44, in ui_live
_ui_dialog(ui, parent, BaseDialog.NONMODAL)
File "/Users/kchoi/ETS/traitsui/traitsui/qt4/ui_live.py", line 66, in _ui_dialog
BaseDialog.display_ui(ui, parent, style)
File "/Users/kchoi/ETS/traitsui/traitsui/qt4/ui_base.py", line 285, in display_ui
ui.owner.init(ui, parent, style)
File "/Users/kchoi/ETS/traitsui/traitsui/qt4/ui_live.py", line 226, in init
self.add_contents(panel(ui), bbox)
File "/Users/kchoi/ETS/traitsui/traitsui/qt4/ui_panel.py", line 261, in panel
panel = _GroupPanel(content[0], ui).control
File "/Users/kchoi/ETS/traitsui/traitsui/qt4/ui_panel.py", line 603, in __init__
layout = self._add_items(content, inner)
File "/Users/kchoi/ETS/traitsui/traitsui/qt4/ui_panel.py", line 877, in _add_items
editor.prepare(inner)
File "/Users/kchoi/ETS/traitsui/traitsui/editor.py", line 241, in prepare
self.init(parent)
File "/Users/kchoi/ETS/traitsui/traitsui/qt4/enum_editor.py", line 168, in init
control.addItems(self.names)
TypeError: addItems(self, Iterable[str]): argument 1 has unexpected type 'NoneType'
```

If I remove this line and let traitsui cleverly guess the editor:
```
editor=EnumEditor(), # remove this
```
Then the UI can be launched with the expected behaviour.

Similarly, if I have the allowed values in a separate trait, this raises the same error
```
name_list = Enum(values="allowed_values")
allowed_values = List(["A-495", "A-498"])

def default_traits_view(self):
return View(
Item(
'name_list', style='simple',
editor=EnumEditor(),
label='Simple'
),
)
```
I need to do this instead:
```
editor=EnumEditor(values="allowed_values"),
```

Given the `name_list` trait already specifies where the allowed values come from, it seems unnecessary to have to tell the editor *again*.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.