ustr_trait Module

Defines the UStr type and HasUniqueStrings mixin class for efficiently creating lists of objects containing traits whose string values must be unique within the list.

class traits.ustr_trait.UStr(owner, list_name, str_name, default_value=<traits.trait_handlers.NoDefaultSpecified object>, **metadata)[source]

Bases: traits.trait_handlers.TraitType

Trait type that ensures that a value assigned to a trait is unique within the list it belongs to.

str_type = <traits.trait_value.TraitValue object>

The type value to assign to restore the original list item type when a list item is removed from the monitored list:

info_text = 'a unique string'

The informational text describing the trait:

validate(object, name, value)[source]

Ensures that a value being assigned to a trait is a unique string.

class traits.ustr_trait.HasUniqueStrings[source]

Bases: traits.has_traits.HasTraits

Mixin or base class for objects containing lists with items containing string valued traits that must be unique.

List traits within the class that contain items which have string traits which must be unique should indicate this by attaching metadata of the form:

unique_string = 'trait1, trait2, ..., traitn'

where each ‘traiti’ value is the name of a trait within each list item that must contain unique string data.

For example:

usa = List( State, unique_string = 'name, abbreviation' )

Adds any UStrMonitor objects to list traits with ‘unique_string’ metadata.