1
# Copyright (c) 2007, Enthought, Inc.
13
#-------------------------------------------------------------------------------
15
#-------------------------------------------------------------------------------
17
class Person ( Handler ):
19
#---------------------------------------------------------------------------
21
#---------------------------------------------------------------------------
25
phone = Regex( value = '000-0000', regex = '\d\d\d[-]\d\d\d\d' )
28
#---------------------------------------------------------------------------
29
# Handles the 'Annoy' button being clicked:
30
#---------------------------------------------------------------------------
32
def _annoy_clicked ( self, info ):
33
self.edit_traits( view = View( title = 'Annoying',
35
buttons = [ 'OK' ] ) )
37
#-------------------------------------------------------------------------------
39
#-------------------------------------------------------------------------------
41
if __name__ == '__main__':
42
AnnoyButton = Action( name = 'Annoy',
43
tooltip = 'Click me to be annoyed',
44
enabled_when = 'age >= 40' )
46
person = Person( name = 'Bill', age = 42, phone = '555-1212' )
48
fields = Group( 'name', 'age', 'phone', 'notes~' )
50
person.notes = ("Should have 6 standard 'live' buttons: Undo, Redo, "
51
"Revert, OK, Cancel, Help")
52
person.configure_traits( view = View( fields,
54
buttons = LiveButtons ) )
56
person.notes = ("Should have 5 standard 'modal' buttons: Apply, Revert, "
58
person.configure_traits( view = View( fields,
59
buttons = ModalButtons ) )
61
person.notes = "Should have 2 standard buttons: OK, Cancel"
62
person.configure_traits(
64
buttons = [ OKButton, CancelButton ] ) )
66
person.notes = "Should have 1 standard button: OK (enabled when age >= 40)"
67
person.configure_traits(
69
buttons = [ Action( name = 'OK',
70
enabled_when = 'age >= 40' ) ] ) )
72
person.notes = "Should have 1 standard button: OK (visible when age >= 40)"
73
person.configure_traits(
75
buttons = [ Action( name = 'OK',
76
visible_when = 'age >= 40' ) ] ) )
78
person.notes = ("Should have 2 standard buttons: OK, Help (defined when "
80
person.configure_traits(
82
buttons = [ 'OK', Action( name = 'Help',
83
defined_when = 'age >= 50' ) ] ) )
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(
89
buttons = [ AnnoyButton ] + ModalButtons ) )