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

« back to all changes in this revision

Viewing changes to examples/demo/Advanced/Apply_Revert_handler_demo.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
"""
 
5
This program demonstrates hows how to add an event handler which performs an
 
6
action when the 'Apply' or 'Revert' buttons are pressed.
 
7
"""
 
8
 
 
9
# Imports:
 
10
from traits.api \
 
11
    import HasTraits, Str, List
 
12
 
 
13
from traitsui.api \
 
14
    import Item, View, Handler, HGroup, VGroup
 
15
 
 
16
# 'ApplyRevert_Handler' class:
 
17
class ApplyRevert_Handler ( Handler ):
 
18
 
 
19
    def apply ( self, info ):
 
20
        object = info.object
 
21
        object.stack.insert( 0, object.input )
 
22
        object.queue.append( object.input )
 
23
 
 
24
    def revert ( self, info ):
 
25
        # Do something exciting here...
 
26
        print 'revert called...'
 
27
 
 
28
# 'ApplyRevertDemo' class:
 
29
class ApplyRevertDemo ( HasTraits ):
 
30
 
 
31
    # Trait definitions:
 
32
    input = Str
 
33
    stack = List
 
34
    queue = List
 
35
 
 
36
    # Traits view definitions:
 
37
    traits_view = View(
 
38
        VGroup(
 
39
            VGroup(
 
40
                Item( 'input',
 
41
                      show_label = False
 
42
                ),
 
43
                label       = 'Input',
 
44
                show_border = True
 
45
            ),
 
46
            HGroup(
 
47
                VGroup(
 
48
                    Item( 'stack',
 
49
                          show_label = False,
 
50
                          height     = 50,
 
51
                          width      = 100,
 
52
                          style      = 'readonly'
 
53
                    ),
 
54
                    label       = 'Stack',
 
55
                    show_border = True
 
56
                ),
 
57
                VGroup(
 
58
                    Item( 'queue',
 
59
                          show_label = False,
 
60
                          height     = 50,
 
61
                          width      = 100,
 
62
                          style      = 'readonly'
 
63
                    ),
 
64
                    label       = 'Queue',
 
65
                    show_border = True
 
66
                )
 
67
            )
 
68
        ),
 
69
        title   = 'Apply/Revert example',
 
70
        buttons = [ 'Apply', 'Revert' ],
 
71
        kind    = 'modal',
 
72
        handler = ApplyRevert_Handler
 
73
    )
 
74
 
 
75
# Create the demo:
 
76
modal_popup = ApplyRevertDemo()
 
77
 
 
78
# Run the demo (if invoked from the command line):
 
79
if __name__ == '__main__':
 
80
    modal_popup.configure_traits()