Attributes
- default_value_type
default_value_type = -Const(1)
- editor
editor = None
- has_items
has_items = False
- info_text
info_text = 'a legal value'
- is_mapped
is_mapped = False
Method summary
- arg_error(self, method, arg_num, object, name, value)
- create_editor(self)
- dup_arg_error(self, method, arg_num, object, name)
- error(self, object, name, value)
- full_info(self, object, name, value)
- get_editor(self, trait = None)
- info(self)
- inner_traits(self)
- is_valid(self, object, name, value)
- keyword_error(self, method, object, name, value)
- missing_arg_error(self, method, arg_num, object, name)
- repr(self, value)
- return_error(self, method, object, value)
Methods
- arg_error(self, method, arg_num, object, name, value)
Raises a TraitError exception to notify the user that a method on an instance received a positional argument of an incorrect type.
Parameters
- method : function
- The method that encountered the error
- arg_num : integer
- The position of the incorrect argument in the argument list
- object : object
- The object whose method was called
- name : string
- The name of the parameter corresponding to the incorrect argument
- value
- The value passed to the argument
Description
This method can be called when type-checking a method.
- create_editor(self)
Returns the default traits UI editor to use for a trait.
- dup_arg_error(self, method, arg_num, object, name)
Raises a TraitError exception to notify the user that a method on an instance received an argument as both a keyword argument and a positional argument.
Parameters
- method : function
- The method that encountered the error
- arg_num : integer
- The position of the incorrect argument in the argument list
- object : object
- The object whose method was called
- name : string
- The name of the parameter corresponding to the incorrect argument
Description
This method can be called when type-checking a method.
- error(self, object, name, value)
Raises a TraitError exception.
Parameters
- object : object
- The object whose attribute is being assigned
- name : string
- The name of the attribute being assigned
- value
- The proposed new value for the attribute
Description
This method is called by the validate() method when an assigned value is not valid. Raising a TraitError exception either notifies the user of the problem, or, in the case of compound traits, provides a chance for another trait handler to handle to validate the value.
- full_info(self, object, name, value)
Returns a string describing the type of value accepted by the trait handler.
Parameters
- object : object
- The object whose attribute is being assigned
- name : string
- The name of the attribute being assigned
- value
- The proposed new value for the attribute
Description
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 full_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 full_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. For example, TraitRange instances return a string indicating the range of values acceptable to the handler (e.g., "an integer in the range from 1 to 9"). If the full_info() method is not overridden, the default method returns the value of calling the info() method.
- get_editor(self, trait = None)
Returns a trait editor that allows the user to modify the trait trait.
Parameters
- trait : trait
- The trait to be edited
Description
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.
- info(self)
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. For example, TraitRange instances return a string indicating the range of values acceptable to the handler (e.g., "an integer in the range from 1 to 9"). If the info() method is not overridden, the default method returns the value of the 'info_text' attribute.
- inner_traits(self)
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, ).
- is_valid(self, object, name, value)
- keyword_error(self, method, object, name, value)
Raises a TraitError exception to notify the user that a method on an instance received a keyword argument of an incorrect type.
Parameters
- method : function
- The method that encountered the error
- object : object
- The object whose method was called
- name : string
- The name of the parameter corresponding to the incorrect argument
- value
- The value passed to the argument
Description
This method can be called when type-checking a method.
- missing_arg_error(self, method, arg_num, object, name)
Raises a TraitError exception to notify the user that a method on an instance failed to receive a required positional argument.
Parameters
- method : function
- The method that encountered the error
- arg_num : integer
- The position of the incorrect argument in the argument list
- object : object
- The object whose method was called
- name : string
- The name of the parameter corresponding to the incorrect argument
Description
This method can be called when type-checking a method.
- repr(self, value)
Returns a printable representation of a value.
Parameters
- value
- The value to be printed
Description
If value is an instance, the method returns the printable representation of the instance's class.
- return_error(self, method, object, value)
Raises a TraitError exception to notify the user that a method on an instance returned a value of incorrect type.
Parameters
- method : function
- The method that encountered the error
- object : object
- The object whose method was called
- value
- The value returned by the method
Description
This method can be called when type-checking a method.