Traits - The Next Generation.notes
Saturday, March 26, 2005
TITLE OF PAPER: Traits - The Next Generation
URL OF PRESENTATION:
PRESENTED BY: David Morrill
REPRESENTING: Enthought
CONFERENCE: PyCon 2005
DATE: Wednesday, March 23, 2005
LOCATION: GWU Cafritz Conference Center, Marvin (Pressure Cooker) Theatre
--------------------------------------------------------------------------
REAL-TIME NOTES / ANNOTATIONS OF THE PAPER:
{If you've contributed, add your name, e-mail & URL at the bottom}
PyCon presentation two years ago
* Core Traits
* Spin off of Chaco project
This year we talk about the next generation
Traits History
Traits 1: Mid 2002, spin-off from the Chaco project. Pure Python.
Talk on Traits 1 presented at PyCon 2003
Traits 2: mid 2004, Major rewrite, converted to "new style" Python types
using a C-based extension module. Much faster with a streamlined syntax
Validation
Every trait has an associated "type" or set of values that can be assigned
Or the type can be very (psychotically) flexible
Trait(0.0, Range(0.0, 1.0), Enum('low', 'middle', 'high'))
Traits comes with a number of predefined types
Constant,int, float..
Initialization
Must have default value
Does not require explicit consturtors
Delegation
Traits can be delegated, on whole, or selectively
The granularity of delegation is at a trait level
Delegated traits use no space until assigned to
Notification
Changed value triggers notification..
[Delegation Example]
(rather un-pythonic syntax)
Notification
Changes to a trait's value can trigger "notification handlers"
Two types of notifications:
normal - only triggers when the value changes
event - triggers on every assignment (even if there's no change)
Two types of notification handlers
Static - defined in the class that defines the trait via naming conv
Dynamic - using the on_trait_change(...) method
Performance implications of notification?
Is notification plugable?
Visualization
User interfaces can be easily constructed for objects with traits
Supports several different styles of UI
Panel, subpanel, modal, nonmodal, livemodal, live, wizard
Supports MVC paradigm
Each trait has a default "editor" associated with it.
There is a large set of predefined trait editors
boolean, button, enum, font, tree, ...
New editors can be defined
Cross-platform, cross-GUI (sort of)
Supports
Automatic change history (undo/redo/etc.)
Automatic and user-defined help screens
Modal or "live" dialogs
Menus, Toolbars
Dynamic updates via event handlers
Implementation
Traits 2 based on "new style" Python classes
Core functionality in a C extension
Initialization, validation, delegation, and notification all in C
Speed
Traits faster than old/new style __gets__
Puts between old/new style __puts__
Notifications add a ton of (Python code) overhead to sets
VET (View Editing Tool)
Interactive tool for creating traits-based user interfaces
Automatically generates Python modules based on an MVC framework
Somewhat different than a VB-style tool: you start with your Model and it
helps you build the View and Controller.
VET is itself a traits-based UI
Still in development, but already useful
Status
Traits is an Enthought core package, used by:
Chaco (plotting)
Enable (component framework)
Envisage (Eclipse-like plug-in framework)
Graph
Pyface (wxPython model-based widgets)
Fairly stable. Mostly tested on Win32, but some use on Linux
To do:
Add more editors (e.g. Table/List editor)
More docs (currently 132+ pp.)
Support more GUI toolkits (OS X?) (HTML? I'm guessing not, since the
whole disableIf() thing would have to be totally rethought.)
(he mentioned Tk as one currently supported GUI)
Issue first release
Example code:
The code is more "declarative" as in you don't write much code to do stuff
but rather declare stuff to make stuff happen.
--------------------------------------------------------------------------
REFERENCES: {as documents / sites are referenced add them below}
--------------------------------------------------------------------------
QUOTES:
--------------------------------------------------------------------------
CONTRIBUTORS: {add your name, e-mail address and URL below}
Nick Bastin (nick.bastin@gmail.com) <http://www.nickbastin.com>
Abhay Saxena <ark3@email.com>
Linden Wright <lwright@mac.com>
Andy Wright <waw@well.com>
--------------------------------------------------------------------------
E-MAIL BOUNCEBACK: {add your e-mail address separated by commas }
Erik Rose <corp@grinchcentral.com>
--------------------------------------------------------------------------
NOTES ON / KEY TO THIS TEMPLATE:
A headline (like a field in a database) will be CAPITALISED
This differentiates from the text that follows
A variable that you can change will be surrounded by _underscores_
Spaces in variables are also replaced with under_scores
This allows people to select the whole variable with a simple double-click
A tool-tip is lower case and surrounded by {curly brackets / parentheses}
These supply helpful contextual information.
--------------------------------------------------------------------------
Copyright shared between all the participants unless otherwise stated...