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

« back to all changes in this revision

Viewing changes to integrationtests/ui/buttons_test.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 \
 
5
    import *
 
6
 
 
7
from traitsui.api \
 
8
    import *
 
9
 
 
10
from traitsui.menu \
 
11
    import *
 
12
 
 
13
#-------------------------------------------------------------------------------
 
14
#  'Person' class:
 
15
#-------------------------------------------------------------------------------
 
16
 
 
17
class Person ( Handler ):
 
18
 
 
19
    #---------------------------------------------------------------------------
 
20
    #  Trait definitions:
 
21
    #---------------------------------------------------------------------------
 
22
 
 
23
    name  = Str
 
24
    age   = Int
 
25
    phone = Regex( value = '000-0000', regex = '\d\d\d[-]\d\d\d\d' )
 
26
    notes = Str
 
27
 
 
28
    #---------------------------------------------------------------------------
 
29
    #  Handles the 'Annoy' button being clicked:
 
30
    #---------------------------------------------------------------------------
 
31
 
 
32
    def _annoy_clicked ( self, info ):
 
33
        self.edit_traits( view = View( title   = 'Annoying',
 
34
                                       kind    = 'modal',
 
35
                                       buttons = [ 'OK' ] ) )
 
36
 
 
37
#-------------------------------------------------------------------------------
 
38
#  Run the tests:
 
39
#-------------------------------------------------------------------------------
 
40
 
 
41
if __name__ == '__main__':
 
42
    AnnoyButton = Action( name         = 'Annoy',
 
43
                          tooltip      = 'Click me to be annoyed',
 
44
                          enabled_when = 'age >= 40' )
 
45
 
 
46
    person = Person( name = 'Bill', age = 42, phone = '555-1212' )
 
47
 
 
48
    fields = Group( 'name', 'age', 'phone', 'notes~' )
 
49
 
 
50
    person.notes = ("Should have 6 standard 'live' buttons: Undo, Redo, "
 
51
                    "Revert, OK, Cancel, Help")
 
52
    person.configure_traits( view = View( fields,
 
53
                             kind    = 'livemodal',
 
54
                             buttons = LiveButtons ) )
 
55
 
 
56
    person.notes = ("Should have 5 standard 'modal' buttons: Apply, Revert, "
 
57
                    "OK, Cancel, Help")
 
58
    person.configure_traits( view = View( fields,
 
59
                                          buttons = ModalButtons ) )
 
60
 
 
61
    person.notes = "Should have 2 standard buttons: OK, Cancel"
 
62
    person.configure_traits(
 
63
               view = View( fields,
 
64
                            buttons = [ OKButton, CancelButton ] ) )
 
65
 
 
66
    person.notes = "Should have 1 standard button: OK (enabled when age >= 40)"
 
67
    person.configure_traits(
 
68
               view = View( fields,
 
69
                            buttons      = [ Action( name = 'OK',
 
70
                            enabled_when = 'age >= 40' ) ] ) )
 
71
 
 
72
    person.notes = "Should have 1 standard button: OK (visible when age >= 40)"
 
73
    person.configure_traits(
 
74
               view = View( fields,
 
75
                            buttons      = [ Action( name = 'OK',
 
76
                            visible_when = 'age >= 40' ) ] ) )
 
77
 
 
78
    person.notes = ("Should have 2 standard buttons: OK, Help (defined when "
 
79
                    "age >= 50)")
 
80
    person.configure_traits(
 
81
               view = View( fields,
 
82
                            buttons      = [ 'OK', Action( name = 'Help',
 
83
                            defined_when = 'age >= 50' ) ] ) )
 
84
 
 
85
    person.notes = ("Should have 1 user and 5 standard buttons: Annoy (enabled "
 
86
                    "when age >= 40), Apply, Revert, OK, Cancel, Help")
 
87
    person.configure_traits(
 
88
               view    = View( fields,
 
89
               buttons = [ AnnoyButton ] + ModalButtons ) )
 
90