1

我无法使用 nested 让视图按预期工作HasTraits。例如:

class A(HasTraits):
    b= Any()

...
view = View(...
    Item('b', style='custom')
...

我想导入 b 的类并将其分配给 A,

from some_other_mod import B 
# B HasTraits also
a = A(b = B())

这有效,但是B()aa.configure_traits()

(注意这是相关的,但与这篇文章不同)

4

1 回答 1

2

您需要使用InstanceEditor.

class A(HasTraits):
    b = Instance(HasTraits)
    traits_view = View( Item('b', editor=InstanceEditor(), style='custom') )

class B(HasTraits):
    c = Int
    traits_view = View( Item('c') )

请注意,一个Instance特征InstanceEditor默认使用一个。默认情况下,Any特征使用 aTextEditor代替。

于 2015-06-08T20:54:55.343 回答