enthought / pyface

pyface: traits-capable windowing framework
Other
105 stars 55 forks source link

`ListeningAction` doesn't track state correctly when updating a connection #1084

Closed corranwebster closed 2 years ago

corranwebster commented 2 years ago

This also affects TaskAction and other ListeningAction subclasses.

Code like the following doesn't work as expected:

class WatchedObject(HasTraits):

    #: Trait to watch for enabled state
    is_enabled = Bool(False)

object = WatchedObject()
action = ListeningAction(object=object, enabled_name="is_enabled")

assert not action.enabled

A similar problem occurs with visible instead of enabled.

When the trait observers are connected to a new object or trait to listen to (including at object init time) the current value of the observed trait is not being transferred across to the action, so the action and the object watched can start in an out-of-sync state.

This hadn't been noticed presumably due to defaults generally agreeing (most actions are going to start enabled and visible).

corranwebster commented 2 years ago

Looks like this isn't quite as expected - it is updating, just not the way that I expected - but is probably OK