Equivalent to __repr__ for TraitsUI?

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

Equivalent to __repr__ for TraitsUI?

Des.P
Is there a single method (like  __repr__ or toString) I can define on my classes to customize the string that represents an instance everywhere on a TraitsUI e.g. in tables, drop-down menus, trees, text boxes, etc?

Thanks!


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

Re: Equivalent to __repr__ for TraitsUI?

Robert Kern
On Tue, Oct 9, 2012 at 3:39 PM, Des.P <[hidden email]> wrote:
> Is there a single method (like  __repr__ or toString) I can define on my classes to customize the string that represents an instance everywhere on a TraitsUI e.g. in tables, drop-down menus, trees, text boxes, etc?

I don't think it's universal everywhere, but many Traits UI elements
will use str() on the object if it needs to get a string
representation of an arbitrary object.

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

Re: Equivalent to __repr__ for TraitsUI?

Des.P

On Oct 9, 2012, at 9:46 AM, Robert Kern wrote:

> On Tue, Oct 9, 2012 at 3:39 PM, Des.P <[hidden email]> wrote:
>> Is there a single method (like  __repr__ or toString) I can define on my classes to customize the string that represents an instance everywhere on a TraitsUI e.g. in tables, drop-down menus, trees, text boxes, etc?
>
> I don't think it's universal everywhere, but many Traits UI elements
> will use str() on the object if it needs to get a string
> representation of an arbitrary object.

Hmm. I defined __repr__(self) for my trait classes, and verified that str(obj) shows my representation, but I could not get this representation to show up in my UIs.

InstanceEditor seems to rely on a name() trait for customized display in its instance selection drop-down, so I defined a name property. But then  I could not seem to get name() used in any other (non InstanceEditor) UIs either.

List(Tuple(MyClass,Int)) seems to show a generic 'F0' button for the MyClass component of the tuple. I cannot figure out how to get some other string in place of 'F0'.

I'm a bit lost on how to customize my classes so my objects can be identified on the UIs. Any suggestions?

Thanks!

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