enthought / enthought/traitsui

ListStrEditor doesn't update selection when selection becomes invalid

Open
#872 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

Qt and wx editor maintain selection differently during `update_editor` (see issue #868 point 4) so there are two separate examples. But the result of no longer valid selection is the same between both -- they don't update the selection which might lead to unexpected results down the line:

QT:
``` python

class Foo(HasTraits):
values = List(Str)
selected_index = Int()
selected = Str()

view = View(
Item(
"values",
editor=ListStrEditor(
selected_index="object.selected_index",
selected="object.selected"
)
)
)

demo = Foo(values=["one", "two", "three"], selected="one")
ui = demo.edit_traits()

# Removing "one" creates a case of no longer valid selection
demo.value = ["two", "three"]
# Visually selection is removed, but the editor (and user model) state isn't
print(demo.selected_index) # prints 0
print(demo.selected) # prints "one"
# Setting selected index hoping to select "two"
demo.selected_index = 0
# Selected_index didn't really change, so editor (and user model) state isn't updated
print(demo.selected_index) # prints 0 as expected
print(demo.selected) # prints "one" but should print "two"

ui.dispose()
```
WX:
``` python
class Foo(HasTraits):
values = List(Str)
selected_index = Int()
selected = Str()

view = View(
Item(
'values',
editor=ListStrEditor(
selected_index="object.selected_index",
selected="object.selected"
)
),
)

demo = Foo(values=["one", "two", "three"], selected_index=1)
ui = demo.edit_traits()

# Shortening the list create a case of no longer valid selection
demo.value = ["two"]
# Visually selection is removed, but the editor (and user model) state isn't
print(demo.selected_index) # prints 1
print(demo.selected) # prints "two"
# Setting selected hoping to select item "two" at index 0
demo.selected = "two"
# Selected didn't really change, so editor (and user model) state isn't updated
print(demo.selected_index) # prints 1 but should print 0
print(demo.selected) # prints "two" as expected

ui.dispose()
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by tracing ListStrEditor.update_editor in the Qt and wx editor implementations, comparing how each handles a selection that becomes invalid. Reproduce the examples in the issue and verify that removing the selected item updates the selection state, including when the replacement value or index is unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
desktop
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.