1

Is there a way to define multiple views for a HasTraits object, and choose them when displaying them as an Item?

class Person(HasTraits):
    first_name = String()
    last_name = String()

    formal_view = View(
        Item('first_name'),
        Item('last_name'),
        )
    familiar_view = View(
        Item('first_name')
        )

class Family(HasTraits):
    formal_father = Instance(Person,())
    familiar_father = Instance(Person,())


    view = View(
        Item('formal_father', style = 'custom'),
        Item('familiar_father', style = 'custom', 
             view = 'familiar_view'),
        )

The keyword view in the last Item is just to illustrate how i would expect it to work.

alex
  • 2,968
  • 3
  • 23
  • 25

1 Answers1

2

Yep, you've almost got it. See http://code.enthought.com/projects/traits/docs/html/TUIUG/advanced_view.html#defining-multiple-views-within-the-model

Jonathan March
  • 5,800
  • 2
  • 14
  • 16