enthought/chaco

Bug in RangeSelection

Opened this issue · 0 comments

Problem Description

Changing the index_mapper on our ColorBar now produces the following error on Chaco 5.0.0. This problem does not occur in 4.8.0.

Traceback (most recent call last):
  File "/Users/charris/.edm/envs/seismic36/lib/python3.6/site-packages/traits/observation/_trait_event_notifier.py", line 122, in __call__
    self.dispatcher(handler, event)
  File "/Users/charris/.edm/envs/seismic36/lib/python3.6/site-packages/traits/observation/observe.py", line 27, in dispatch_same
    handler(event)
  File "/Users/charris/.edm/envs/seismic36/lib/python3.6/site-packages/chaco/tools/range_selection.py", line 700, in _axis_mapper_updated
    self.deselect()
  File "/Users/charris/.edm/envs/seismic36/lib/python3.6/site-packages/chaco/tools/range_selection.py", line 193, in deselect
    self.selection = None
  File "/Users/charris/.edm/envs/seismic36/lib/python3.6/site-packages/chaco/tools/range_selection.py", line 633, in _set_selection
    l.set_value_selection(val)
  File "/Users/charris/.edm/envs/seismic36/lib/python3.6/site-packages/chaco/plots/cmap_image_plot.py", line 81, in set_value_selection
    del self.value.metadata["selection_masks"]
  File "/Users/charris/.edm/envs/seismic36/lib/python3.6/site-packages/traits/trait_dict_object.py", line 199, in __delitem__
    super().__delitem__(key)
KeyError: 'selection_masks'

The issue seems to originate in the changes made in #591 and #601. We are currently working around the issue with the following patch, which simply reverts the changes made in those PRs.

class PatchedRangeSelection(RangeSelection):
    def _axis_mapper_updated(self, event):
        pass

    def __mapper_changed(self, event):
        self.deselect()

    def _axis_changed(self, old, new):
        if old is not None:
            self.plot.on_trait_change(
                self.__mapper_changed, old + "_mapper", remove=True)
        if new is not None:
            self.plot.on_trait_change(
                self.__mapper_changed, old + "_mapper", remove=True)