source: moxy/trunk/src/test/instance_editor_selection.py @ 789

Last change on this file since 789 was 698, checked in by jemian, 14 years ago

add some more examples and test code: test3 is getting close ...

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 1.7 KB
Line 
1
2# from http://github.enthought.com/traitsui/traitsui_user_manual/factories_basic.html
3
4# instance_editor_selection.py -- Example of an instance editor
5#                                 with instance selection
6
7from traits.api    \
8    import HasStrictTraits, Int, Instance, List, Regex, Str
9from traitsui.api \
10    import View, Item, InstanceEditor
11
12class Person ( HasStrictTraits ):
13    name  = Str
14    age   = Int
15    phone = Regex( value = '000-0000',
16                   regex = '\d\d\d[-]\d\d\d\d' )
17
18    traits_view = View( 'name', 'age', 'phone' )
19
20people = [
21  Person( name = 'Dave',   age = 39, phone = '555-1212' ),
22  Person( name = 'Mike',   age = 28, phone = '555-3526' ),
23  Person( name = 'Joe',    age = 34, phone = '555-6943' ),
24  Person( name = 'Tom',    age = 22, phone = '555-7586' ),
25  Person( name = 'Dick',   age = 63, phone = '555-3895' ),
26  Person( name = 'Harry',  age = 46, phone = '555-3285' ),
27  Person( name = 'Sally',  age = 43, phone = '555-8797' ),
28  Person( name = 'Fields', age = 31, phone = '555-3547' )
29]
30
31class Team ( HasStrictTraits ):
32
33    name    = Str
34    captain = Instance( Person )
35    roster  = List( Person )
36
37    traits_view = View( Item('name'),
38                        Item('_'),
39                        Item( 'captain',
40                              label='Team Captain',
41                              editor =
42                                  InstanceEditor( name = 'roster',
43                                                  editable = True),
44                              style = 'custom',
45                             ),
46                        buttons = ['OK'])
47
48if __name__ == '__main__':
49    Team( name    = 'Vultures',
50          captain = people[0],
51          roster  = people ).configure_traits()
52
Note: See TracBrowser for help on using the repository browser.