Skip to content

Remove thing_changed Event traits if possible #604

@aaronayres35

Description

@aaronayres35

Problem Description
I personally find it very confusing to have a trait named thing_changed = Event which explicitly gets set to True when thing changes. Chaco will often listen to that trait when setting up change handlers, but I am not seeing why we couldn't just listen to the trait itself. e.g why do something like observe(_____, thing_changed) instead of just observe(_____, thing).
I may be missing something important as to why this is needed but as far as I can tell it is not.

See #601 which removed the metadata_changed event trait. Other examples include:

#: Event fired when the index data changes. Subclasses can listen for this
#: event and take appropriate steps (except for requesting a redraw, which
#: is done in this class).
index_data_changed = Event
#: Event fired when the index mapper changes. Subclasses can listen for this
#: event and take appropriate steps (except for requesting a redraw, which
#: is done in this class).
index_mapper_changed = Event
#: Event fired when the value data changes. Subclasses can listen for this
#: event and take appropriate steps (except for requesting a redraw, which
#: is done in this class).
value_data_changed = Event

chaco/chaco/base_2d_plot.py

Lines 278 to 284 in ef72277

def _update_index_data(self, event=None):
""" Updates the index data.
Called by various trait change handlers.
"""
self.index_data_changed = True
self.invalidate_draw()

chaco/chaco/base_2d_plot.py

Lines 313 to 332 in ef72277

def _index_changed(self, old, new):
if old is not None:
old.obseve(self._update_index_data, "data_changed", remove=True)
if new is not None:
new.obseve(self._update_index_data, "data_changed")
self._update_index_data()
def _value_changed(self, old, new):
if old is not None:
old.observe(self._update_value_data, "data_changed", remove=True)
if new is not None:
new.observe(self._update_value_data, "data_changed")
self._update_value_data()
def _index_mapper_changed(self, old, new):
if old is not None:
old.observe(self._update_index_mapper, "updated", remove=True)
if new is not None:
new.observe(self._update_index_mapper, "updated")
self._update_index_mapper()

In any case, if there is a reason that something like this needs to be done, we should still make an effort to clean this code up and make it more easily understandable / better documented of why things are like this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions