adding nested HasTraits properties to a TraitsUI TView

天涯浪子 提交于 2019-12-10 11:42:18

问题


i have a main HasTraits class which contains several Instance's of other HasTraits objects. I would like to define an Item in the view of the main object which points to a trait of a nested object. for example:

class Person(HasTraits):
    name = String()

class Pet(HasTraits):
    name = String()


class Family(HasTraits):
    father = Instance(Person,())
    dog = Instance(Pet,())

    view = View(
        Item('father.name'),
        Item('dog.name'),
        )

is this possible?

thanks!


回答1:


Somebody named Alex asked this question 1 week ago by email, and we responded:

view = View(
    Item('object.father.name'),
    Item('object.dog.name'),
    )

See the bottom of http://docs.enthought.com/traitsui/traitsui_user_manual/advanced_view.html#multi-object-views

If you are the same Alex, you might want to tweak your spam filters (enthought.com and enthought.zendesk.com)



来源:https://stackoverflow.com/questions/19566477/adding-nested-hastraits-properties-to-a-traitsui-tview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!