enamlx
enamlx copied to clipboard
Selected Items are wrong on multi select
Enamlx.TableView seems to have a incorrect support for selection
In examples/table_view/table_view.enaml
simply add to the table looper the two lines below in TableViewRow->clicked :
Looper:
#: Max number of visible rows
#: If this number is too small, stuff will get jacked
iterable << range(table.visible_rows)
TableViewRow:
row << table.visible_row+loop_index
attr person << table.items[self.row]
clicked ::
print("Row %s clicked!" % self.row)
print(f" Enamlx Selection : {self.parent.selection}")
print(f"Underlying widget selection: {self.proxy.widget.selectedIndexes()}" )
(You probably should also comment out the updating thread that mess with the data)
Select one row : everything looks fine Select two rows (two items in two rows) : only one in table.selection, 2 in the widget Do a SHIFT+click selection on multiple items: there is at best one more item in qt widget selection than in the enamlx widget Do a CTRL+Click on multiple items : Only one in the enamlx.selection, the correct list in the underlying Qt widget ..
Is this the correct behavior ? Is there a way to get the proper selection at the enamlx level ?
Thanks for reporting this. I pushed a fix, can you please give it a try?
Sorry I missed your answer. I will check it out. ASAP In the meantime I kept working around several warts I found (Deletion is the great revealer ;) ) and made a repos with a few examples of "not working thing" and workarounds, I will upload it on github and put the link up here.
Added the repos here thub.com/Annakan/EnamlxTableView_warts Readme except
what is this about
This repos contains both some experiments showing small bug/warts in enamlx TableView and ways to work around then and have a working Qt grid in enaml.
what's in it
Directories table_view2/3/4 contain working programs that show working TableView usages while supporting deletion, including deletion of currectly "in-view" items and multiple item selection.
They contain a small readme that explain the sample, the encoutered "bugs" and the strategy used to work around them.
Perfect !!! Selection is working perfectly. Do you want me to turn the above comment into a separate "issue" (and I shall update it with the selection working too) ?
Yes, please create a separate issue for each. Thanks!
I adapted my tests to check further on the selection here : https://github.com/Annakan/EnamlxTableView_warts/tree/master/table_view4
There seem to still be a flaw about the selection not being updated when the underlying objects change (i.e. are destroyed). To reproduce :
- select a few items
- press remove button once => the grid is updated and the selection stays in place (standard Qt table behavior AFAIK)
- press the remove button again => nothing happens and in fact we are trying to delete the same items again (defensive programming in remove_items in table_model.py prevents that but you can see the print out)
I don't know if "'selected" should be "anything more" than a thin wrapper around the QTableView selectedIndexes() method (because mapping back to self.items can be complicated to "wrap"), but if it can't be that thin wrapper, the cause of the problem might be that the selection is not taking proper subscriptions to the objects it references.
PS: I could clear the selection after the removal but I think it the wrong solution to this because it would only hide that the selection is not a correct view on the underlying items of the selected rows/collums/cells and the same problem could be triggered by any other method modifying objects that happen to be selected