Debian Codegraph @

docs/source/traitsui_user_manual/examples/instance_editor_selection.py

raw
1 # (C) Copyright 2004-2023 Enthought, Inc., Austin, TX
2 # All rights reserved.
3 #
4 # This software is provided without warranty under the terms of the BSD
5 # license included in LICENSE.txt and may be redistributed only under
6 # the conditions described in the aforementioned license. The license
7 # is also available online at http://www.enthought.com/licenses/BSD.txt
8 #
9 # Thanks for using Enthought open source!
10
11 # instance_editor_selection.py -- Example of an instance editor with instance
12 # selection
13
14 from traits.api import HasStrictTraits, Instance, Int, List, Regex, Str
15 from traitsui.api import InstanceEditor, Item, View
16
17
18 class Person(HasStrictTraits):
19 name = Str()
20 age = Int()
21 phone = Regex(value='000-0000', regex=r'\d\d\d[-]\d\d\d\d')
22
23 traits_view = View('name', 'age', 'phone')
24
25
26 people = [
27 Person(name='Dave', age=39, phone='555-1212'),
28 Person(name='Mike', age=28, phone='555-3526'),
29 Person(name='Joe', age=34, phone='555-6943'),
30 Person(name='Tom', age=22, phone='555-7586'),
31 Person(name='Dick', age=63, phone='555-3895'),
32 Person(name='Harry', age=46, phone='555-3285'),
33 Person(name='Sally', age=43, phone='555-8797'),
34 Person(name='Fields', age=31, phone='555-3547'),
35 ]
36
37
38 class Team(HasStrictTraits):
39
40 name = Str()
41 captain = Instance(Person)
42 roster = List(Person)
43
44 traits_view = View(
45 Item('name'),
46 Item('_'),
47 Item(
48 'captain',
49 label='Team Captain',
50 editor=InstanceEditor(name='roster', editable=True),
51 style='custom',
52 ),
53 buttons=['OK'],
54 )
55
56
57 if __name__ == '__main__':
58 team = Team(name='Vultures', captain=people[0], roster=people)
59 team.configure_traits()