Inherits from
- TraitHandler: enthought.traits.trait_handlers.TraitHandler
Attributes
Inherited from base classes
Method summary
- __init__(self, *values)
- get_editor(self, trait)
- info(self)
- validate(self, object, name, value)
Inherited from base classes
- arg_error(self, method, arg_num, object, name, value)
- create_editor(self)
- dup_arg_error(self, method, arg_num, object, name)
- error(self, object, name, value)
- full_info(self, object, name, value)
- inner_traits(self)
- is_valid(self, object, name, value)
- keyword_error(self, method, object, name, value)
- missing_arg_error(self, method, arg_num, object, name)
- repr(self, value)
- return_error(self, method, object, value)
Methods
- __init__(self, *values)
Creates a TraitEnum handler.
Parameters
- values : list or tuple
- Enumeration of all legal values for a trait
Description
The list of legal values can be provided as a list of values. That is, TraitEnum([1, 2, 3]) and TraitEnum(1, 2, 3) are equivalent. For example:
class Flower(HasTraits): color = Trait('white', TraitEnum(['white', 'yellow', 'red'])) kind = Trait('annual', TraitEnum('annual', 'perennial'))This example defines a Flower class, which has a color trait attribute, which can have as its value, one of the three strings, 'white', 'yellow', or 'red', and a kind trait attribute, which can have as its value, either of the strings 'annual' or 'perennial'. This is equivalent to the following class definition:
class Flower(HasTraits): color = Trait(['white', 'yellow', 'red']) kind = Trait('annual', 'perennial')The Trait() function automatically maps traits of the form shown in this example to the form shown in the preceding example whenever it encounters them in a trait definition.
- get_editor(self, trait)
- info(self)
- validate(self, object, name, value)