Debian Codegraph @

traitsui/examples/demo/Advanced/Apply_Revert_handler_demo.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 """
12 Apply / Revert
13
14 Provides support in a dialog box for an "Apply" button which modifies the
15 object being viewed, and a "Revert" button, which returns the object to its
16 starting state (before any "Apply").
17
18 Note that this does not automatically provide a full (multi-step incremental)
19 Undo capability.
20 """
21
22 from traits.api import HasTraits, Str, List
23 from traitsui.api import Item, View, Handler, HGroup, VGroup, TextEditor
24
25
26 class ApplyRevert_Handler(Handler):
27 def apply(self, info):
28 print('apply called...')
29 object = info.object
30 object.stack.insert(0, object.input)
31 object.queue.append(object.input)
32
33 def revert(self, info):
34 # Do something exciting here...
35 print('revert called...')
36
37
38 class ApplyRevertDemo(HasTraits):
39
40 # Trait definitions:
41 input = Str()
42 stack = List()
43 queue = List()
44
45 # Traits view definitions:
46 traits_view = View(
47 VGroup(
48 VGroup(
49 Item(
50 'input', show_label=False, editor=TextEditor(auto_set=True)
51 ),
52 label='Input',
53 show_border=True,
54 ),
55 HGroup(
56 VGroup(
57 Item(
58 'stack',
59 show_label=False,
60 height=50,
61 width=100,
62 style='readonly',
63 ),
64 label='Stack',
65 show_border=True,
66 ),
67 VGroup(
68 Item(
69 'queue',
70 show_label=False,
71 height=50,
72 width=100,
73 style='readonly',
74 ),
75 label='Queue',
76 show_border=True,
77 ),
78 ),
79 ),
80 resizable=True,
81 height=300,
82 title='Apply/Revert example',
83 buttons=['Apply', 'Revert'],
84 handler=ApplyRevert_Handler,
85 )
86
87
88 # Create the demo:
89 modal_popup = ApplyRevertDemo()
90
91 # Run the demo (if invoked from the command line):
92 if __name__ == '__main__':
93 modal_popup.configure_traits(kind='modal')