Debian Codegraph @

traitsui/examples/demo/Standard_Editors/ButtonEditor_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 Implementation of a ButtonEditor demo plugin for Traits UI demo program.
13
14 This demo shows each of the two styles of the ButtonEditor.
15 (As of this writing, they are identical.)
16
17 Please refer to the `ButtonEditor API docs`_ for further information.
18
19 .. _ButtonEditor API docs: https://docs.enthought.com/traitsui/api/traitsui.editors.button_editor.html#traitsui.editors.button_editor.ButtonEditor
20 """
21
22 from traits.api import HasTraits, Button, observe
23 from traitsui.api import Item, View, Group, message
24
25
26 # -------------------------------------------------------------------------
27 # Demo Class
28 # -------------------------------------------------------------------------
29
30
31 class ButtonEditorDemo(HasTraits):
32 """This class specifies the details of the ButtonEditor demo."""
33
34 # To demonstrate any given Trait editor, an appropriate Trait is required.
35 fire_event = Button('Click Me')
36
37 @observe('fire_event')
38 def _button_clicked_message(self, event):
39 message("Button clicked!")
40
41 # ButtonEditor display
42 # (Note that Text and ReadOnly versions are not applicable)
43 event_group = Group(
44 Item('fire_event', style='simple', label='Simple', id="simple"),
45 Item('_'),
46 Item('fire_event', style='custom', label='Custom', id="custom"),
47 Item('_'),
48 Item(label='[text style unavailable]'),
49 Item('_'),
50 Item(label='[readonly style unavailable]'),
51 )
52
53 # Demo view
54 traits_view = View(
55 event_group, title='ButtonEditor', buttons=['OK'], width=250
56 )
57
58
59 # Create the demo:
60 demo = ButtonEditorDemo()
61
62 # Run the demo (if invoked from the command line):
63 if __name__ == '__main__':
64 demo.configure_traits()