10 Sep 23:05
Re: [Traits] dirty trait metadata
Prabhu:
I just added support for the new 'comparison_mode' metadata, which can
(legally) have one of the three values:
- NO_COMPARE: Change fired on every assignment.
- OBJECT_IDENTITY_COMPARE: Change fired if old value is not the same
object as the new value.
- RICH_COMPARE: Change fired if old value does not compare equal to
the new value (the standard traits default).
So you should now be able to implement your example by declaring:
class Data(HasTraits):
x = Array( comparison_mode = NO_COMPARE )
Of course, if you intend to use a lot of these, you should probably do something like:
NCArray = Array( comparison_mode = NO_COMPARE )
class Data(HasTraits):
x = NCArray
y = NCArray
...
The old 'rich_compare' metadata is now deprecated in favor of the new 'comparison_mode' metadata. I've
modified the default Array trait definition to use comparison_mode = OBJECT_IDENTITY_COMPARE instead
of the old rich_compare = False.
Hope this helps...
Dave Morrill
Prabhu Ramachandran wrote:
> Hi,
>
> Consider the following:
>
> -----------------
> from numpy import *
> from enthought.traits.api import *
> class Data(HasTraits):
> x = Array
> def _x_changed(self, value):
> print value
>
> x = linspace(0, 1)
> d = Data(x=x)
> -------------------
>
> Now I'd like to always call _x_changed when the x trait is set. Thus,
> I'd like this to work:
>
> x *= 2
> d.x = x # Should call _x_changed
>
> Is there a simple way of doing this? I know that I could achieve this
> if I implemented x as a Property(Array) but is there an easier way?
>
> Thanks.
> prabhu
>
> _______________________________________________
> Enthought-dev mailing list
> Enthought-dev@...
> https://mail.enthought.com/mailman/listinfo/enthought-dev
>
>
RSS Feed