[Enthought-dev] Listening for List Item Changes for Another Object

Peter Wang pwang at enthought.com
Mon Aug 6 12:39:35 CDT 2007

You can listen for changes on a particular trait of a list of items  
by using static list handlers: https://svn.enthought.com/enthought/ 

So, you can have a static handler on B that will activate whenever  
any of its A instances change:

class A(HasTraits):
     enabled = Bool(True)

class B(HasTraits):
     my_list = List(Instance(A))

     def _enabled_changed_for_my_list(self, event):
         print "enabled changed:", event

Unfortunately, this only seems to work with static handlers, so you  
will have to create an Event trait on B that has gets fired, and have  
C listen for that.

On Aug 6, 2007, at 12:12 PM, Alexander Michael wrote:

>>>> a = A()
>>>> b = B(my_list=[a, A()])
>>>> c = C(b)
>>>> a.enabled = True
> Something has been enabled!

Note that in the specific example code you posted, you won't get an  
event since a.enabled defaults to True, and traits doesn't fire  
events unless the value has changed.


More information about the Enthought-Dev mailing list