6 Sep 11:51
Re: [Traits] feature request
G'day,
Prabhu Ramachandran wrote:
> Hi Dave Morrill,
>
> I see from the implementation (from trunk) that the CHasTraits class
> defines a _trait_change_notify method that is used in the trait_set
> method to disable/enable notifications. Unfortunately, there is no way
> to determine from Python if this flag has been set or not. This is
> needed if you want to create a Property trait that does the right thing
> in its set method. For example:
>
> class Test(HasTraits):
> x = Property(Float)
> _x = Float
> def _get_x(self):
> return self._x
> def _set_x(self, value):
> old = self._x
> self._x = value
> if old != new:
> self.trait_property_changed('x', old, new)
>
> Clearly, this will break the trait_set method when
> trait_change_notify=False. I propose to add a
> _get_trait_change_notify() to the ctraits.c to be able to get this so
> users can write:
>
> if self._get_trait_change_notify():
> ...
>
> etc. to work around this.
Hmmm... I wouldn't want to have to put this line in every property setter... smells like
duplication... Couldn't the 'trait_property_changed' method handle the check?
Martin
RSS Feed