开发者

Python (Enthought) Tuple / List Trait: how to access a specific element?

Let's sa开发者_运维问答y I have a HasTraits object with a Tuple or a List attribute. Is there a way to set up an editor that would display (or allow to edit, in the case of a List), for example, only the first element of the sequence?

Thanks.


On the epd-users mailing list, I got the following answer: define a new trait as a property that depends on the tuple, and create an editor for this new Property.

Something like:

tuple = Tuple(blah)
t0 = Property(depends_on="tuple", fget=lambda self: self.tuple[0])

(and likewise a setter if necessary).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜