I am using the Python trait set, and I am trying to figure out the correct way to use the traits.trait_numeric.Array class. Directly write a subclass of traits.api.HasTraits with the sign of an array, so when Array changes, on_trait_change is fired, but I canβt figure out how to trigger any event when the elements of the array are changed in place. Here is a minimal example:
from traits.api import HasTraits from traits.trait_numeric import Array import numpy as np class C(HasTraits): x = Array def __init__(self): self.on_trait_event(self.do_something, 'x') def do_something(self): print 'Doing something' c = C()
I hope there is some built-in function traits.trait_numeric.Array that I do not know about, since detecting when a part of the array has changed seems to be very standard what is needed.
Denying this, I think the problem can be resolved by creating a custom attribute class that also inherits numpy.array and then changes the [] operator so that it explicitly calls the correct attribute event types. But I hope this may be a worm that I donβt have to open.
source share