Debian Codegraph @

traitsui/examples/demo/Standard_Editors/RangeEditor_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 Range editor
13
14 A Range Trait holds a numeric value which is restricted to a specified range.
15
16 This example shows how the RangeEditor's simple and custom styles vary
17 depending on the type (integer or float) and size (small, medium, or large
18 integer) of the specified range.
19
20 The example also shows how multiple Groups at the top level of a View are
21 automatically placed into separate tabs.
22
23 For an example of how to dynamically vary the bounds of a Range trait, see
24 the *Dynamic Range Editor* example.
25
26 Please refer to the `RangeEditor API docs`_ for further information.
27
28 .. _RangeEditor API docs: https://docs.enthought.com/traitsui/api/traitsui.editors.range_editor.html#traitsui.editors.range_editor.RangeEditor
29 """
30
31 from traits.api import HasTraits, Range
32 from traitsui.api import Item, Group, View
33
34
35 class RangeEditorDemo(HasTraits):
36 """Defines the RangeEditor demo class."""
37
38 # Define a trait for each of four range variants:
39 small_int_range = Range(1, 16)
40 medium_int_range = Range(1, 25)
41 large_int_range = Range(1, 150)
42 float_range = Range(0.0, 150.0)
43
44 # RangeEditor display for narrow integer Range traits (< 17 wide):
45 int_range_group1 = Group(
46 Item(
47 'small_int_range',
48 style='simple',
49 label='Simple',
50 id='simple_small',
51 ),
52 Item('_'),
53 Item(
54 'small_int_range',
55 style='custom',
56 label='Custom',
57 id='custom_small',
58 ),
59 Item('_'),
60 Item('small_int_range', style='text', label='Text', id='text_small'),
61 Item('_'),
62 Item(
63 'small_int_range',
64 style='readonly',
65 label='ReadOnly',
66 id='readonly_small',
67 ),
68 label='Small Int',
69 )
70
71 # RangeEditor display for medium-width integer Range traits (17 to 100):
72 int_range_group2 = Group(
73 Item(
74 'medium_int_range',
75 style='simple',
76 label='Simple',
77 id='simple_medium',
78 ),
79 Item('_'),
80 Item(
81 'medium_int_range',
82 style='custom',
83 label='Custom',
84 id='custom_medium',
85 ),
86 Item('_'),
87 Item('medium_int_range', style='text', label='Text', id='text_medium'),
88 Item('_'),
89 Item(
90 'medium_int_range',
91 style='readonly',
92 label='ReadOnly',
93 id='readonly_medium',
94 ),
95 label='Medium Int',
96 )
97
98 # RangeEditor display for wide integer Range traits (> 100):
99 int_range_group3 = Group(
100 Item(
101 'large_int_range',
102 style='simple',
103 label='Simple',
104 id='simple_large',
105 ),
106 Item('_'),
107 Item(
108 'large_int_range',
109 style='custom',
110 label='Custom',
111 id='custom_large',
112 ),
113 Item('_'),
114 Item('large_int_range', style='text', label='Text', id='text_large'),
115 Item('_'),
116 Item(
117 'large_int_range',
118 style='readonly',
119 label='ReadOnly',
120 id='readonly_large',
121 ),
122 label='Large Int',
123 )
124
125 # RangeEditor display for float Range traits:
126 float_range_group = Group(
127 Item('float_range', style='simple', label='Simple', id='simple_float'),
128 Item('_'),
129 Item('float_range', style='custom', label='Custom', id='custom_float'),
130 Item('_'),
131 Item('float_range', style='text', label='Text', id='text_float'),
132 Item('_'),
133 Item(
134 'float_range',
135 style='readonly',
136 label='ReadOnly',
137 id='readonly_float',
138 ),
139 label='Float',
140 )
141
142 # The view includes one group per data type. These will be displayed
143 # on separate tabbed panels:
144 traits_view = View(
145 int_range_group1,
146 int_range_group2,
147 int_range_group3,
148 float_range_group,
149 title='RangeEditor',
150 buttons=['OK'],
151 resizable=True,
152 )
153
154
155 # Create the demo:
156 demo = RangeEditorDemo()
157
158 # Run the demo (if invoked from the comand line):
159 if __name__ == '__main__':
160 demo.configure_traits()