Question

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!

Was it helpful?
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top