API Reference for Enthought Tool Suite 3.0.1

Checks that the value assigned to a trait attribute is a key of a specified dictionary, and also assigns the dictionary value corresponding to that key to a shadow attribute.

A trait attribute that uses a TraitMap handler is called mapped trait attribute. In practice, this means that the resulting object actually contains two attributes: one whose value is a key of the TraitMap dictionary, and the other whose value is the corresponding value of the TraitMap dictionary. The name of the shadow attribute is simply the base attribute name with an underscore ('_') appended. Mapped trait attributes can be used to allow a variety of user-friendly input values to be mapped to a set of internal, program-friendly values. For example:

>>>class Person(HasTraits):
...    married = Trait('yes', TraitMap({'yes': 1, 'no': 0 })
>>>
>>>bob = Person()
>>>print bob.married
yes
>>>print bob.married_
1

In this example, the default value of the married attribute of the Person class is 'yes'. Because this attribute is defined using TraitPrefixList, instances of Person have another attribute, married_, whose default value is 1, the dictionary value corresponding to the key 'yes'.

Inherits from

Attributes

Inherited from base classes

Method summary

Inherited from base classes

Methods

© Copyright 2002-2008 Enthought, Inc.