enthought / enthought/traitsui

ListEditor loses focus per keystroke if the edited item is too nested

Open
#680 0 comments 0 reactions 0 assignees View on GitHub
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:
![Oct-30-2019 16-16-50](https://user-images.githubusercontent.com/3673984/67877130-eb86e900-fb30-11e9-8f8f-2396beecca66.gif)

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.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.