Debian Codegraph @

traitsui/examples/demo/Standard_Editors/CompoundEditor_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 **WARNING**
13
14 This demo might not work as expected and some documented features might be
15 missing.
16
17 -------------------------------------------------------------------------------
18
19 Implementation of a CompoundEditor demo plugin for Traits UI demo program.
20
21 This demo shows each of the four styles of the CompoundEditor.
22
23 Please refer to the `CompoundEditor API docs`_ for further information.
24
25 .. _CompoundEditor API docs: https://docs.enthought.com/traitsui/api/traitsui.editors.compound_editor.html#traitsui.editors.compound_editor.CompoundEditor
26 """
27 # Issue related to the demo warning: enthought/traitsui#945
28
29
30 from traits.api import Enum, HasTraits, Range, Union
31
32 from traitsui.api import Item, Group, View
33
34
35 # Define the demo class:
36 class CompoundEditorDemo(HasTraits):
37 """Defines the main CompoundEditor demo class."""
38
39 # Define a compound trait to view:
40 compound_trait = Union(
41 Range(1, 6), Enum('a', 'b', 'c', 'd', 'e', 'f'), default_value=1
42 )
43
44 # Display specification (one Item per editor style):
45 comp_group = Group(
46 Item('compound_trait', style='simple', label='Simple'),
47 Item('_'),
48 Item('compound_trait', style='custom', label='Custom'),
49 Item('_'),
50 Item('compound_trait', style='text', label='Text'),
51 Item('_'),
52 Item('compound_trait', style='readonly', label='ReadOnly'),
53 )
54
55 # Demo view:
56 traits_view = View(
57 comp_group, title='CompoundEditor', buttons=['OK'], resizable=True
58 )
59
60
61 # Create the demo:
62 demo = CompoundEditorDemo()
63
64 # Run the demo (if invoked from the command line):
65 if __name__ == '__main__':
66 demo.configure_traits()