enthought / enthought/traitsui
ListEditor loses focus per keystroke if the edited item is too nested
- Dominant language
- Python
- Stars
- 306
- Forks
- 99
- PR merge metrics
- No merged PRs in 30d
Description
When the list item is nested, editing the item leads to focus leaving the editor at every keystroke:

To reproduce (same example as in https://github.com/enthought/traitsui/issues/403#issuecomment-547445747):
```
from traits.api import HasTraits, Float, List, Instance
from traitsui.api import ModelView, View, Item
class Child(HasTraits):
play_list = List(Float(), [1, 2, 3, 4])
class Model(HasTraits):
child = Instance(Child, ())
class ListEditorDemo(ModelView):
# The Trait to be displayed in the editor
model = Instance(Model)
def default_traits_view(self):
return View(
Item('model.child.play_list', label='Simple'),
title='ListEditor',
height=400,
width=400,
)
popup = ListEditorDemo(model=Model())
if __name__ == '__main__':
popup.configure_traits()
```
Offline discussion with @corranwebster:
- If `play_list` is moved under `ListEditorDemo.model`, then this issue is not observed. We suspect the issue is related to how the extended name ("model.child.play_list") is used together with traits change listener, e.g. here:
https://github.com/enthought/traitsui/blob/c13f87a33c35ade082ef6f85729d5427d59b3cd0/traitsui/qt4/list_editor.py#L491-L494
- The focus is lost because the entire list panel is being refreshed when the list content is changed. We can verify this by adding a `print` statement in https://github.com/enthought/traitsui/blob/c13f87a33c35ade082ef6f85729d5427d59b3cd0/traitsui/qt4/list_editor.py#L146
The value change happens here: https://github.com/enthought/traitsui/blob/2c11874d55097dcf8d047273df6de1e175c258ac/traitsui/editors/list_editor.py#L217
- This behaviour may be a desired feature for use cases where the list item is an instance and the UI needs to be refreshed when an instance is replaced with another. Naively fixing this issue for float items may break other use cases.
Workaround:
- One can workaround this issue by setting `auto_set` to `False`, so the list does not actually change at every keystroke and the focus is not lost while the user is typing.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.