traits.trait_types Module

Core Trait definitions.

Traits

class traits.trait_types.Any(default_value=<traits.trait_type._NoDefaultSpecifiedType object>, *, factory=None, args=(), kw={}, **metadata)[source]

Bases: traits.trait_type.TraitType

A trait type whose value can be anything.

Parameters
  • default_value (object, optional) –

    The default value for the trait. If this is an instance of either list or dict then a copy of the default value is made for each instance. Otherwise, the default is shared between all instances.

    Deprecated since version 6.3.0: In a future version of Traits, a list or dict default value will no longer be copied. If you need a per-instance default, use a _trait_name_default method to supply that default.

  • factory (callable, optional) – A callable, that when called with args and kw, returns the default value for the trait.

  • args (tuple, optional) – Positional arguments (if any) for generating the default value.

  • kw (dictionary, optional) – Keyword arguments (if any) for generating the default value.

  • **metadata – Metadata for the trait.

default_value = None

The default value for the trait:

info_text = 'any value'

A description of the type of value this trait accepts:

default_value_type = 0

The default value type to use.

class traits.trait_types.BaseInt(default_value=<traits.trait_type._NoDefaultSpecifiedType object>, **metadata)[source]

Bases: traits.trait_type.TraitType

A trait type whose value must be an int.

Values which support the Python index protocol will validate and will be converted to the corresponding int value.

evaluate

alias of int

default_value_type = 0

The default value type to use.

default_value = 0

The default value for the trait:

info_text = 'an integer'

A description of the type of value this trait accepts:

validate(object, name, value)[source]

Validates that a specified value is valid for this trait.

create_editor()[source]

Returns the default traits UI editor for this type of trait.

class traits.trait_types.Int(default_value=<traits.trait_type._NoDefaultSpecifiedType object>, **metadata)[source]

Bases: traits.trait_types.BaseInt

A fast-validating trait type whose value must be an integer.

Values which support the Python index protocol will validate and will be converted to the corresponding int value.

fast_validate = (<ValidateTrait.int: 20>,)

The C-level fast validator to use:

class traits.trait_types.BaseFloat(default_value=<traits.trait_type._NoDefaultSpecifiedType object>, **metadata)[source]

Bases: traits.trait_type.TraitType

A trait type whose value must be a float.

Values which support automatic conversion to floats via the Python __float__ method will validate and will be converted to the corresponding float value.

evaluate

alias of float

default_value_type = 0

The default value type to use.

default_value = 0.0

The default value for the trait:

info_text = 'a float'

A description of the type of value this trait accepts:

validate(object, name, value)[source]

Validates that a specified value is valid for this trait.

Note: The ‘fast validator’ version performs this check in C.

create_editor()[source]

Returns the default traits UI editor for this type of trait.

class traits.trait_types.Float(default_value=<traits.trait_type._NoDefaultSpecifiedType object>, **metadata)[source]

Bases: traits.trait_types.BaseFloat

A fast-validating trait type whose value must be a float.

Values which support automatic conversion to floats via the Python __float__ method will validate and will be converted to the corresponding float value.

fast_validate = (<ValidateTrait.float: 21>,)

The C-level fast validator to use:

class traits.trait_types.BaseComplex(default_value=<traits.trait_type._NoDefaultSpecifiedType object>, **metadata)[source]

Bases: traits.trait_type.TraitType

A trait type whose value must be a complex number.

Integers and floating-point numbers will be converted to the corresponding complex value.

evaluate

alias of complex

default_value_type = 0

The default value type to use.

default_value = 0j

The default value for the trait:

info_text = 'a complex number'

A description of the type of value this trait accepts:

validate(object, name, value)[source]

Validates that a specified value is valid for this trait.

Note: The ‘fast validator’ version performs this check in C.

create_editor()[source]

Returns the default traits UI editor for this type of trait.

class traits.trait_types.Complex(default_value=<traits.trait_type._NoDefaultSpecifiedType object>, **metadata)[source]

Bases: traits.trait_types.BaseComplex

A fast-validating trait type whose value must be a complex number.

Integers and floating-point numbers will be converted to the corresponding complex value.

fast_validate = (<ValidateTrait.complex_number: 23>,)

The C-level fast validator to use:

class traits.trait_types.BaseStr(default_value=<traits.trait_type._NoDefaultSpecifiedType object>, **metadata)[source]

Bases: traits.trait_type.TraitType

A trait type whose value must be a string.

default_value_type = 0

The default value type to use.

default_value = ''

The default value for the trait:

info_text = 'a string'

A description of the type of value this trait accepts:

validate(object, name, value)[source]

Validates that a specified value is valid for this trait.

Note: The ‘fast validator’ version performs this check in C.

create_editor()[source]

Returns the default traits UI editor for this type of trait.

class traits.trait_types.Str(default_value=<traits.trait_type._NoDefaultSpecifiedType object>, **metadata)[source]

Bases: traits.trait_types.BaseStr

A fast-validating trait type whose value must be a string.

fast_validate = (<ValidateTrait.coerce: 11>, <class 'str'>)

The C-level fast validator to use:

class traits.trait_types.Title(default_value=<traits.trait_type._NoDefaultSpecifiedType object>, **metadata)[source]

Bases: traits.trait_types.Str

A Str trait which by default uses a TraitsUI TitleEditor.

create_editor()[source]

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

class traits.trait_types.BaseBytes(default_value=<traits.trait_type._NoDefaultSpecifiedType object>, **metadata)[source]

Bases: traits.trait_type.TraitType

A trait type whose value must be a bytestring.

default_value_type = 0

The default value type to use.

default_value = b''

The default value for the trait:

info_text = 'a bytes string'

A description of the type of value this trait accepts:

encoding = None

An encoding to use with TraitsUI editors

validate(object, name, value)[source]

Validates that a specified value is valid for this trait.

Note: The ‘fast validator’ version performs this check in C.

create_editor()[source]

Returns the default traits UI editor for this type of trait.

class traits.trait_types.Bytes(default_value=<traits.trait_type._NoDefaultSpecifiedType object>, **metadata)[source]

Bases: traits.trait_types.BaseBytes

A fast-validating trait type whose value must be a bytestring.

fast_validate = (<ValidateTrait.coerce: 11>, <class 'bytes'>)

The C-level fast validator to use:

class traits.trait_types.BaseBool(default_value=<traits.trait_type._NoDefaultSpecifiedType object>, **metadata)[source]

Bases: traits.trait_type.TraitType

A trait type whose value must be a bool.

evaluate

alias of bool

default_value_type = 0

The default value type to use.

default_value = False

The default value for the trait:

info_text = 'a boolean'

A description of the type of value this trait accepts:

validate(object, name, value)[source]

Validates that a specified value is valid for this trait.

Note: The ‘fast validator’ version performs this check in C.

create_editor()[source]

Returns the default traits UI editor for this type of trait.

class traits.trait_types.Bool(default_value=<traits.trait_type._NoDefaultSpecifiedType object>, **metadata)[source]

Bases: traits.trait_types.BaseBool

A fast-validating trait type whose value must be a bool.

fast_validate = (<ValidateTrait.coerce: 11>, <class 'bool'>, None, <class 'numpy.bool_'>)

The C-level fast validator to use:

class traits.trait_types.BaseCInt(default_value=<traits.trait_type._NoDefaultSpecifiedType object>, **metadata)[source]

Bases: traits.trait_types.BaseInt

A coercing trait type whose value is an integer.

evaluate

alias of int

validate(object, name, value)[source]

Validates that a specified value is valid for this trait.

Note: The ‘fast validator’ version performs this check in C.

class traits.trait_types.CInt(default_value=<traits.trait_type._NoDefaultSpecifiedType object>, **metadata)[source]

Bases: traits.trait_types.BaseCInt

A fast-validating, coercing trait type whose value is an int.

fast_validate = (<ValidateTrait.cast: 12>, <class 'int'>)

The C-level fast validator to use:

class traits.trait_types.BaseCFloat(default_value=<traits.trait_type._NoDefaultSpecifiedType object>, **metadata)[source]

Bases: traits.trait_types.BaseFloat

A coercing trait type whose value is a float.

evaluate

alias of float

validate(object, name, value)[source]

Validates that a specified value is valid for this trait.

Note: The ‘fast validator’ version performs this check in C.

class traits.trait_types.CFloat(default_value=<traits.trait_type._NoDefaultSpecifiedType object>, **metadata)[source]

Bases: traits.trait_types.BaseCFloat

A fast-validating, coercing trait type whose value is a float.

fast_validate = (<ValidateTrait.cast: 12>, <class 'float'>)

The C-level fast validator to use:

class traits.trait_types.BaseCComplex(default_value=<traits.trait_type._NoDefaultSpecifiedType object>, **metadata)[source]

Bases: traits.trait_types.BaseComplex

A coercing trait type whose value is a complex number.

evaluate

alias of complex

validate(object, name, value)[source]

Validates that a specified value is valid for this trait.

Note: The ‘fast validator’ version performs this check in C.

class traits.trait_types.CComplex(default_value=<traits.trait_type._NoDefaultSpecifiedType object>, **metadata)[source]

Bases: traits.trait_types.BaseCComplex

A fast-validating, coercing trait type whose value is a complex number.

fast_validate = (<ValidateTrait.cast: 12>, <class 'complex'>)

The C-level fast validator to use:

class traits.trait_types.BaseCStr(default_value=<traits.trait_type._NoDefaultSpecifiedType object>, **metadata)[source]

Bases: traits.trait_types.BaseStr

A coercing trait type whose value is a string.

validate(object, name, value)[source]

Validates that a specified value is valid for this trait.

Note: The ‘fast validator’ version performs this check in C.

class traits.trait_types.CStr(default_value=<traits.trait_type._NoDefaultSpecifiedType object>, **metadata)[source]

Bases: traits.trait_types.BaseCStr

A fast-validating, coercing trait type whose value is a string.

fast_validate = (<ValidateTrait.cast: 12>, <class 'str'>)

The C-level fast validator to use:

class traits.trait_types.BaseCBytes(default_value=<traits.trait_type._NoDefaultSpecifiedType object>, **metadata)[source]

Bases: traits.trait_types.BaseBytes

A coercing trait type whose value is a bytestring.

validate(object, name, value)[source]

Validates that a specified value is valid for this trait.

Note: The ‘fast validator’ version performs this check in C.

class traits.trait_types.CBytes(default_value=<traits.trait_type._NoDefaultSpecifiedType object>, **metadata)[source]

Bases: traits.trait_types.BaseCBytes

A fast-validating, coercing trait type whose value is a bytestring.

fast_validate = (<ValidateTrait.cast: 12>, <class 'bytes'>)

The C-level fast validator to use:

class traits.trait_types.BaseCBool(default_value=<traits.trait_type._NoDefaultSpecifiedType object>, **metadata)[source]

Bases: traits.trait_types.BaseBool

A coercing trait type whose value is a bool.

evaluate

alias of bool

validate(object, name, value)[source]

Validates that a specified value is valid for this trait.

Note: The ‘fast validator’ version performs this check in C.

class traits.trait_types.CBool(default_value=<traits.trait_type._NoDefaultSpecifiedType object>, **metadata)[source]

Bases: traits.trait_types.BaseCBool

A fast-validating, coercing trait type whose value is a bool.

fast_validate = (<ValidateTrait.cast: 12>, <class 'bool'>)

The C-level fast validator to use:

class traits.trait_types.String(value='', minlen=0, maxlen=9223372036854775807, regex='', **metadata)[source]

Bases: traits.trait_type.TraitType

A trait type whose value must be a string with optional constraints.

The value is a string whose length is in a specified range, and which optionally matches a specified regular expression.

Parameters
  • value (str) – The default value for the string.

  • minlen (integer) – The minimum length allowed for the string.

  • maxlen (integer) – The maximum length allowed for the string.

  • regex (str) – A Python regular expression that the string must match.

  • **metadata – The trait metadata for the trait.

minlen

The minimum length allowed for the string.

Type

integer

maxlen

The maximum length allowed for the string.

Type

integer

regex

A Python regular expression that the string must match.

Type

str

default_value_type = 0

The default value type to use.

validate(object, name, value)[source]

Validates that the value is a valid string.

validate_all(object, name, value)[source]

Validates that the value is a valid string in the specified length range which matches the specified regular expression.

validate_str(object, name, value)[source]

Validates that the value is a valid string.

validate_len(object, name, value)[source]

Validates that the value is a valid string in the specified length range.

validate_regex(object, name, value)[source]

Validates that the value is a valid string which matches the specified regular expression.

info()[source]

Returns a description of the trait.

create_editor()[source]

Returns the default traits UI editor for this type of trait.

class traits.trait_types.Regex(value='', regex='.*', **metadata)[source]

Bases: traits.trait_types.String

A trait type whose value must match a regular expression.

Parameters
  • value (str) – The default value of the trait.

  • regex (str) – The regular expression that the trait value must match.

  • **metadata – Trait metadata.

class traits.trait_types.Code(value='', minlen=0, maxlen=9223372036854775807, regex='', **metadata)[source]

Bases: traits.trait_types.String

A trait type whose value holds a string of source code.

Validation does not perform any sort of syntax checking. The default TraitsUI editor is a CodeEditor.

metadata = {'editor': <function code_editor>}

The standard metadata for the trait:

class traits.trait_types.HTML(value='', minlen=0, maxlen=9223372036854775807, regex='', **metadata)[source]

Bases: traits.trait_types.String

A trait type whose value holds an HTML string.

The validation of the value does not enforce HTML syntax. The default TraitsUI editor is an HTMLEditor.

metadata = {'editor': <function html_editor>}

The standard metadata for the trait:

class traits.trait_types.Password(value='', minlen=0, maxlen=9223372036854775807, regex='', **metadata)[source]

Bases: traits.trait_types.String

A trait type whose value holds a password string.

The default TraitsUI editor is an PasswordEditor, which obscures text entered by the user.

metadata = {'editor': <function password_editor>}

The standard metadata for the trait:

class traits.trait_types.BaseCallable(default_value=<traits.trait_type._NoDefaultSpecifiedType object>, **metadata)[source]

Bases: traits.trait_type.TraitType

A trait type whose value must be a Python callable.

metadata = {'copy': 'ref'}

The standard metadata for the trait:

default_value_type = 0

The default value type to use.

default_value = None

The default value for the trait:

info_text = 'a callable value'

A description of the type of value this trait accepts:

validate(object, name, value)[source]

Validates that the value is a Python callable.

class traits.trait_types.Callable(value=None, allow_none=True, **metadata)[source]

Bases: traits.trait_types.BaseCallable

A fast-validating trait type whose value must be a Python callable.

class traits.trait_types.BaseType(default_value=<traits.trait_type._NoDefaultSpecifiedType object>, **metadata)[source]

Bases: traits.trait_type.TraitType

A trait type whose value must be an instance of a Python type.

This is an abstract class and should not be directly instantiated.

default_value_type = 0

The default value type to use.

validate(object, name, value)[source]

Validates that the value is a Python callable.

class traits.trait_types.This(value=None, allow_none=True, **metadata)[source]

Bases: traits.trait_types.BaseType

A trait type whose value must be an instance of the defining class.

default_value_type = 0

The default value type to use.

info_text = 'an instance of the same type as the receiver'

A description of the type of value this trait accepts:

fast_validate = (<ValidateTrait.self_type: 2>,)

The C-level fast validator to use:

validate(object, name, value)[source]

Validates that the value is a Python callable.

info()[source]

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.

class traits.trait_types.self(value=None, allow_none=True, **metadata)[source]

Bases: traits.trait_types.This

A trait type whose default value is the object containing the trait.

The trait can be assigned to, but any new value must be an instance of the defining class.

default_value_type = 2

The default value type to use (i.e. ‘self’):

class traits.trait_types.Function(default_value=<traits.trait_type._NoDefaultSpecifiedType object>, **metadata)[source]

Bases: traits.trait_type.TraitType

A trait type whose value must be a function.

Deprecated since version 6.2.0: This trait type explicitly checks for an instance of types.FunctionType. For the majority of use cases, the more general Callable trait type should be used instead. If an instance specifically of types.FunctionType really is needed, one can use Instance(types.FunctionType).

default_value_type = 0

The default value type to use.

default_value = <undefined>

The default value for the trait type.

fast_validate = (<ValidateTrait.coerce: 11>, <class 'function'>)

The C-level fast validator to use:

info_text = 'a function'

A description of the type of value this trait accepts:

class traits.trait_types.Method(default_value=<traits.trait_type._NoDefaultSpecifiedType object>, **metadata)[source]

Bases: traits.trait_type.TraitType

A trait type whose value must be a method.

Deprecated since version 6.2.0: This trait type explicitly checks for an instance of types.MethodType. For the majority of use cases, the more general Callable trait type should be used instead. If an instance specifically of types.MethodType really is needed, one can use Instance(types.MethodType).

default_value_type = 0

The default value type to use.

default_value = <undefined>

The default value for the trait type.

fast_validate = (<ValidateTrait.coerce: 11>, <class 'method'>)

The C-level fast validator to use:

info_text = 'a method'

A description of the type of value this trait accepts:

class traits.trait_types.Module(default_value=<traits.trait_type._NoDefaultSpecifiedType object>, **metadata)[source]

Bases: traits.trait_type.TraitType

A trait type whose value must be a module.

default_value_type = 0

The default value type to use.

default_value = <undefined>

The default value for the trait type.

fast_validate = (<ValidateTrait.coerce: 11>, <class 'module'>)

The C-level fast validator to use:

info_text = 'a module'

A description of the type of value this trait accepts:

class traits.trait_types.Python(default_value=<traits.trait_type._NoDefaultSpecifiedType object>, **metadata)[source]

Bases: traits.trait_type.TraitType

A trait type that behaves as a standard Python attribute.

This trait type allows any value to be assigned, and raises an ValueError if an attempt is made to get the value before one has been assigned. It has no default value. This trait is most often used in conjunction with wildcard naming. See the Traits User Manual for details on wildcards.

metadata = {'type': 'python'}

The standard metadata for the trait:

default_value_type = 0

The default value type to use.

default_value = <undefined>

The default value for the trait:

traits.trait_types.ReadOnly[source]

alias of traits.trait_types.None

traits.trait_types.Disallow[source]

alias of traits.trait_types.None

class traits.trait_types.Constant(default_value=<traits.trait_type._NoDefaultSpecifiedType object>, **metadata)[source]

Bases: traits.trait_type.TraitType

A trait type whose value is a constant.

Traits of this type are very space efficient (and fast) because value is not stored in each instance using the trait, but only in the trait object itself.

Parameters
  • value (any) – The constant value for the trait.

  • **metadata – Trait metadata for the trait.

default_value_type = 0

The default value type to use.

ctrait_type = 7

Defines the CTrait type to use for this trait:

metadata = {'transient': True, 'type': 'constant'}

The standard metadata for the trait:

class traits.trait_types.Delegate(delegate, prefix='', modify=False, listenable=True, **metadata)[source]

Bases: traits.trait_type.TraitType

A trait type whose value is delegated to a trait on another object.

This is a base class that shouldn’t be used directly, rather use one of the subclasses DelegatesTo or PrototypesFrom, depending on desired behaviour.

An object containing a delegator trait attribute must contain a second attribute that references the object containing the delegate trait attribute. The name of this second attribute is passed as the delegate argument.

The following rules govern the application of the prefix parameter:

  • If prefix is empty or omitted, the delegation is to an attribute of the delegate object with the same name as the delegator attribute.

  • If prefix is a valid Python attribute name, then the delegation is to an attribute whose name is the value of prefix.

  • If prefix ends with an asterisk (‘*’) and is longer than one character, then the delegation is to an attribute whose name is the value of prefix, minus the trailing asterisk, prepended to the delegator attribute name.

  • If prefix is equal to a single asterisk, the delegation is to an attribute whose name is the value of the delegator object’s __prefix__ attribute prepended to delegator attribute name.

Parameters
  • delegate (str) – The name of the trait that holds the HasTraits instance that the value is delegated to.

  • prefix (str) – The name of the trait on the delegate that holds the delegated value. If empty, then the name of this trait will be used.

  • modify (bool) – Whether modifications of this trait are applied to the delegated object. This differentiates the behaviour of DelegatesTo and PrototypedFrom.

  • listenable (bool) – Whether changes to the delegated trait will fire listeners to this trait.

delegate

The name of the trait that holds the HasTraits instance that the value is delegated to.

Type

str

prefix

The name of the trait on the delegate that holds the delegated value. If empty, then the name of this trait will be used.

Type

str

prefix_type

An integer giving the type of prefix being used.

Type

int

modify

Whether modifications of this trait are applied to the delegated object. This differentiates the behaviour of DelegatesTo and PrototypedFrom.

Type

bool

ctrait_type = 3

Defines the CTrait type to use for this trait:

default_value_type = 0

The default value type to use.

metadata = {'transient': False, 'type': 'delegate'}

The standard metadata for the trait:

as_ctrait()[source]

Returns a CTrait corresponding to the trait defined by this class.

class traits.trait_types.DelegatesTo(delegate, prefix='', listenable=True, **metadata)[source]

Bases: traits.trait_types.Delegate

A trait type that matches the ‘delegate’ design pattern.

This defines a trait whose value and definition is “delegated” to another trait on a different object.

An object containing a delegator trait attribute must contain a second attribute that references the object containing the delegate trait attribute. The name of this second attribute is passed as the delegate argument to the DelegatesTo() function.

The following rules govern the application of the prefix parameter:

  • If prefix is empty or omitted, the delegation is to an attribute of the delegate object with the same name as the delegator attribute.

  • If prefix is a valid Python attribute name, then the delegation is to an attribute whose name is the value of prefix.

  • If prefix ends with an asterisk (‘*’) and is longer than one character, then the delegation is to an attribute whose name is the value of prefix, minus the trailing asterisk, prepended to the delegator attribute name.

  • If prefix is equal to a single asterisk, the delegation is to an attribute whose name is the value of the delegator object’s __prefix__ attribute prepended to delegator attribute name.

Note that any changes to the delegator attribute are actually applied to the corresponding attribute on the delegate object. The original object containing the delegator trait is not modified.

Parameters
  • delegate (str) – Name of the attribute on the current object which references the object that is the trait’s delegate.

  • prefix (str) – A prefix or substitution applied to the original attribute when looking up the delegated attribute.

  • listenable (bool) – Indicates whether a listener can be attached to this attribute such that changes to the delegated attribute will trigger it.

  • **metadata – Trait metadata for the trait.

class traits.trait_types.PrototypedFrom(prototype, prefix='', listenable=True, **metadata)[source]

Bases: traits.trait_types.Delegate

A trait type that matches the ‘prototype’ design pattern.

This defines a trait whose default value and definition is “prototyped” from another trait on a different object.

An object containing a prototyped trait attribute must contain a second attribute that references the object containing the prototype trait attribute. The name of this second attribute is passed as the prototype argument to the PrototypedFrom() function.

The following rules govern the application of the prefix parameter:

  • If prefix is empty or omitted, the prototype delegation is to an attribute of the prototype object with the same name as the prototyped attribute.

  • If prefix is a valid Python attribute name, then the prototype delegation is to an attribute whose name is the value of prefix.

  • If prefix ends with an asterisk (‘*’) and is longer than one character, then the prototype delegation is to an attribute whose name is the value of prefix, minus the trailing asterisk, prepended to the prototyped attribute name.

  • If prefix is equal to a single asterisk, the prototype delegation is to an attribute whose name is the value of the prototype object’s __prefix__ attribute prepended to the prototyped attribute name.

Note that any changes to the prototyped attribute are made to the original object, not the prototype object. The prototype object is only used to define to trait type and default value.

Parameters
  • prototype (str) – Name of the attribute on the current object which references the object that is the trait’s prototype.

  • prefix (str) – A prefix or substitution applied to the original attribute when looking up the prototyped attribute.

  • listenable (bool) – Indicates whether a listener can be attached to this attribute such that changes to the corresponding attribute on the prototype object will trigger it.

  • **metadata – Trait metadata for the trait.

class traits.trait_types.Expression(default_value=<traits.trait_type._NoDefaultSpecifiedType object>, **metadata)[source]

Bases: traits.trait_type.TraitType

A trait type whose value must be a valid Python expression.

The compiled form of a valid expression is stored as the mapped value of the trait.

default_value_type = 0

The default value type to use.

default_value = '0'

The default value for the trait:

info_text = 'a valid Python expression'

A description of the type of value this trait accepts:

is_mapped = True

Indicate that this is a mapped trait:

validate(object, name, value)[source]

Validates that a specified value is valid for this trait.

post_setattr(object, name, value)[source]

Performs additional post-assignment processing.

mapped_value(value)[source]

Returns the ‘mapped’ value for the specified value.

as_ctrait()[source]

Returns a CTrait corresponding to the trait defined by this class.

class traits.trait_types.PythonValue(default_value=<traits.trait_type._NoDefaultSpecifiedType object>, *, factory=None, args=(), kw={}, **metadata)[source]

Bases: traits.trait_types.Any

A trait type whose value can be of any type.

The default editor is a ShellEditor.

metadata = {'editor': <function shell_editor>}

The standard metadata for the trait:

class traits.trait_types.BaseFile(value='', filter=None, auto_set=False, entries=0, exists=False, **metadata)[source]

Bases: traits.trait_types.BaseStr

A trait type whose value must be a file path string.

This will accept both strings and os.pathlib Path objects, converting the latter to the corresponding string value.

Parameters
  • value (str) – The default value for the trait.

  • filter (str) – A wildcard string to filter filenames in the file dialog box used by the attribute trait editor.

  • auto_set (bool) – Indicates whether the file editor updates the trait value after every key stroke.

  • entries (int) – A hint to the TraitsUI editor about how many values to display in the editor.

  • exists (bool) – Indicates whether the trait value must be an existing file or not.

filter

A wildcard string to filter filenames in the file dialog box used by the attribute trait editor.

Type

str

auto_set

Indicates whether the file editor updates the trait value after every key stroke.

Type

bool

entries

A hint to the TraitsUI editor about how many values to display in the editor.

Type

int

exists

Indicates whether the trait value must be an existing file or not.

Type

bool

validate(object, name, value)[source]

Validates that a specified value is valid for this trait.

Note: The ‘fast validator’ version performs this check in C.

info()[source]

Return a description of the type of value this trait accepts.

create_editor()[source]

Returns the default traits UI editor for this type of trait.

class traits.trait_types.File(value='', filter=None, auto_set=False, entries=0, exists=False, **metadata)[source]

Bases: traits.trait_types.BaseFile

A fast-validating trait type whose value must be a file path string.

This will accept both strings and os.pathlib Path objects, converting the latter to the corresponding string value.

Parameters
  • value (str) – The default value for the trait.

  • filter (str) – A wildcard string to filter filenames in the file dialog box used by the attribute trait editor.

  • auto_set (bool) – Indicates whether the file editor updates the trait value after every key stroke.

  • entries (int) – A hint to the TraitsUI editor about how many values to display in the editor.

  • exists (bool) – Indicates whether the trait value must be an existing file or not.

filter

A wildcard string to filter filenames in the file dialog box used by the attribute trait editor.

Type

str

auto_set

Indicates whether the file editor updates the trait value after every key stroke.

Type

bool

entries

A hint to the TraitsUI editor about how many values to display in the editor.

Type

int

exists

Indicates whether the trait value must be an existing file or not.

Type

bool

class traits.trait_types.BaseDirectory(value='', auto_set=False, entries=0, exists=False, **metadata)[source]

Bases: traits.trait_types.BaseStr

A trait type whose value must be a directory path string.

This also accepts objects implementing the os.PathLike interface, converting them to the corresponding string.

Parameters
  • value (str) – The default value for the trait.

  • auto_set (bool) – Indicates whether the directory editor updates the trait value after every key stroke.

  • entries (int) – A hint to the TraitsUI editor about how many values to display in the editor.

  • exists (bool) – Indicates whether the trait value must be an existing directory or not.

auto_set

Indicates whether the directory editor updates the trait value after every key stroke.

Type

bool

entries

A hint to the TraitsUI editor about how many values to display in the editor.

Type

int

exists

Indicates whether the trait value must be an existing directory or not.

Type

bool

validate(object, name, value)[source]

Validates that a specified value is valid for this trait.

Note: The ‘fast validator’ version performs this check in C.

info()[source]

Return a description of the type of value this trait accepts.

create_editor()[source]

Returns the default traits UI editor for this type of trait.

class traits.trait_types.Directory(value='', auto_set=False, entries=0, exists=False, **metadata)[source]

Bases: traits.trait_types.BaseDirectory

A fast-validating trait type whose value is a directory path string.

This also accepts objects implementing the os.PathLike interface, converting them to the corresponding string.

Parameters
  • value (str) – The default value for the trait.

  • auto_set (bool) – Indicates whether the directory editor updates the trait value after every key stroke.

  • entries (int) – A hint to the TraitsUI editor about how many values to display in the editor.

  • exists (bool) – Indicates whether the trait value must be an existing directory or not.

auto_set

Indicates whether the directory editor updates the trait value after every key stroke.

Type

bool

entries

A hint to the TraitsUI editor about how many values to display in the editor.

Type

int

exists

Indicates whether the trait value must be an existing directory or not.

Type

bool

class traits.trait_types.BaseRange(low=None, high=None, value=None, exclude_low=False, exclude_high=False, **metadata)[source]

Bases: traits.trait_type.TraitType

A trait type whose numeric value lies inside a range.

The value held will be either an integer or a float, which type is determined by whether the low, high and value arguments are integers or floats.

The low, high, and value arguments must be of the same type (integer or float), except in the case where either low or high is a string (i.e. extended trait name).

If value is None or omitted, the default value is low, unless low is None or omitted, in which case the default value is high.

Parameters
  • low (integer, float or string (i.e. extended trait name)) – The low end of the range.

  • high (integer, float or string (i.e. extended trait name)) – The high end of the range.

  • value (integer, float or string (i.e. extended trait name)) – The default value of the trait.

  • exclude_low (bool) – Indicates whether the low end of the range is exclusive.

  • exclude_high (bool) – Indicates whether the high end of the range is exclusive.

default_value_type = 0

The default value type to use.

init_fast_validate(*args)[source]

Does nothing for the BaseRange class. Used in the Range class to set up the fast validator.

validate(object, name, value)[source]

Validate that the value is in the specified range.

float_validate(object, name, value)[source]

Validate that the value is a float value in the specified range.

int_validate(object, name, value)[source]

Validate that the value is an int value in the specified range.

full_info(object, name, value)[source]

Returns a description of the trait.

create_editor()[source]

Returns the default UI editor for the trait.

class traits.trait_types.Range(low=None, high=None, value=None, exclude_low=False, exclude_high=False, **metadata)[source]

Bases: traits.trait_types.BaseRange

A fast-validating trait type whose numeric value lies inside a range.

init_fast_validate(*args)[source]

Set up the C-level fast validator.

class traits.trait_types.BaseEnum(*args, values=None, **metadata)[source]

Bases: traits.trait_type.TraitType

A trait type whose value is an element of a finite collection.

This trait type can be either static, with the collection of valid values specified directly in the constructor, or dynamic, with the collection provided by the value of another trait attribute.

For both static and dynamic enumerations, a default value can be provided as a positional argument. If no default is provided, the default is the first item (in iteration order) of the underlying collection.

Notes

  1. If the enumeration is based on an unordered collection like a set, and no explicit default is given, the default used will effectively be arbitrary (the first element of the set in iteration order). It’s recommended that a default be given explicitly in this case.

  2. Instances of str, bytes and bytearray are not treated as collections for the purposes of this trait type, both for pragmatic reasons (it’s more likely that a user wants to use a string as an element in a collection than as a collection in its own right), and because the behavior of the in operator for those types does not express the usual membership semantics (for example, "bc" in "abc" is True).

Parameters
  • *args

    The enumeration of all valid values for the trait. For a static enumeration trait (where the values keyword argument is not given) the supported signatures for args are as follows:

    (collection,)

    A nonempty collection of valid values. The default is the first element of the collection, in iteration order.

    (default, collection)

    The default value, followed by a nonempty collection of valid values. The default should be an element of the collection, but this is not checked.

    (item1, item2, …, itemn)

    One or more items giving the valid values for the collection. The default is item1.

    For a dynamic enumeration trait, where the values keyword argument is given, the supported signatures for args are:

    ()

    No arguments given. In this case the default is the first item of the collection, in iteration order.

    (default,)

    The default value for the collection.

    For the static case, the ambiguity in the signatures is resolved as follows: if args has length 1 or 2, args[-1] can be iterated over, and args[-1] is not an instance of str, bytes or bytearray, then args[-1] is assumed to give the collection of values. Otherwise, all elements of args are assumed to be items in the collection. Thus the first two signatures are safe from ambiguity, and it’s recommended to use one of these two signatures in preference to the third form.

  • values (str, optional) – The name of a trait holding the valid values. If given, this is a dynamic enumeration, otherwise it’s a static numeration.

  • **metadata – Metadata for the trait.

values

For a static enumeration, this is a tuple holding the valid values. For a dynamic enumeration, this is None.

Type

tuple or None

name

For a dynamic enumeration, this is the name of a trait holding the collection of valid values. For a static enumeration, this is None.

Type

str or None

default_value_type = 0

The default value type to use.

init_fast_validate(*args)[source]

Does nothing for the BaseEnum class. Used in the Enum class to set up the fast validator.

validate(object, name, value)[source]

Validates that the value is one of the enumerated set of valid values.

full_info(object, name, value)[source]

Returns a description of the trait.

create_editor()[source]

Returns the default UI editor for the trait.

class traits.trait_types.Enum(*args, values=None, **metadata)[source]

Bases: traits.trait_types.BaseEnum

A fast-validating trait type whose value is an element of a finite collection.

This trait type can be either static, with the collection of valid values specified directly in the constructor, or dynamic, with the collection provided by the value of another trait attribute.

For both static and dynamic enumerations, a default value can be provided as a positional argument. If no default is provided, the default is the first item (in iteration order) of the underlying collection.

Notes

  1. If the enumeration is based on an unordered collection like a set, and no explicit default is given, the default used will effectively be arbitrary (the first element of the set in iteration order). It’s recommended that a default be given explicitly in this case.

  2. Instances of str, bytes and bytearray are not treated as collections for the purposes of this trait type, both for pragmatic reasons (it’s more likely that a user wants to use a string as an element in a collection than as a collection in its own right), and because the behavior of the in operator for those types does not express the usual membership semantics (for example, "bc" in "abc" is True).

Parameters
  • *args

    The enumeration of all valid values for the trait. For a static enumeration trait (where the values keyword argument is not given) the supported signatures for args are as follows:

    (collection,)

    A nonempty collection of valid values. The default is the first element of the collection, in iteration order.

    (default, collection)

    The default value, followed by a nonempty collection of valid values. The default should be an element of the collection, but this is not checked.

    (item1, item2, …, itemn)

    One or more items giving the valid values for the collection. The default is item1.

    For a dynamic enumeration trait, where the values keyword argument is given, the supported signatures for args are:

    ()

    No arguments given. In this case the default is the first item of the collection, in iteration order.

    (default,)

    The default value for the collection.

    For the static case, the ambiguity in the signatures is resolved as follows: if args has length 1 or 2, args[-1] can be iterated over, and args[-1] is not an instance of str, bytes or bytearray, then args[-1] is assumed to give the collection of values. Otherwise, all elements of args are assumed to be items in the collection. Thus the first two signatures are safe from ambiguity, and it’s recommended to use one of these two signatures in preference to the third form.

  • values (str, optional) – The name of a trait holding the valid values. If given, this is a dynamic enumeration, otherwise it’s a static numeration.

  • **metadata – Metadata for the trait.

values

For a static enumeration, this is a tuple holding the valid values. For a dynamic enumeration, this is None.

Type

tuple or None

name

For a dynamic enumeration, this is the name of a trait holding the collection of valid values. For a static enumeration, this is None.

Type

str or None

init_fast_validate(*args)[source]

Set up C-level fast validation.

class traits.trait_types.BaseTuple(*types, **metadata)[source]

Bases: traits.trait_type.TraitType

A trait type holding a tuple with typed elements.

The default value is determined as follows:

  1. If no arguments are specified, the default value is ().

  2. If a tuple is specified as the first argument, it is the default value.

  3. If a tuple is not specified as the first argument, the default value is a tuple whose length is the length of the argument list, and whose values are the default values for the corresponding trait types.

Example for case #2:

mytuple = Tuple(('Fred', 'Betty', 5))

The trait’s value must be a 3-element tuple whose first and second elements are strings, and whose third element is an integer. The default value is ('Fred', 'Betty', 5).

Example for case #3:

mytuple = Tuple('Fred', 'Betty', 5)

The trait’s value must be a 3-element tuple whose first and second elements are strings, and whose third element is an integer. The default value is ('','',0).

Parameters
  • *types – Definition of the default and allowed tuples. If the first item of types is a tuple, it is used as the default value. The remaining argument list is used to form a tuple that constrains the values assigned to the returned trait. The trait’s value must be a tuple of the same length as the remaining argument list, whose elements must match the types specified by the corresponding items of the remaining argument list.

  • **metadata – Trait metadata for the trait.

types

The tuple of traits specifying the type of each element in order.

Type

tuple

no_type_check

Flag to indicate whether validation should check the type of each element.

Type

bool

default_value_type = 0

The default value type to use.

init_fast_validate(*args)[source]

Saves the validation parameters.

validate(object, name, value)[source]

Validates that the value is a valid tuple.

full_info(object, name, value)[source]

Returns a description of the trait.

create_editor()[source]

Returns the default UI editor for the trait.

class traits.trait_types.Tuple(*types, **metadata)[source]

Bases: traits.trait_types.BaseTuple

A fast-validating trait type holding a tuple with typed elements.

init_fast_validate(*args)[source]

Set up the C-level fast validator.

validate(object, name, value)[source]

Validates that the value is a valid tuple.

class traits.trait_types.ValidatedTuple(*types, **metadata)[source]

Bases: traits.trait_types.BaseTuple

A trait type holding a tuple with customized validation.

Parameters
  • *types – Definition of the default and allowed tuples. (see BaseTuple for more details)

  • fvalidate (callable, optional) – A callable to provide the additional custom validation for the tuple. The callable will be passed the tuple value and should return True or False.

  • fvalidate_info (string, optional) – A string describing the custom validation to use for the error messages.

  • **metadata – Trait metadata for the trait.

Example

The definition:

value_range = ValidatedTuple(
    Int(0), Int(1), fvalidate=lambda x: x[0] < x[1])

will accept only tuples (a, b) containing two integers that satisfy a < b.

validate(object, name, value)[source]

Validates that the value is a valid tuple.

full_info(object, name, value)[source]

Returns a description of the trait.

class traits.trait_types.List(trait=None, value=None, minlen=0, maxlen=9223372036854775807, items=True, **metadata)[source]

Bases: traits.trait_type.TraitType

A trait type for a list of values of the specified type.

The length of the list assigned to the trait must be such that:

minlen <= len(list) <= maxlen

Note that this trait type creates copies of values on assignment, rather than assigning the exact instance. For example, consider:

>>> class A(HasTraits):
...     x = List()
...
>>> b = [1, 2, 3]
>>> a = A(x=b)
>>> a.x
[1, 2, 3]
>>> b.append(4)
>>> a.x
[1, 2, 3]
Parameters
  • trait (a trait or value that can be converted using trait_from()) – The type of item that the list contains. If not specified, the list can contain items of any type.

  • value (list) – Default value for the list.

  • minlen (integer) – The minimum length of a list that can be assigned to the trait.

  • maxlen (integer) – The maximum length of a list that can be assigned to the trait.

  • items (bool) – Whether there is a corresponding <name>_items trait.

  • **metadata – Trait metadata for the trait.

item_trait

The type of item that the list contains.

Type

trait

minlen

The minimum length of a list that can be assigned to the trait.

Type

integer

maxlen

The maximum length of a list that can be assigned to the trait.

Type

integer

has_items

Whether there is a corresponding <name>_items trait.

Type

bool

validate(object, name, value)[source]

Validates that the values is a valid list.

Note

object can be None when validating a default value (see e.g. clone())

full_info(object, name, value)[source]

Returns a description of the trait.

create_editor()[source]

Returns the default UI editor for the trait.

inner_traits()[source]

Returns the inner trait (or traits) for this trait.

class traits.trait_types.CList(trait=None, value=None, minlen=0, maxlen=9223372036854775807, items=True, **metadata)[source]

Bases: traits.trait_types.List

A coercing trait type for a list of values of the specified type.

validate(object, name, value)[source]

Validates that the values is a valid list.

full_info(object, name, value)[source]

Returns a description of the trait.

class traits.trait_types.PrefixList(values, *, default_value=None, **metadata)[source]

Bases: traits.trait_type.TraitType

Ensures that a value assigned to the attribute is a member of a list of

specified string values, or is a unique prefix of one of those values.

The values that can be assigned to a trait attribute of type PrefixList type is the set of all strings supplied to the PrefixList 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.

The legal values can be provided as an iterable of values.

Example

::
class Person(HasTraits):

married = PrefixList([‘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’.

Parameters

values – A list or other iterable of legal string values for this trait.

values

The list of legal values for this trait.

Type

list of str

default_value_type = 0

The default value type to use.

info()[source]

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.

class traits.trait_types.Set(trait=None, value=None, items=True, **metadata)[source]

Bases: traits.trait_type.TraitType

A trait type for a set of values of the specified type.

Note that this trait type creates copies of values on assignment, rather than assigning the exact instance. For example, consider:

>>> class A(HasTraits):
...     x = Set()
...
>>> b = set()
>>> a = A(x=b)
>>> a.x
TraitSetObject()
>>> b.add(1)
>>> a.x
TraitSetObject()
Parameters
  • trait (a trait or value that can be converted using trait_from()) – The type of item that the set contains. If not specified, the set can contain items of any type.

  • value (set) – Default value for the set.

  • items (bool) – Whether there is a corresponding <name>_items trait.

  • **metadata – Trait metadata for the trait.

item_trait

The type of item that the set contains. If not specified, the set can contain items of any type.

Type

a trait or value that can be converted to a trait

has_items

Whether there is a corresponding <name>_items trait.

Type

bool

validate(object, name, value)[source]

Validates that the values is a valid set.

Note

object can be None when validating a default value (see e.g. clone())

full_info(object, name, value)[source]

Returns a description of the trait.

create_editor()[source]

Returns the default UI editor for the trait.

inner_traits()[source]

Returns the inner trait (or traits) for this trait.

class traits.trait_types.CSet(trait=None, value=None, items=True, **metadata)[source]

Bases: traits.trait_types.Set

A coercing trait type for a set of values of the specified type.

validate(object, name, value)[source]

Validates that the values is a valid list.

full_info(object, name, value)[source]

Returns a description of the trait.

class traits.trait_types.Dict(key_trait=None, value_trait=None, value=None, items=True, **metadata)[source]

Bases: traits.trait_type.TraitType

A trait type for a dictionary with specified key and value types.

Note that this trait type creates copies of values on assignment, rather than assigning the exact instance. For example, consider:

>>> class A(HasTraits):
...     x = Dict()
...
>>> b = {}
>>> a = A(x=b)
>>> a.x
{}
>>> b['one'] = 1
>>> a.x
{}
Parameters
  • key_trait (a trait or value that can be converted using trait_from()) – The trait type for keys in the dictionary; if not specified, any values can be used as keys.

  • value_trait (a trait or value that can be converted using trait_from()) – The trait type for values in the dictionary; if not specified, any values can be used as dictionary values.

  • value (dict) – The default value for the returned trait.

  • items (bool) – Indicates whether the value contains items.

key_trait

The trait type for keys in the dictionary; if not specified, any values can be used as keys.

Type

a trait

value_trait

The trait type for values in the dictionary; if not specified, any values can be used as dictionary values.

Type

a trait

value_trait_handler

The TraitHandler for the value_trait.

Type

TraitHandler

has_items

Indicates whether the value contains items.

Type

bool

validate(object, name, value)[source]

Validates that the value is a valid dictionary.

Note

object can be None when validating a default value (see e.g. clone())

full_info(object, name, value)[source]

Returns a description of the trait.

create_editor()[source]

Returns the default UI editor for the trait.

inner_traits()[source]

Returns the inner trait (or traits) for this trait.

class traits.trait_types.Map(map, **metadata)[source]

Bases: traits.trait_type.TraitType

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 of type Map is called a mapped trait attribute. In practice, this means that the resulting object actually contains two attributes: one whose value is a key of the Map dictionary, and the other whose value is the corresponding value of the Map 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.

Example

The following example defines a Person class:

>>> class Person(HasTraits):
...     married = Map({'yes': 1, 'no': 0 }, default_value="yes")
...
>>> 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 Map, instances of Person have another attribute, married_, whose default value is 1, the dictionary value corresponding to the key ‘yes’.

Parameters
  • map (dict) – A dictionary whose keys are valid values for the trait attribute, and whose corresponding values are the values for the shadow trait attribute.

  • default_value (object, optional) – The default value for the trait. If given, this should be a key from the mapping. If not given, the first key from the mapping (in normal dictionary iteration order) will be used as the default.

map

A dictionary whose keys are valid values for the trait attribute, and whose corresponding values are the values for the shadow trait attribute.

Type

dict

default_value_type = 0

The default value type to use.

mapped_value(value)[source]

Get the mapped value for a value.

info()[source]

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.

get_editor(trait)[source]

Returns a trait editor that allows the user to modify the trait trait. This method only needs to be specified if traits defined using this trait handler require a non-default trait editor in trait user interfaces. The default implementation of this method returns a trait editor that allows the user to type an arbitrary string as the value.

For more information on trait user interfaces, refer to the Traits UI User Guide.

Parameters

trait (Trait) – The trait to be edited.

class traits.trait_types.PrefixMap(map, *, default_value=None, **metadata)[source]

Bases: traits.trait_type.TraitType

A cross between the PrefixList and Map classes.

Like Map, PrefixMap is created using a dictionary, but in this case, the keys of the dictionary must be strings. Like PrefixList, a string v is a valid value for the trait attribute if it is a prefix of one and only one key k in the dictionary. The actual values assigned to the trait attribute is k, and its corresponding mapped attribute is map*[*k].

Example

mapping = {'true': 1, 'yes': 1, 'false': 0, 'no': 0 }
boolean_map = PrefixMap(mapping)

This example defines a Boolean trait that accepts any prefix of ‘true’, ‘yes’, ‘false’, or ‘no’, and maps them to 1 or 0.

Parameters
  • map (dict) – A dictionary whose keys are strings that are valid values for the trait attribute, and whose corresponding values are the values for the shadow trait attribute.

  • default_value (object, optional) – The default value for the trait. If given, this should be either a key from the mapping or a unique prefix of a key from the mapping. If not given, the first key from the mapping (in normal dictionary iteration order) will be used as the default.

map

A dictionary whose keys are strings that are valid values for the trait attribute, and whose corresponding values are the values for the shadow trait attribute.

Type

dict

default_value_type = 0

The default value type to use.

mapped_value(value)[source]

Get the mapped value for a value.

info()[source]

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.

get_editor(trait)[source]

Returns a trait editor that allows the user to modify the trait trait. This method only needs to be specified if traits defined using this trait handler require a non-default trait editor in trait user interfaces. The default implementation of this method returns a trait editor that allows the user to type an arbitrary string as the value.

For more information on trait user interfaces, refer to the Traits UI User Guide.

Parameters

trait (Trait) – The trait to be edited.

class traits.trait_types.BaseClass(default_value=<traits.trait_type._NoDefaultSpecifiedType object>, **metadata)[source]

Bases: traits.trait_type.TraitType

A base trait type for trait types which have an associated class.

Traits sometimes need to be able to access classes which have not yet been defined, or which are from a module that we want to defer importing from. To support this, classes can be determined dynamically by specifying a string name for the class (e.g. 'package1.package2.module.class'). This base class provides the machinery for this sort of deferred access to classes.

Any subclass must define instances with ‘klass’ and ‘module’ attributes that contain the string name of the class (or actual class object) and the module name that contained the original trait definition (used for resolving local class names (e.g. ‘LocalClass’)).

This is an abstract class that only provides helper methods used to resolve the class name into an actual class object.

klass

The class object or a string that refers to it.

Type

type or str

module

The name of the module that contains the class.

Type

str

default_value_type = 0

The default value type to use.

resolve_class(object, name, value)[source]

Resolve the class object as part of validation.

This is called when the klass attribute is a string and sets the klass attribute to the actual klass object as a side-effect. If the class cannot be resolved, it will call validate_failed().

validate_class(klass)[source]

Validate a class object.

find_class(klass)[source]

Given a string describing a class, get the class object.

validate_failed(object, name, value)[source]

Raise a TraitError if the class could not be resolved.

class traits.trait_types.BaseInstance(klass=None, factory=None, args=None, kw=None, allow_none=True, adapt=None, module=None, **metadata)[source]

Bases: traits.trait_types.BaseClass

A trait type whose value is an instance of a class or its subclasses.

The default value is None if klass is an instance or if it is a class and args and kw are not specified. Otherwise, the default value is the instance obtained by calling klass(*args, **kw). Note that the constructor call is performed each time a default value is assigned, so each default value assigned is a unique instance.

Parameters
  • klass (class, str or instance) – The object that forms the basis for the trait; if it is an instance, then trait values must be instances of the same class or a subclass. This object is not the default value, even if it is an instance. If the provided value is a string, it is expected to be a reference to a class that will be resolved at run-time.

  • factory (callable) – A callable, typically a class, that when called with args and kw, returns the default value for the trait. If not specified, or None, klass is used as the factory.

  • args (tuple) – Positional arguments for generating the default value.

  • kw (dictionary) – Keyword arguments for generating the default value.

  • allow_none (bool) – Indicates whether None is allowed as a value.

  • adapt (str) –

    A string specifying how adaptation should be applied. The possible values are:

    • ’no’: Adaptation is not allowed.

    • ’yes’: Adaptation is allowed. If adaptation fails, an exception should be raised.

    • ’default’: Adaptation is allowed. If adaptation fails, the default value for the trait should be used.

factory

A callable, typically a class, that when called with args and kw, returns the default value for the trait. If not specified, or None, klass is used as the factory.

Type

callable

args

Positional arguments for generating the default value.

Type

tuple

kw

Keyword arguments for generating the default value.

Type

dictionary

allow_none[source]

Indicates whether None is allowed as a value.

Type

bool

adapt

A string specifying how adaptation should be applied. The possible values are:

  • ‘no’: Adaptation is not allowed.

  • ‘yes’: Adaptation is allowed. If adaptation fails, an exception should be raised.

  • ‘default’: Adaptation is allowed. If adaptation fails, the default value for the trait should be used.

Type

str

adapt_default = 'no'

Default adaptation behavior.

validate(object, name, value)[source]

Validates that the value is a valid object instance.

info()[source]

Returns a description of the trait.

clone(default_value=<traits.trait_type._NoDefaultSpecifiedType object>, **metadata)[source]

Copy, optionally modifying default value and metadata.

create_editor()[source]

Returns the default traits UI editor for this type of trait.

init_fast_validate()[source]

Does nothing for the BaseInstance’ class. Used by the ‘Instance’, ‘Supports’ and ‘AdaptsTo’ classes to set up the C-level fast validator.

resolve_class(object, name, value)[source]

Resolve the class object as part of validation.

This is called when the klass attribute is a string and sets the klass attribute to the actual klass object as a side-effect. If the class cannot be resolved, it will call validate_failed().

class traits.trait_types.Instance(klass=None, factory=None, args=None, kw=None, allow_none=True, adapt=None, module=None, **metadata)[source]

Bases: traits.trait_types.BaseInstance

A fast-validated trait type whose value is an instance of a class.

init_fast_validate()[source]

Sets up the C-level fast validator.

class traits.trait_types.Supports(klass=None, factory=None, args=None, kw=None, allow_none=True, adapt=None, module=None, **metadata)[source]

Bases: traits.trait_types.Instance

A trait type whose value is adapted to a specified protocol.

In other words, the value of the trait directly provide, or can be adapted to, the given protocol (Interface or type).

The value of the trait after assignment is the possibly adapted value (i.e., it is the original assigned value if that provides the protocol, or is an adapter otherwise).

The original, unadapted value is stored in a “shadow” attribute with the same name followed by an underscore (e.g., foo and foo_).

post_setattr(object, name, value)[source]

Performs additional post-assignment processing.

as_ctrait()[source]

Returns a CTrait corresponding to the trait defined by this class.

class traits.trait_types.AdaptsTo(klass=None, factory=None, args=None, kw=None, allow_none=True, adapt=None, module=None, **metadata)[source]

Bases: traits.trait_types.Supports

A trait type whose value must support a specified protocol.

In other words, the value of the trait directly provide, or can be adapted to, the given protocol (Interface or type).

The value of the trait after assignment is the original, unadapted value.

A possibly adapted value is stored in a “shadow” attribute with the same name followed by an underscore (e.g., foo and foo_).

class traits.trait_types.Type(value=None, klass=None, allow_none=True, **metadata)[source]

Bases: traits.trait_types.BaseClass

A trait type whose value must be a subclass of a specified class.

Parameters
  • value (class or None) – The default value of the trait.

  • klass (class, str or None) – The class that trait values must be subclasses of. If None, then the default value is used instead. If both are None, then the object type is used. If it is a string, the first time that the validate method is called, the class will be imported and the value replaced with the class object.

  • allow_none (bool) – Indicates whether None is allowed as an assignable value. Even if False, the default value may be None.

  • **metadata – Trait metadata for the trait.

klass

The class that trait values must be subclasses of. If this is a string, the first time that the validate method is called, the class will be imported and the value replaced with the class object.

Type

class or str

module

The name of the module where local class names (ie. class names with no module components) are presumed to be importable from. This is the caller’s caller’s module, as determined by the get_module_method.

Type

str

validate(object, name, value)[source]

Validates that the value is a valid object instance.

resolve(object, name, value)[source]

Resolves a class originally specified as a string into an actual class, then resets the trait so that future calls will be handled by the normal validate method.

info()[source]

Returns a description of the trait.

get_default_value()[source]

Returns a tuple of the form: ( default_value_type, default_value ) which describes the default value for this trait.

resolve_default_value()[source]

Resolves a class name into a class so that it can be used to return the class as the default value of the trait.

traits.trait_types.Subclass

An alias for the Type trait

alias of traits.trait_types.Type

class traits.trait_types.Event(trait=None, **metadata)[source]

Bases: traits.trait_type.TraitType

A trait type that holds no value but can be set and listened to.

Event traits are write-only traits. They do not hold any value, but they can be assigned to, and listeners to the trait will be notified of the assignment. Since no value is held, trait change functions that ask for the old value of the trait will be given the Undefined special value.

Event traits can be given an optional trait type that is used to validate values assigned to the trait. If the assigned value does not validate, then a TraitError will occur.

Parameters

trait (a trait) – The type of value that can be assigned to the event.

default_value_type = 0

The default value type to use.

full_info(object, name, value)[source]

Returns a description of the trait.

class traits.trait_types.Button(label='', image=None, values_trait=None, style='button', orientation='vertical', width_padding=7, height_padding=5, view=None, **metadata)[source]

Bases: traits.trait_types.Event

An Event trait type whose UI editor is a button.

Parameters
  • label (str) – The label for the button.

  • image (pyface.ImageResource) – An image to display on the button.

  • style ('button', 'radio', 'toolbar' or 'checkbox') – The style of button to display.

  • values_trait (str) – For a “button” or “toolbar” style, the name of an enum trait whose values will populate a drop-down menu on the button. The selected value will replace the label on the button.

  • orientation ('horizontal' or 'vertical') – The orientation of the label relative to the image.

  • width_padding (integer between 0 and 31) – Extra padding (in pixels) added to the left and right sides of the button.

  • height_padding (integer between 0 and 31) – Extra padding (in pixels) added to the top and bottom of the button.

  • view (traitsui View, optional) – An optional View to display when the button is clicked.

  • **metadata – Trait metadata for the trait.

label

The label for the button.

Type

str

image

An image to display on the button.

Type

pyface.ImageResource

style

The style of button to display.

Type

‘button’, ‘radio’, ‘toolbar’ or ‘checkbox’

values_trait

For a “button” or “toolbar” style, the name of an enum trait whose values will populate a drop-down menu on the button. The selected value will replace the label on the button.

Type

str

orientation

The orientation of the label relative to the image.

Type

‘horizontal’ or ‘vertical’

width_padding

Extra padding (in pixels) added to the left and right sides of the button.

Type

integer between 0 and 31

height_padding

Extra padding (in pixels) added to the top and bottom of the button.

Type

integer between 0 and 31

view

An optional View to display when the button is clicked.

Type

traitsui View, optional

create_editor()[source]

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

class traits.trait_types.ToolbarButton(label='', image=None, style='toolbar', orientation='vertical', width_padding=2, height_padding=2, **metadata)[source]

Bases: traits.trait_types.Button

A Button trait type whose UI editor is a toolbar button.

This is just a Button trait with different defaults to style it like a toolbar button.

Parameters
  • label (str) – The label for the button.

  • image (pyface.ImageResource) – An image to display on the button.

  • style ('button', 'radio', 'toolbar' or 'checkbox') – The style of button to display.

  • orientation ('horizontal' or 'vertical') – The orientation of the label relative to the image.

  • width_padding (integer between 0 and 31) – Extra padding (in pixels) added to the left and right sides of the button.

  • height_padding (integer between 0 and 31) – Extra padding (in pixels) added to the top and bottom of the button.

  • **metadata – Trait metadata for the trait.

label

The label for the button.

Type

str

image

An image to display on the button.

Type

pyface.ImageResource

style

The style of button to display.

Type

‘button’, ‘radio’, ‘toolbar’ or ‘checkbox’

values_trait

For a “button” or “toolbar” style, the name of an enum trait whose values will populate a drop-down menu on the button. The selected value will replace the label on the button.

Type

str

orientation

The orientation of the label relative to the image.

Type

‘horizontal’ or ‘vertical’

width_padding

Extra padding (in pixels) added to the left and right sides of the button.

Type

integer between 0 and 31

height_padding

Extra padding (in pixels) added to the top and bottom of the button.

Type

integer between 0 and 31

view

An optional View to display when the button is clicked.

Type

traitsui View, optional

class traits.trait_types.Union(*traits, **metadata)[source]

Bases: traits.trait_type.TraitType

Defines a trait whose value can be any of of a specified list of trait types or list of trait type instances or None

If the default value is not defined on Union, the default value from the first trait will be used.

default_value_type = 0

The default value type to use.

validate(obj, name, value)[source]

Return the value by the first trait in the list that can validate the assigned value, raise an error if none of them can.

info()[source]

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.

inner_traits()[source]

Returns a tuple containing the inner traits for this trait. Most trait handlers do not have any inner traits, and so will return an empty tuple. The exceptions are List and Dict trait types, which have inner traits used to validate the values assigned to the trait. For example, in List( Int ), the inner traits for List are ( Int, ).

get_editor(trait)[source]

Returns a trait editor that allows the user to modify the trait trait. This method only needs to be specified if traits defined using this trait handler require a non-default trait editor in trait user interfaces. The default implementation of this method returns a trait editor that allows the user to type an arbitrary string as the value.

For more information on trait user interfaces, refer to the Traits UI User Guide.

Parameters

trait (Trait) – The trait to be edited.

class traits.trait_types.Either(*traits, **metadata)[source]

Bases: traits.trait_type.TraitType

A trait type whose value can be any of of a specified list of traits.

Note

This class has some unusual corner-case behaviours and is not recommended for use in new code. It may eventually be deprecated and removed. For new code, consider using the Union trait type instead.

Parameters
  • *traits – Arguments that define allowable trait values.

  • **metadata – Trait metadata for the trait.

trait_maker

A TraitHandler generated by _TraitMaker from the arguments.

Type

TraitHandler

as_ctrait()[source]

Returns a CTrait corresponding to the trait defined by this class.

class traits.trait_types.Symbol(default_value=<traits.trait_type._NoDefaultSpecifiedType object>, **metadata)[source]

Bases: traits.trait_type.TraitType

A property trait type that refers to a Python object by name.

The value set to the trait must be a value of the form '[package.package...package.]module[:symbol[([arg1,...,argn])]]' which is imported and evaluated to get underlying value.

The value returned by the trait is the actual object that this string refers to. The value is cached, so any calls are only evaluated once.

Deprecated since version 6.3.0: This trait type is deprecated, and will be removed in a future version of Traits.

info_text = "an object or a string of the form '[package.package...package.]module[:symbol[([arg1,...,argn])]]' specifying where to locate the object"

A description of the type of value this trait accepts:

class traits.trait_types.UUID(can_init=False, **metadata)[source]

Bases: traits.trait_type.TraitType

A read-only trait type whose value is a globally unique UUID (type 4).

Parameters

can_init (bool) – Whether the value can be set during object instantiation. Otherwise the UUID is generated automatically.

Example

Passing can_init=True allows the UUID value to be set during object instantiation, e.g.:

class A(HasTraits):
    id = UUID

class B(HasTraits):
    id = UUID(can_init=True)

# TraitError!
A(id=uuid.uuid4())

# Okay!
B(id=uuid.uuid4())

Note however that in both cases, the UUID trait is set automatically to a uuid.UUID instance (assuming none is provided during initialization in the latter case).

info_text = 'a read-only UUID'

A description of the type of value this trait accepts:

validate(object, name, value)[source]

Raises an error, since no values can be assigned to the trait.

get_default_value()[source]

Return a Traits default value tuple for the trait.

This uses the _create_uuid method to generate the default value.

class traits.trait_types.WeakRef(klass='traits.has_traits.HasTraits', allow_none=False, adapt='yes', **metadata)[source]

Bases: traits.trait_types.Instance

A trait type holding a weak reference to an instance of a class.

Only a weak reference is maintained to any object assigned to a WeakRef trait. If no other references exist to the assigned value, the value may be garbage collected, in which case the value of the trait becomes None. In all other cases, the value returned by the trait is the original object.

Parameters
  • klass (class, str or instance) – The object that forms the basis for the trait. If klass is omitted, then values must be an instance of HasTraits. If a string, the value will be resolved to a class object at runtime.

  • allow_none (boolean) – Indicates whether None can be _assigned_. The trait attribute may give a None value if the object referred to has been garbage collected even if allow_none is False.

  • adapt (str) – How to use the adaptation infrastructure when setting the value.

resolve_class(object, name, value)[source]

Resolve the class object as part of validation.

This is called when the klass attribute is a string and sets the klass attribute to the actual klass object as a side-effect. If the class cannot be resolved, it will call validate_failed().

class traits.trait_types.Date(default_value=None, *, allow_datetime=None, allow_none=None, **metadata)[source]

Bases: traits.trait_type.TraitType

A trait type whose value must be a date.

The value must be an instance of datetime.date. Note that datetime.datetime is a subclass of datetime.date, so by default instances of datetime.datetime are also permitted. Use Date(allow_datetime=False) to exclude this possibility.

Deprecated since version 6.3.0: In the future, datetime.datetime instances will not be valid values for this trait type unless “allow_datetime=True” is explicitly given.

Deprecated since version 6.3.0: In the future, None will not be a valid value for this trait type unless “allow_none=True” is explicitly given.

Parameters
  • default_value (datetime.date, optional) – The default value for this trait. If no default is provided, the default is None.

  • allow_datetime (bool, optional) – If False, instances of datetime.datetime are not valid values for this Trait. If True, datetime.datetime instances are explicitly permitted. If this argument is not given, datetime.datetime instances will be accepted, but a DeprecationWarning will be issued; in some future version of Traits, datetime.datetime instances will not be permitted.

  • allow_none (bool, optional) – If False, it’s not permitted to assign None to this trait. If True, None instances are permitted. If this argument is not given, None instances will be accepted but a DeprecationWarning will be issued; in some future verison of Traits, None may no longer be permitted.

  • **metadata (dict) – Additional metadata.

default_value_type = 0

The default value type to use.

validate(object, name, value)[source]

Check that the given value is valid date for this trait.

info()[source]

Return text description of this trait.

create_editor()[source]

Create default editor factory for this trait.

class traits.trait_types.Datetime(default_value=None, *, allow_none=None, **metadata)[source]

Bases: traits.trait_type.TraitType

A trait type whose value must be a datetime.

The value must be an instance of datetime.datetime.

Deprecated since version 6.3.0: In the future, None will not be a valid value for this trait type unless “allow_none=True” is explicitly given.

Parameters
  • default_value (datetime.datetime, optional) – The default value for this trait. If no default is provided, the default is None.

  • allow_none (bool, optional) – If False, it’s not permitted to assign None to this trait. If True, None instances are permitted. If this argument is not given, None instances will be accepted but a DeprecationWarning will be issued; in some future verison of Traits, None may no longer be permitted.

  • **metadata (dict) – Additional metadata.

default_value_type = 0

The default value type to use.

validate(object, name, value)[source]

Check that the given value is valid datetime for this trait.

info()[source]

Return text description of this trait.

create_editor()[source]

Create default editor factory for this trait.

class traits.trait_types.Time(default_value=None, *, allow_none=None, **metadata)[source]

Bases: traits.trait_type.TraitType

A trait type whose value must be a time.

The value must be an instance of datetime.time.

Deprecated since version 6.3.0: In the future, None will not be a valid value for this trait type unless “allow_none=True” is explicitly given.

Parameters
  • default_value (datetime.time, optional) – The default value for this trait. If no default is provided, the default is None.

  • allow_none (bool, optional) – If False, it’s not permitted to assign None to this trait. If True, None instances are permitted. If this argument is not given, None instances will be accepted but a DeprecationWarning will be issued; in some future verison of Traits, None may no longer be permitted.

  • **metadata (dict) – Additional metadata.

default_value_type = 0

The default value type to use.

validate(object, name, value)[source]

Check that the given value is valid time for this trait.

info()[source]

Return text description of this trait.

create_editor()[source]

Create default editor factory for this trait.

Deprecated Traits

The following TraitType classes and instances are deprecated, and may be removed in a future version of Traits.

Deprecated since version 6.0.0.

traits.trait_types.AdaptedTo = <class 'traits.trait_types.Supports'>

A trait whose value must support a specified protocol. This is an alias for Supports. Use Supports instead.

traits.trait_types.BaseUnicode = <class 'traits.trait_types.BaseStr'>

A trait whose value must be a (Unicode) string. This is an alias for BaseStr. Use BaseStr instead.

traits.trait_types.Unicode = <class 'traits.trait_types.Str'>

A trait whose value must be a (Unicode) string, using a C-level fast validator. This is an alias for Str. Use Str instead.

traits.trait_types.BaseCUnicode = <class 'traits.trait_types.BaseCStr'>

A trait whose value must be a (Unicode) string and which supports coercions of non-string values to string. This is an alias for BaseCStr. Use BaseCStr instead.

traits.trait_types.CUnicode = <class 'traits.trait_types.CStr'>

A trait whose value must be a (Unicode) string and which supports coercions of non-string values to string, using a C-level fast validator. This is an alias for CStr. Use CStr instead.

traits.trait_types.BaseLong = <class 'traits.trait_types.BaseInt'>

A trait whose value must be an integer. This is an alias for BaseInt. Use BaseInt instead.

traits.trait_types.Long = <class 'traits.trait_types.Int'>

A trait whose value must be an integer, using a C-level fast validator. This is an alias for Int. Use Int instead.

traits.trait_types.BaseCLong = <class 'traits.trait_types.BaseCInt'>

A trait whose value must be an integer and which supports coercions of non-integer values to integer. This is an alias for BaseCInt. Use BaseCInt instead.

traits.trait_types.CLong = <class 'traits.trait_types.CInt'>

A trait whose value must be an integer and which supports coercions of non-integer values to integer, using a C-level fast validator. This is an alias for CInt. Use CInt instead.

traits.trait_types.false = <class 'traits.trait_types.Bool'>

Synonym for Bool; default value is False. This trait type is deprecated. Use Bool(False) or Bool() instead.

traits.trait_types.true = <traits.trait_types.Bool object>

Boolean values only; default value is True. This trait type is deprecated. Use Bool(True) instead.

traits.trait_types.undefined = <traits.trait_types.Any object>

Allows any value to be assigned; no type-checking is performed. Default value is Undefined. This trait type is deprecated. Use Any(Undefined) instead.

traits.trait_types.ListInt = <traits.trait_types.List object>

List of integer values; default value is []. This trait type is deprecated. Use List(Int) instead.

traits.trait_types.ListFloat = <traits.trait_types.List object>

List of float values; default value is []. This trait type is deprecated. Use List(Float) instead.

traits.trait_types.ListStr = <traits.trait_types.List object>

List of string values; default value is []. This trait type is deprecated. Use List(Str) instead.

traits.trait_types.ListUnicode = <traits.trait_types.List object>

List of string values; default value is []. This trait type is deprecated. Use List(Str) instead.

traits.trait_types.ListComplex = <traits.trait_types.List object>

List of complex values; default value is []. This trait type is deprecated. Use List(Complex) instead.

traits.trait_types.ListBool = <traits.trait_types.List object>

List of Boolean values; default value is []. This trait type is deprecated. Use List(Bool) instead.

traits.trait_types.ListFunction = <traits.trait_types.List object>

List of function values; default value is []. This trait type is deprecated. Use List(Instance(types.FunctionType, allow_none=False)) instead.

traits.trait_types.ListMethod = <traits.trait_types.List object>

List of method values; default value is []. This trait type is deprecated. Use List(Instance(types.MethodType, allow_none=False)) instead.

traits.trait_types.ListThis = <traits.trait_types.List object>

List of container type values; default value is []. This trait type is deprecated. Use List(This(allow_none=False)) instead.

traits.trait_types.DictStrAny = <traits.trait_types.Dict object>

Only a dictionary with strings as keys can be assigned; only string keys can be inserted. The default value is {}. This trait type is deprecated. Use Dict(Str, Any) instead.

traits.trait_types.DictStrStr = <traits.trait_types.Dict object>

Only a dictionary mapping strings to strings can be assigned; only string keys with string values can be inserted. The default value is {}. This trait type is deprecated. Use Dict(Str, Str) instead.

traits.trait_types.DictStrInt = <traits.trait_types.Dict object>

Only a dictionary mapping strings to integers can be assigned; only string keys with integer values can be inserted. The default value is {}. This trait type is deprecated. Use Dict(Str, Int) instead.

traits.trait_types.DictStrFloat = <traits.trait_types.Dict object>

Only a dictionary mapping strings to floats can be assigned; only string keys with float values can be inserted. The default value is {}. This trait type is deprecated. Use Dict(Str, Float) instead.

traits.trait_types.DictStrBool = <traits.trait_types.Dict object>

Only a dictionary mapping strings to booleans can be assigned; only string keys with boolean values can be inserted. The default value is {}. This trait type is deprecated. Use Dict(Str, Bool) instead.

traits.trait_types.DictStrList = <traits.trait_types.Dict object>

Only a dictionary mapping strings to lists can be assigned; only string keys with list values can be inserted. The default value is {}. This trait type is deprecated. Use Dict(Str, List) instead.

Private Classes

class traits.trait_types.HandleWeakRef(object, name, value)[source]

Functions

traits.trait_types.default_text_editor(trait, type=None)[source]

Return a default text editor for a trait.

Parameters
  • trait (TraitType) – The trait we are constructing the editor for.

  • type (callable, optional) – A callable (usually a Python type) to use to evaluate the text content of the editor and return the correct type of value for the trait.

Returns

A TraitsUI TextEditor instance for the trait.

Return type

TextEditor