trait_types Module

Core Trait definitions.

Traits

class traits.trait_types.Any(default_value=<traits.trait_handlers.NoDefaultSpecified object>, **metadata)[source]

Defines a trait whose value can be anything.

default_value = None

The default value for the trait:

info_text = 'any value'

A description of the type of value this trait accepts:

class traits.trait_types.Generic(default_value=<traits.trait_handlers.NoDefaultSpecified object>, **metadata)[source]

Defines a trait whose value can be anything and whose definition can be redefined via assignment using a TraitValue object.

metadata = {'trait_value': True}

The standard metadata for the trait:

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

Defines a trait whose type must be an int or long.

evaluate

The function to use for evaluating strings to this type:

alias of int

default_value = 0

The default value for the trait:

info_text = 'an integer (int or long)'

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_handlers.NoDefaultSpecified object>, **metadata)[source]

Defines a trait whose type must be an int or long using a C-level fast validator.

fast_validate = (20,)

The C-level fast validator to use:

class traits.trait_types.BaseLong(default_value=<traits.trait_handlers.NoDefaultSpecified object>, **metadata)[source]

Defines a trait whose value must be a Python long.

evaluate

The function to use for evaluating strings to this type:

alias of long

default_value = 0L

The default value for the trait:

info_text = 'a long'

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.Long(default_value=<traits.trait_handlers.NoDefaultSpecified object>, **metadata)[source]

Defines a trait whose value must be a Python long using a C-level fast validator.

fast_validate = (11, <type 'long'>, None, <type 'int'>)

The C-level fast validator to use:

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

Defines a trait whose value must be a Python float.

evaluate

The function to use for evaluating strings to this type:

alias of float

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_handlers.NoDefaultSpecified object>, **metadata)[source]

Defines a trait whose value must be a Python float using a C-level fast validator.

fast_validate = (11, <type 'float'>, None, <type 'int'>, <type 'long'>)

The C-level fast validator to use:

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

Defines a trait whose value must be a Python complex.

evaluate

The function to use for evaluating strings to this type:

alias of complex

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_handlers.NoDefaultSpecified object>, **metadata)[source]

Defines a trait whose value must be a Python complex using a C-level fast validator.

fast_validate = (11, <type 'complex'>, None, <type 'float'>, <type 'int'>)

The C-level fast validator to use:

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

Defines a trait whose value must be a Python string.

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_handlers.NoDefaultSpecified object>, **metadata)[source]

Defines a trait whose value must be a Python string using a C-level fast validator.

fast_validate = (11, <type 'basestring'>)

The C-level fast validator to use:

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

Defines a string type which by default uses the traits ui TitleEditor when used in a View.

create_editor()[source]

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

class traits.trait_types.BaseUnicode(default_value=<traits.trait_handlers.NoDefaultSpecified object>, **metadata)[source]

Defines a trait whose value must be a Python unicode string.

default_value = u''

The default value for the trait:

info_text = 'a unicode 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.Unicode(default_value=<traits.trait_handlers.NoDefaultSpecified object>, **metadata)[source]

Defines a trait whose value must be a Python unicode string using a C-level fast validator.

fast_validate = (11, <type 'unicode'>, None, <type 'str'>)

The C-level fast validator to use:

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

Defines a trait whose value must be a Python bytes string.

default_value = ''

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_handlers.NoDefaultSpecified object>, **metadata)[source]

Defines a trait whose value must be a Python bytes string using a C-level fast validator.

fast_validate = (11, <type 'str'>)

The C-level fast validator to use:

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

Defines a trait whose value must be a Python boolean.

evaluate

The function to use for evaluating strings to this type:

alias of bool

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_handlers.NoDefaultSpecified object>, **metadata)[source]

Defines a trait whose value must be a Python boolean using a C-level fast validator.

fast_validate = (11, <type 'bool'>)

The C-level fast validator to use:

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

Defines a trait whose value must be a Python int and which supports coercions of non-int values to int.

evaluate

The function to use for evaluating strings to this type:

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_handlers.NoDefaultSpecified object>, **metadata)[source]

Defines a trait whose value must be a Python int and which supports coercions of non-int values to int using a C-level fast validator.

fast_validate = (12, <type 'int'>)

The C-level fast validator to use:

class traits.trait_types.BaseCLong(default_value=<traits.trait_handlers.NoDefaultSpecified object>, **metadata)[source]

Defines a trait whose value must be a Python long and which supports coercions of non-long values to long.

evaluate

The function to use for evaluating strings to this type:

alias of long

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.CLong(default_value=<traits.trait_handlers.NoDefaultSpecified object>, **metadata)[source]

Defines a trait whose value must be a Python long and which supports coercions of non-long values to long using a C-level fast validator.

fast_validate = (12, <type 'long'>)

The C-level fast validator to use:

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

Defines a trait whose value must be a Python float and which supports coercions of non-float values to float.

evaluate

The function to use for evaluating strings to this type:

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_handlers.NoDefaultSpecified object>, **metadata)[source]

Defines a trait whose value must be a Python float and which supports coercions of non-float values to float using a C-level fast validator.

fast_validate = (12, <type 'float'>)

The C-level fast validator to use:

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

Defines a trait whose value must be a Python complex and which supports coercions of non-complex values to complex.

evaluate

The function to use for evaluating strings to this type:

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_handlers.NoDefaultSpecified object>, **metadata)[source]

Defines a trait whose value must be a Python complex and which supports coercions of non-complex values to complex using a C-level fast validator.

fast_validate = (12, <type 'complex'>)

The C-level fast validator to use:

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

Defines a trait whose value must be a Python string and which supports coercions of non-string values to 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_handlers.NoDefaultSpecified object>, **metadata)[source]

Defines a trait whose value must be a Python string and which supports coercions of non-string values to string using a C-level fast validator.

fast_validate = (7, ((12, <type 'str'>), (12, <type 'unicode'>)))

The C-level fast validator to use:

class traits.trait_types.BaseCUnicode(default_value=<traits.trait_handlers.NoDefaultSpecified object>, **metadata)[source]

Defines a trait whose value must be a Python unicode string and which supports coercions of non-unicode values to unicode.

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.CUnicode(default_value=<traits.trait_handlers.NoDefaultSpecified object>, **metadata)[source]

Defines a trait whose value must be a Python unicode string and which supports coercions of non-unicode values to unicode using a C-level fast validator.

fast_validate = (12, <type 'unicode'>)

The C-level fast validator to use:

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

Defines a trait whose value must be a Python bytes object and which supports coercions of non-bytes values to bytes.

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_handlers.NoDefaultSpecified object>, **metadata)[source]

Defines a trait whose value must be a Python bytes and which supports coercions of non-bytes values bytes using a C-level fast validator.

fast_validate = (12, <type 'str'>)

The C-level fast validator to use:

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

Defines a trait whose value must be a Python boolean and which supports coercions of non-boolean values to boolean.

evaluate

The function to use for evaluating strings to this type:

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_handlers.NoDefaultSpecified object>, **metadata)[source]

Defines a trait whose value must be a Python boolean and which supports coercions of non-boolean values to boolean using a C-level fast validator.

fast_validate = (12, <type 'bool'>)

The C-level fast validator to use:

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

Defines a trait whose value must be a Python string whose length is optionally in a specified range, and which optionally matches a specified regular expression.

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]

Defines a trait whose value is a Python string that matches a specified regular expression.

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

Defines a trait whose value is a Python string that represents source code in some language.

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

The standard metadata for the trait:

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

Defines a trait whose value must be a string that is interpreted as being HTML. By default the value is parsed and displayed as HTML in TraitsUI views. The validation of the value does not enforce HTML syntax.

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

The standard metadata for the trait:

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

Defines a trait whose value must be a string, optionally of constrained length or matching a regular expression.

The trait is identical to a String trait except that by default it uses a PasswordEditor in TraitsUI views, which obscures text entered by the user.

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

The standard metadata for the trait:

class traits.trait_types.Callable(default_value=<traits.trait_handlers.NoDefaultSpecified object>, **metadata)[source]

Defines a trait whose value must be a Python callable.

metadata = {'copy': 'ref'}

The standard metadata for the trait:

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.BaseType(default_value=<traits.trait_handlers.NoDefaultSpecified object>, **metadata)[source]

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

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]

Defines a trait whose value must be an instance of the defining class.

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

A description of the type of value this trait accepts:

fast_validate = (2,)

The C-level fast validator to use:

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

Defines a trait whose value must be an instance of the defining class and whose default value is the object containing the trait.

default_value_type = 2

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

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

Defines a trait whose value must be a Python function.

fast_validate = (11, <type '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_handlers.NoDefaultSpecified object>, **metadata)[source]

Defines a trait whose value must be a Python method.

fast_validate = (11, <type 'instancemethod'>)

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.Class(default_value=<traits.trait_handlers.NoDefaultSpecified object>, **metadata)[source]

Defines a trait whose value must be an old-style Python class.

fast_validate = (11, <type 'classobj'>)

The C-level fast validator to use:

info_text = 'an old-style class'

A description of the type of value this trait accepts:

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

Defines a trait whose value must be a Python module.

fast_validate = (11, <type '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_handlers.NoDefaultSpecified object>, **metadata)[source]

Defines a trait that provides behavior identical to a standard Python attribute. That is, it 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 = <undefined>

The default value for the trait:

traits.trait_types.ReadOnly[source]
traits.trait_types.Disallow[source]
class traits.trait_types.Constant(value, **metadata)[source]

Defines a trait whose value is a constant.

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]

Defines a trait whose value is delegated to a trait on another object.

ctrait_type = 3

Defines the CTrait type to use for this trait:

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]

Defines a trait delegate that matches the standard ‘delegate’ design pattern.

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

Defines a trait delegate that matches the standard ‘prototype’ design pattern.

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

Defines a trait 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 = '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_handlers.NoDefaultSpecified object>, **metadata)[source]

Defines a trait whose value can be of any type, and whose default editor is a Python shell.

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]

Defines a trait whose value must be the name of a file.

info_text = 'a file name'

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.

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

Defines a trait whose value must be the name of a file using a C-level fast validator.

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

Defines a trait whose value must be the name of a directory.

info_text = 'a directory name'

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.

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

Defines a trait whose value must be the name of a directory using a C-level fast validator.

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

Defines a trait whose numeric value must be in a specified range.

init_fast_validator(*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.

long_validate(object, name, value)[source]

Validate that the value is a long 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]

Defines a trait whose numeric value must be in a specified range using a C-level fast validator.

init_fast_validator(*args)[source]

Set up the C-level fast validator.

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

Defines a trait whose value must be one of a specified set of values.

init_fast_validator(*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, **metadata)[source]

Defines a trait whose value must be one of a specified set of values using a C-level fast validator.

init_fast_validator(*args)[source]

Set up the C-level fast validator.

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

Defines a trait whose value must be a tuple of specified trait types.

__init__(*types, **metadata)[source]

Returns a Tuple trait.

Parameters:types (zero or more arguments) – 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.

Default Value

  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).

init_fast_validator(*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]

Defines a trait whose value must be a tuple of specified trait types using a C-level fast validator.

init_fast_validator(*args)[source]

Set up the C-level fast validator.

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

A Tuple trait that supports custom validation.

__init__(*types, **metadata)[source]

Returns a ValidatedTuple trait

Parameters:
  • types (zero or more arguments) – 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.

For example:

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

This definition 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]

Defines a trait whose value must be a list whose items are of the specified trait type.

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]

Defines a trait whose values must be a list whose items are of the specified trait type or which can be coerced to a list whose values are of the specified trait 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.Set(trait=None, value=None, items=True, **metadata)[source]

Defines a trait whose value must be a set whose items are of the specified trait type.

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]

Defines a trait whose values must be a set whose items are of the specified trait type or which can be coerced to a set whose values are of the specified trait 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]

Defines a trait whose value must be a dictionary, optionally with specified types for keys and values.

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.BaseClass(default_value=<traits.trait_handlers.NoDefaultSpecified object>, **metadata)[source]

Base class for types which have an associated class which can be determined dynamically by specifying a string name for the class (e.g. ‘package1.package2.module.class’.

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.

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

Defines a trait whose value must be an instance of a specified class, or one of its subclasses.

validate(object, name, value)[source]

Validates that the value is a valid object instance.

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.

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’, ‘AdaptedTo’ and ‘AdaptsTo’ classes to set up the C-level fast validator.

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

Defines a trait whose value must be an instance of a specified class, or one of its subclasses using a C-level fast validator.

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]

A traits 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 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]

A traits 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]

Defines a trait whose value must be a subclass of a specified class.

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.

class traits.trait_types.Event(trait=None, **metadata)[source]
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]

Defines a trait whose UI editor is a button.

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

Defines a trait whose UI editor is a button that can be used on a toolbar.

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

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

as_ctrait()[source]

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

class traits.trait_types.Symbol(default_value=<traits.trait_handlers.NoDefaultSpecified object>, **metadata)[source]
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(**metadata)[source]

Defines a trait whose value is a globally unique UUID (type 4).

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.

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

Returns a trait whose value must be an instance of the same type (or a subclass) of the specified klass, which can be a class or an instance. Note that the trait only maintains a weak reference to the assigned value.

traits.trait_types.Date = <traits.trait_types.BaseInstance object>

Defines a trait whose value must be an instance of a specified class, or one of its subclasses.

traits.trait_types.Time = <traits.trait_types.BaseInstance object>

Defines a trait whose value must be an instance of a specified class, or one of its subclasses.

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

List of integer values; default value is [].

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

List of float values; default value is [].

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

List of string values; default value is [].

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

List of Unicode string values; default value is [].

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

List of complex values; default value is [].

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

List of Boolean values; default value is [].

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

List of function values; default value is [].

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

List of method values; default value is [].

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

List of class values; default value is [].

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

List of instance values; default value is [].

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

List of container type values; default value is [].

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

Only a dictionary of string:Any values can be assigned; only string keys can be inserted. The default value is {}.

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

Only a dictionary of string:string values can be assigned; only string keys with string values can be inserted. The default value is {}.

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

Only a dictionary of string:integer values can be assigned; only string keys with integer values can be inserted. The default value is {}.

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

Only a dictionary of string:long-integer values can be assigned; only string keys with long-integer values can be inserted. The default value is {}.

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

Only a dictionary of string:float values can be assigned; only string keys with float values can be inserted. The default value is {}.

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

Only a dictionary of string:bool values can be assigned; only string keys with boolean values can be inserted. The default value is {}.

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

Only a dictionary of string:list values can be assigned; only string keys with list values can be assigned. The default value is {}.

Private Classes

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

Functions

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