Undefined Enum

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

Undefined Enum

Martin Gustafsson
Hello,

Is there a way for an Enum trait to default to Undefined?

Use case: An Enum with the states "off" and "on" represents the output of an instrument, and a handler function for that Enum communicates the state to the hardware. I cannot talk to the hardware in a default handler, since the instrument is not initialized until its __init__() method has executed. Whether I first assign "on" or "off" to the trait, I would like the handler to execute. At the same time, I don't want to have "undefined" to be a proper value for the Enum and show up in editors and such.

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

Re: Undefined Enum

Robert Kern
On Thu, Dec 20, 2012 at 10:28 PM, Martin Gustafsson
<[hidden email]> wrote:
> Hello,
>
> Is there a way for an Enum trait to default to Undefined?
>
> Use case: An Enum with the states "off" and "on" represents the output of an instrument, and a handler function for that Enum communicates the state to the hardware. I cannot talk to the hardware in a default handler, since the instrument is not initialized until its __init__() method has executed. Whether I first assign "on" or "off" to the trait, I would like the handler to execute. At the same time, I don't want to have "undefined" to be a proper value for the Enum and show up in editors and such.


The Enum() constructor takes several less-than-well-documented forms.
One of them is to provide the default value first, then provide a list
of the valid values.

class Test(HasTraits):
    x = Enum(Undefined, ['off', 'on'])

--
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: Undefined Enum

Martin Gustafsson
Thanks Robert, that's just what I wanted.

Best wishes
Martin Gustafsson


21 dec 2012 kl. 15.56 skrev Robert Kern:

> On Thu, Dec 20, 2012 at 10:28 PM, Martin Gustafsson
> <[hidden email]> wrote:
>> Hello,
>>
>> Is there a way for an Enum trait to default to Undefined?
>>
>> Use case: An Enum with the states "off" and "on" represents the output of an instrument, and a handler function for that Enum communicates the state to the hardware. I cannot talk to the hardware in a default handler, since the instrument is not initialized until its __init__() method has executed. Whether I first assign "on" or "off" to the trait, I would like the handler to execute. At the same time, I don't want to have "undefined" to be a proper value for the Enum and show up in editors and such.
>
>
> The Enum() constructor takes several less-than-well-documented forms.
> One of them is to provide the default value first, then provide a list
> of the valid values.
>
> class Test(HasTraits):
>    x = Enum(Undefined, ['off', 'on'])
>
> --
> Robert Kern
> Enthought
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev

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