1

I am trying to make a Traits gui base class and I have other classes that I want to inherit some items (i.e. groups) from this class. I do not want to completely inherit the view between these classes, just some of the objects.

When I try

For example:

from enthought.traits.api import Int, Str, Array, Instance, HasTraits, Float, Enum, Bool, Range
from enthought.traits.ui.api import View, Group, HGroup, VGroup, Item, spring

class A(HasTraits):
u = Int(23)
i = Int(66)
group1 = Group(Item('u'))
group2 = Group(Item('i'))
main = View(group1,group2)

class B(A):
group1 = a.group1 # I have tried this with a().group1 as well
o = Str('4345')
p = Str('3423')
group2 = Group(Item('o'))
group3 = Group(Item('p'))
main = View(group1,group2,group3)

#----------

I know that this is a ridiculous example, but it illustrates the point. When try to make an instance of class B, I get the error that class A does not have the attribute 'group1'.

In normal python classes this would not be a problem, but somehow these TraitsUI Group objects are hidden. Does anyone know if there is a workaround?

This does work with other Traits type (i.e. Int() ), just not with Groups as far as I've tested.

Thanks!

1 Answers1

1

This may help: Traits UI User Guide / Advanced View Concepts / Include Objects

Jonathan March
  • 5,800
  • 2
  • 14
  • 16
  • 1
    Also, the enthought namespace and traits.ui subpackage have been deprecated for several years. Use traits.api and traitsui.api – Jonathan March May 06 '14 at 21:45
  • This does work. When I read this I thought that the Include class was deprecated, but it works as documented! – user3609866 May 08 '14 at 21:52