enthought / enthought/traitsui
False selection state in TableEditor after deleting a row
- Dominant language
- Python
- Stars
- 306
- Forks
- 99
- PR merge metrics
- No merged PRs in 30d
Description
After the selected item is deleted from the list, I'm left with an inconsistent selection state. My case is with `selection_mode='rows'`:
- The row (at the position of the deleted row) is highlighted though it is not selected internally (by `selected` trait).
- The `selected` trait still points to the deleted item.
- Then the highlighted row cannot be selected (for just selection or context menu) until another row is clicked first.
Adding something like `self.selected = []` after the deletion fixed that. (Removing items in `self.selected` didn't help. Perhaps listening to list items isn't working or implemented.) Still, I feel this should be fixed in TableEditor.
I'm using Ubuntu 18.04 and traitsui 6 and 7. Here's my example script:
```python
from traits.api import *
from traitsui.api import *
class Row(HasTraits):
col1 = Int()
col2 = Int()
def __repr__(self):
return f''
class Table(HasTraits):
rows = List(Row)
class TableView(ModelView):
model = Instance(Table)
selected = List
check_button = Button()
remove_button = Button()
def _check_button_fired(self):
print(self.selected)
def _remove_button_fired(self):
self.model.rows.remove(self.selected[0])
# Uncomment to bypass selected* non-update bug
# self.selected = []
# This doesn't help
# self.selected.pop()
def default_traits_view(self):
columns = [
ObjectColumn(name='col1', style='readonly'),
ObjectColumn(name='col2', style='readonly'),
]
view = View(
Item(
'object.model.rows',
editor=TableEditor(
columns=columns,
selection_mode='rows',
selected='selected',
selected_indices='selected_indices',
),
),
Item('check_button'),
Item('remove_button'),
)
return view
table = Table(rows=[
Row(col1=i, col2=i) for i in range(5)
])
view = TableView(model=table)
view.configure_traits()
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.