5.3.2
TraitPrefixMap
The TraitPrefixMap handler combines the TraitPrefixList
with mapped traits. Its constructor takes a parameter that is a dictionary whose
keys are strings. A string is a valid value if it is a unique prefix for a key
in the dictionary. The value assigned is the dictionary value corresponding to
the matched key.
The following example uses TraitPrefixMap to define a
Boolean trait that accepts any prefix of 'true', 'yes', 'false', or 'no', and
maps them to 1 or 0.
# traitprefixmap.py --- Example of using the TraitPrefixMap handler
from
enthought.traits.api import Trait, TraitPrefixMap
boolean_map
= Trait('true', TraitPrefixMap( {
'true': 1,
'yes': 1,
'false': 0,
'no': 0 } ) )
|