属性特征“depends_on”

时间:2014-12-12 13:33:37

标签: python enthought traits

给定基于traits的类Material-class,Base-class和Child-class(派生自Base-class),如果Child-class的Property-trait b仅依赖于{,则运行以下代码{1}}或a属性,即

x

b = Property(Float, depends_on=['a'])

但不是如果它取决于两者:

b = Property(Float, depends_on=['x'])

为什么?

b = Property(Float, depends_on=['a','x'])

1 个答案:

答案 0 :(得分:2)

您可以通过不使用DelegatesTo解决这个问题,只收听m.a上的更改:

class Child(Base):
    m = Instance(Material)
    b = Property(Float, depends_on=['m.a','x'])   # <-- runs

    def _get_b(self):
        return self.a * self.x

委托的问题似乎与设置监听器有关。我得到的错误信息是

DelegationError: The 'a' attribute of a 'Child' object has a delegate which does not have traits.

相关问题