亲爱的社区成员,
我目前遇到了TableEditor
的{{1}}属性(特征版本4.5.0,traitsui版本4.5.1,Ubuntu)的问题。问题仅出现在一种特殊的Matryoshka结构中,如下面的代码所示。基本上,无论如何,selected
都会指向selected
。相应地,观察特征变化是行不通的。
以下是我的观点的代码:
None
如果你现在按下了什么?'按钮,无论您点击from traits.api import HasTraits, List, Str, Float, Instance, Button
from traitsui.api import View, Item, TableEditor
from traitsui.table_column import ObjectColumn
table_editor = TableEditor(
selected = 'selected_guy',
columns = [ObjectColumn(name = 'name' , label = 'Name'),
ObjectColumn(name = 'height', label = 'Height in meters')]
)
class TallGuy(HasTraits):
name = Str('')
height = Float(0) #in meters
class BunchOfTallGuys(HasTraits):
selected_guy = Instance(TallGuy)
bunch_of_guys = List(TallGuy,
editor = table_editor)
whats_going_on = Button('What\'s going on?')
def _whats_going_on_changed(self):
print 'id of None: ', id(None)
print 'id of selected_guy: ', id(self.selected_guy)
#this still works fine, the problem arises on the next level
class BunchWrapper(HasTraits):
bunch = Instance(BunchOfTallGuys, required=True)
traits_view = View(
Item('object.bunch.bunch_of_guys', style='custom'),
Item('object.bunch.whats_going_on')
)
def __init__(self):
self.bunch = BunchOfTallGuys()
self.bunch.bunch_of_guys.append(TallGuy(name='Larry', height = 1.8))
self.bunch.bunch_of_guys.append(TallGuy(name='Garry', height = 2.0))
self.bunch.bunch_of_guys.append(TallGuy(name='Jerry', height = 1.95))
bw = BunchWrapper()
bw.configure_traits()
中的哪一行,您都会看到None
和selected_guy
特征的ID保持不变。这是预期的行为吗?您是否有任何解决方法,允许使用TabularEditor
结构,这对我来说有利于保持我的代码排列良好?
欢迎任何建议!
此致
扬