Multi Object View Behaviour - Creating an Editor for a HasTraits subclass

跟風遠走 提交于 2019-12-06 15:03:40

Would something like this work? It simplifies things a little bit and gives you a view that contains the list of views for your houses.

# multi_object_view.py -- Sample code to show multi-object view
#                         with context

from traits.api import HasTraits, Str, Int, Bool
from traitsui.api import View, Group, Item,InstanceEditor

# Sample class
class House(HasTraits):
    address = Str
    bedrooms = Int
    pool = Bool
    price = Int

    traits_view =View(
        Group(
            Item('address'), Item('bedrooms'), Item('pool'), Item('price')
        )
    )


class Houses(HasTraits):
    house1 = House()
    house2= House()
    house3 = House()

    traits_view =View(
        Group(
            Item('house1', editor=InstanceEditor(), style='custom'),
            Item('house2', editor=InstanceEditor(), style='custom'), 
            Item('house3', editor=InstanceEditor(), style='custom')
        )
    )

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