API Reference for Enthought Tool Suite 3.0.1

Ensures that a value assigned to a trait attribute is a member of a list of specified string values, or is a unique prefix of one of those values.

TraitPrefixList is a variation on TraitEnum. The values that can be assigned to a trait attribute defined using a TraitPrefixList handler is the set of all strings supplied to the TraitPrefixList constructor, as well as any unique prefix of those strings. That is, if the set of strings supplied to the constructor is described by [s1, s2, ..., sn], then the string v is a valid value for the trait if v == si[:j] for one and only one pair of values (i, j). If v is a valid value, then the actual value assigned to the trait attribute is the corresponding si value that v matched. For example:

class Person(HasTraits):
    married = Trait('no', TraitPrefixList('yes', 'no')

The Person class has a married trait that accepts any of the strings 'y', 'ye', 'yes', 'n', or 'no' as valid values. However, the actual values assigned as the value of the trait attribute are limited to either 'yes' or 'no'. That is, if the value 'y' is assigned to the married attribute, the actual value assigned will be 'yes'.

Note that the algorithm used by TraitPrefixList in determining whether a string is a valid value is fairly efficient in terms of both time and space, and is not based on a brute force set of comparisons.

Inherits from

Attributes

Inherited from base classes

Method summary

Inherited from base classes

Methods

© Copyright 2002-2008 Enthought, Inc.