API Reference for Enthought Tool Suite 3.0.1
Defines the HasTraits class, along with several useful subclasses and associated metaclasses.
Generic 'Any' trait:
any_trait = Any().as_ctrait()
BaseTraits = '__base_traits__'
Trait types which cannot have default values
CantHaveDefaultValue = ('event', 'delegate', 'constant')
CHECK_INTERFACES = 0
ClassTraits = '__class_traits__'
The default Traits View name
DefaultTraitsView = 'traits_view'
The trait types that should be copied last when doing a 'copy_traits':
DeferredCopy = ('delegate', 'property')
An empty list
EmptyList = [ ]
Quick test for normal vs extended trait name
extended_trait_pat = re.compile('.*[ :\\+\\-,\\.\\*\\?\\[\\]]')
FunctionTypes = (FunctionType, CTraitMethod)
ImplementsClass = '__implements__'
InstanceTraits = '__instance_traits__'
ListenerTraits = '__listener_traits__'
MethodTypes = (MethodType, CTraitMethod)
PrefixTraits = '__prefix_traits__'
SubclassTraits = '__subclass_traits__'
VetoableEvent = Event(Vetoable)
ViewTraits = '__view_traits__'
WrapperTypes = (StaticAnyTraitChangeNotifyWrapper, StaticTraitChangeNotifyWrapper)
Marks the following method definition as being a "cached property". That is, it is a property getter which, for performance reasons, caches its most recently computed result in an attribute whose name is of the form: _traits_cache_name, where name is the name of the property. A method marked as being a cached property needs only to compute and return its result. The @cached_property decorator automatically wraps the decorated method in cache management code, eliminating the need to write boilerplate cache management code explicitly. For example:
file_name = File
file_contents = Property( depends_on = 'file_name' )
@cached_property
def _get_file_contents(self):
fh = open(self.file_name, 'rb')
result = fh.read()
fh.close()
return result
In this example, accessing the file_contents trait calls the _get_file_contents() method only once each time after the file_name trait is modified. In all other cases, the cached value _file_contents, which maintained by the @cached_property wrapper code, is returned.
Note the use, in the example, of the depends_on metadata attribute to specify that the value of file_contents depends on file_name, so that _get_file_contents() is called only when file_name changes. For details, see the enthought.traits.traits.Property() function.
Returns the correct 'delegate' listener pattern for a specified name and delegate trait.
Declares the interfaces that a class implements.
Nothing
Registers each specified interface with the interface manager as an interface that the containing class implements. Each specified interface must be a subclass of Interface. This function should only be called from directly within a class body.
Declares that the method defined immediately following a call to this function is type-checked.
Whenever the type-checked method is called, the method() function ensures that each parameter passed to the method of the type specified by arg_types and kwarg_types, and that the return value is of the type specified by return_type. It is an error to specify both positional and keyword definitions for the same method parameter. If a parameter defined by the type-checked method is not referenced in the method() call, the parameter is not type-checked (i.e., its type is implicitly set to Any). If the call to method() signature contains an arg_types or kwarg_types parameter that does not correspond to a parameter in the type-checked method definition, a TraitError exception is raised.
Marks the following method definition as being a handler for the extended trait change specified by name(s).
Refer to the documentation for the on_trait_change() method of the HasTraits class for information on the correct syntax for the name(s) argument.
A handler defined using this decorator is normally effective immediately. However, if post_init is True, then the handler only become effective after all object constructor arguments have been processed. That is, trait values assigned as part of object construction will not cause the handler to be invoked.
Marks the following method definition as being a "cached property" that depends on the specified extended trait names. That is, it is a property getter which, for performance reasons, caches its most recently computed result in an attribute whose name is of the form: _traits_cache_name, where name is the name of the property. A method marked as being a cached property needs only to compute and return its result. The @property_depends_on decorator automatically wraps the decorated method in cache management code that will cache the most recently computed value and flush the cache when any of the specified dependencies are modified, thus eliminating the need to write boilerplate cache management code explicitly. For example:
file_name = File
file_contents = Property
@property_depends_on( 'file_name' )
def _get_file_contents(self):
fh = open(self.file_name, 'rb')
result = fh.read()
fh.close()
return result
In this example, accessing the file_contents trait calls the _get_file_contents() method only once each time after the file_name trait is modified. In all other cases, the cached value _file_contents, which is maintained by the @cached_property wrapper code, is returned.
Factory function for creating type-checked methods.
© Copyright 2002-2008 Enthought, Inc.