Traits User Manual
  Table of Contents Next: 1 Introduction
Traits User Manual
1 Introduction
1.1 What Are Traits?
1.2 Background
2 Defining Traits: Initialization and Validation
2.1 Predefined Traits
2.1.1 Predefined Traits for Simple Types
2.1.2 Other Predefined Traits
2.2 Trait Metadata
2.2.1 Internal Metadata Attributes
2.2.2 Recognized Metadata Attributes
2.2.3 Accessing Metadata Attributes
3 Trait Notification
3.1 Dynamic Notification
3.1.1 Example of a Dynamic Notification Handler
3.1.2 The name Parameter
3.1.3 Notification Handler Signatures
3.1.4 Dynamic Handler Special Cases
3.2 Static Notification
3.2.1 Handler Decorator
3.2.2 Specially-named Notification Handlers
3.2.3 Attribute-specific Handler Signatures
3.2.4 General Static Handler Signatures
3.3 Trait Events
3.4 Undefined Object
4 Deferring Trait Definitions
4.1 DelegatesTo
4.2 PrototypedFrom
4.3 Keyword Parameters
4.3.1 Prefix Keyword
4.3.2 Listenable Keyword
5 Custom Traits
5.1 Trait Subclassing
5.1.1 Defining a Trait Type
5.1.2 Defining a Trait Property
5.1.3 Other TraitType Members
5.2 The Trait() Factory Function
5.2.1 Trait () Parameters
5.2.2 Mapped Traits
5.3 Trait Handlers
5.3.1 TraitPrefixList
5.3.2 TraitPrefixMap
5.4 Custom Trait Handlers
5.4.1 Example Custom Trait Handler
6 Advanced Topics
6.1 Initialization and Validation Revisited
6.1.1 Dynamic Initialization
6.1.2 Overriding Default Values in a Subclass
6.1.3 Trait Attribute Definition Strategies
6.1.4 Type-Checked Methods
6.2 Interfaces
6.2.1 Defining an Interface
6.2.2 Implementing an Interface
6.2.3 Using Interfaces
6.3 Adaptation
6.3.1 Defining Adapters
6.3.2 Using Adapters
6.3.3 Controlling Adaptation
6.4 Property Traits
6.4.1 Property Factory Function
6.4.2 Caching a Property Value
6.5 Persistence
6.5.1 Pickling HasTraits Objects
6.5.2 Predefined Transient Traits
6.5.3 Overriding __getstate__()
6.5.4 Unpickling HasTraits Objects
6.5.5 Overriding __setstate__()
6.6 Useful Methods on HasTraits
6.6.1 add_trait()
6.6.2 clone_traits()
6.6.3 set()
6.6.4 add_class_trait()
6.7 Performance Considerations of Traits


Traits User Manual

David C. Morrill
Janet M. Swisher

Document Version 4


© 2005, 2006, 2008 Enthought, Inc.

All Rights Reserved.

Redistribution and use of this document in source and derived forms, with or without modification, are permitted provided that the following conditions are met:

Redistributions of source or derived format (for example, Portable Document Format or Hypertext Markup Language) must retain the above copyright notice, this list of conditions and the following disclaimer.

Neither the name of Enthought, Inc., nor the names of contributors may be used to endorse or promote products derived from this document without specific prior written permission.

THIS DOCUMENT IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS DOCUMENT, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

All trademarks and registered trademarks are the property of their respective owners.

Enthought, Inc.

515 Congress Avenue

Suite 2100

Austin TX 78701

1.512.536.1057 (voice)

1.512.536.1059 (fax)

http://www.enthought.com

info@enthought.com



Revision History

Version

Date

Description

1.0

12-May-05

Initial published version.

1.1

9-Feb-06

Converted source files from OpenOffice.org to Microsoft Word. Removed sections on Traits UI, as these are now covered in the Traits UI User Guide.

1.2

3-Jan-07

Converted to a template that is more compatible with Pydoh. Removed “Syntax and Class Reference”, as this content is now covered in the Traits API Reference.

3

11-Apr-08

Revised and updated to reflect Traits 3.0. Incremented the version number to match the software version.

4

11-Aug-08

Minor updates for Traits 3.0 release. Document version is now independent of the software version.

 

 










  Table of Contents Next: 1 Introduction
Traits User Manual