1

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!

alex
  • 2,968
  • 3
  • 23
  • 25

1 Answers1

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)

Jonathan March
  • 5,800
  • 2
  • 14
  • 16
  • thanks, and you are correct, the gmail spam-filter snagged it. – alex Oct 25 '13 at 13:26
  • i believe that my objects are not independent, as required by that solution. the above example is trivial but in the real application the object represented by Family contains its own functionality which requires information from Person and Pet. I want to retain the Family class, but simply tweak the views of Person and Pet. – alex Oct 25 '13 at 13:33
  • Are you mentioning this because there is a problem? The "object" syntax is particular to the View. For Python object references, you can proceed normally -- e.g. within a method of Family, refer to self.father.name. Does this help? – Jonathan March Oct 26 '13 at 00:54
  • yes your solution works, thanks! the docs had a different usage. also, my indention was incorrect in the original question and has been fixed. – alex Oct 29 '13 at 19:12