List of Instances in traitsui

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

List of Instances in traitsui

Hanno Klemm
Hi,

I have the following problem: I have a list of instances of a class. If
I want to have them displayed they all are called 'value' in the view.
Does there exist a possibility to change this?

The following example code should make clear what I mean: I would
expect the editor to show 'Some name' instead of 'value'. I'm using
traitsui 4.0



from traits.api import HasTraits, List, Str, Instance
from traitsui.api import View, Item

class Thing(HasTraits):
     thing_name = Str('A nice name')


     def __repr__(self):
         return thing_name

class MoreThings(HasTraits):

     thingies = List( Instance( Thing ) )
     view = View(Item('thingies', resizable=True),
                 resizable=True)

theThing = Thing( thing_name='Some name')
myThings = MoreThings( thingies = [theThing] )

myThings.configure_traits()



Many thanks,
Hanno

--
Hanno Klemm
[hidden email]

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: List of Instances in traitsui

Tiago Pereira
Hi,

On 31/7/12 8:03 AM, Hanno Klemm wrote:
> I have the following problem: I have a list of instances of a class. If
> I want to have them displayed they all are called 'value' in the view.
> Does there exist a possibility to change this?

You can use the 'label' attribute in View, like this:

view = View(Item('thingies', label='Some name'), resizable=True)


Cheers,

Tiago
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev