enable.trait_defs.rgba_color_trait module

Trait definition for an RGBA-based color

An RGBA-based color is a tuple of the form (red, green, blue, alpha), where each component is in the range from 0.0 to 1.0, which is the color representation used by Kiva for drawing.

Two traits are made available, a casting trait which takes many different color representations and converts them to a tuple, and a mapped version of the trait which holds the unconverted value and has a shadow trait holding the RGBA tuple value.

class enable.trait_defs.rgba_color_trait.MappedRGBAColor(value='white', **metadata)[source]

Bases: enable.trait_defs.rgba_color_trait.RGBAColor

A mapped trait that maps various color representations to RGBA tuples.

is_mapped = True

Return the mapped RGBA value.

post_setattr(object, name, value)[source]

Set the shadow trait after setting the current value.

validate(object, name, value)[source]
class enable.trait_defs.rgba_color_trait.RGBAColor(value='white', **metadata)[source]

Bases: traits.trait_type.TraitType

A Trait which casts Pyface Colors, strings and tuples to RGBA tuples.


Returns the default traits UI editor to use for a trait.

default_value_type = 0

Default values should be a tuple of floats.


Must return a string describing the type of value accepted by the trait handler.

The string should be a phrase describing the type defined by the TraitHandler subclass, rather than a complete sentence. For example, use the phrase, “a square sprocket” instead of the sentence, “The value must be a square sprocket.” The value returned by info() is combined with other information whenever an error occurs and therefore makes more sense to the user if the result is a phrase. The info() method is similar in purpose and use to the info attribute of a validator function.

Note that the result can include information specific to the particular trait handler instance. If the info() method is not overridden, the default method returns the value of the ‘info_text’ attribute.

validate(object, name, value)[source]

alias of enable.trait_defs.rgba_color_trait.RGBAColor


Convert various color representations to Kiva color tuple.

This can accept integers of the form 0xRRGGBB, strings which can be parsed by Pyface’s color parser, (r, g, b) and (r, g, b, a) tuples with either float 0.0 to 1.0 or int 0 to 255, Pyface Color objects, and toolkit color objects.