~ubuntu-branches/ubuntu/utopic/python-traitsui/utopic

« back to all changes in this revision

Viewing changes to integrationtests/ui/instance_editor_test6.py

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath
  • Date: 2011-07-09 13:57:39 UTC
  • Revision ID: james.westby@ubuntu.com-20110709135739-x5u20q86huissmn1
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#  Copyright (c) 2007, Enthought, Inc.
 
2
#  License: BSD Style.
 
3
 
 
4
from traits.api    import *
 
5
from traitsui.api import *
 
6
from traitsui.instance_choice \
 
7
    import InstanceChoice, InstanceFactoryChoice
 
8
 
 
9
#-------------------------------------------------------------------------------
 
10
#  'Person' class:
 
11
#-------------------------------------------------------------------------------
 
12
 
 
13
class Person ( HasStrictTraits ):
 
14
 
 
15
    #---------------------------------------------------------------------------
 
16
    #  Trait definitions:
 
17
    #---------------------------------------------------------------------------
 
18
 
 
19
    name  = Str
 
20
    age   = Int
 
21
    phone = Regex( value = '000-0000', regex = '\d\d\d[-]\d\d\d\d' )
 
22
 
 
23
    #---------------------------------------------------------------------------
 
24
    #  Traits view definition:
 
25
    #---------------------------------------------------------------------------
 
26
 
 
27
    traits_view = View( 'name', 'age', 'phone',
 
28
                        buttons = [ 'OK', 'Cancel' ] )
 
29
 
 
30
#-------------------------------------------------------------------------------
 
31
#  Sample data:
 
32
#-------------------------------------------------------------------------------
 
33
 
 
34
people = [
 
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' )
 
43
]
 
44
 
 
45
#-------------------------------------------------------------------------------
 
46
#  'Team' class:
 
47
#-------------------------------------------------------------------------------
 
48
 
 
49
class Team ( HasStrictTraits ):
 
50
 
 
51
    #---------------------------------------------------------------------------
 
52
    #  Trait definitions:
 
53
    #---------------------------------------------------------------------------
 
54
 
 
55
    name    = Str
 
56
    captain = Instance( Person )
 
57
    roster  = List( Person )
 
58
 
 
59
    #---------------------------------------------------------------------------
 
60
    #  Traits view definitions:
 
61
    #---------------------------------------------------------------------------
 
62
 
 
63
    traits_view = View( [ 'name', '_',
 
64
                          Item( 'captain',
 
65
                                editor = InstanceEditor( name   = 'roster',
 
66
                                                         label  = 'Edit...',
 
67
                                                         values = [
 
68
                                             InstanceFactoryChoice(
 
69
                                                 klass = Person,
 
70
                                                 name  = 'Non player',
 
71
                                                 view  = 'edit_view' ) ] ) ) ],
 
72
                        buttons = [ 'OK', 'Cancel' ] )
 
73
 
 
74
#-------------------------------------------------------------------------------
 
75
#  Run the test:
 
76
#-------------------------------------------------------------------------------
 
77
 
 
78
if __name__ == '__main__':
 
79
    Team( name    = 'Vultures',
 
80
          captain = people[0],
 
81
          roster  = people ).configure_traits()