hajicj / MUSCIMarker

Tool for annotating objects in musical scores.
http://muscimarker.readthedocs.io/en/latest/
Apache License 2.0
7 stars 2 forks source link

Indestructible info labels on mass delete #175

Closed hajicj closed 6 years ago

hajicj commented 6 years ago

Only one info label gets deleted when multiple CropObjects are destroyed (either with simple delete, or with destructive merge).

hajicj commented 6 years ago

Tracked this down to the interplay between:

update_cropobject_data() --> adapter.update_for_new_data() --> adapter.initialize_selection() --> adapter.selection = []

and

CropObjectView.ensure_deselected() --> CropObjectView.on_release() (bound by ListAdapter.create_view()) --> adapter.handle_selection() --> adapter.selection

The change in adapter.selection on the data update does not propagate into the CropObjectViews, so by the time they are supposed to be deselected, they are already not in adapter.selection and therefore adapter.handle_selection() falls into the "toggle this one on" instead of "toggle this one off" code branch.

Furthermore, this happens silently: when CropObjectView.select() is called, it does nothing: the info label already exists, so it is not re-created, and its background color is set to the selected version, which it already has -- deselect has never been called.

hajicj commented 6 years ago

Solution: add a function to sync the selection status of CropObjectViews to adapter selection. Do this through the adapter.on_selection_change event, which is exactly the kind of thing the event is meant for.