1
# Copyright (c) 2007, Enthought, Inc.
4
from traits.api import *
5
from traitsui.api import *
6
from traitsui.instance_choice \
7
import InstanceChoice, InstanceFactoryChoice
9
#-------------------------------------------------------------------------------
11
#-------------------------------------------------------------------------------
13
class Person ( HasStrictTraits ):
15
#---------------------------------------------------------------------------
17
#---------------------------------------------------------------------------
21
phone = Regex( value = '000-0000', regex = '\d\d\d[-]\d\d\d\d' )
23
#---------------------------------------------------------------------------
24
# Traits view definition:
25
#---------------------------------------------------------------------------
27
traits_view = View( 'name', 'age', 'phone',
28
buttons = [ 'OK', 'Cancel' ] )
30
#-------------------------------------------------------------------------------
32
#-------------------------------------------------------------------------------
35
Person( name = 'Dave', age = 39, phone = '555-1212' ),
36
Person( name = 'Mike', age = 28, phone = '555-3526' ),
37
Person( name = 'Joe', age = 34, phone = '555-6943' ),
38
Person( name = 'Tom', age = 22, phone = '555-7586' ),
39
Person( name = 'Dick', age = 63, phone = '555-3895' ),
40
Person( name = 'Harry', age = 46, phone = '555-3285' ),
41
Person( name = 'Sally', age = 43, phone = '555-8797' ),
42
Person( name = 'Fields', age = 31, phone = '555-3547' )
45
#-------------------------------------------------------------------------------
47
#-------------------------------------------------------------------------------
49
class Team ( HasStrictTraits ):
51
#---------------------------------------------------------------------------
53
#---------------------------------------------------------------------------
56
captain = Instance( Person )
57
roster = List( Person )
59
#---------------------------------------------------------------------------
60
# Traits view definitions:
61
#---------------------------------------------------------------------------
63
traits_view = View( [ 'name', '_',
65
editor = InstanceEditor( name = 'roster',
68
InstanceFactoryChoice(
71
view = 'edit_view' ) ] ) ) ],
72
buttons = [ 'OK', 'Cancel' ] )
74
#-------------------------------------------------------------------------------
76
#-------------------------------------------------------------------------------
78
if __name__ == '__main__':
79
Team( name = 'Vultures',
81
roster = people ).configure_traits()