Debian Codegraph @

integrationtests/ui/test_ui.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 # Imports:
13 # -------------------------------------------------------------------------
14
15 import wx
16
17 from traits.api import (
18 Trait,
19 HasTraits,
20 Str,
21 Int,
22 Range,
23 List,
24 Event,
25 File,
26 Directory,
27 Bool,
28 Enum,
29 )
30
31 from traitsui.api import (
32 View,
33 Handler,
34 Item,
35 CheckListEditor,
36 ButtonEditor,
37 FileEditor,
38 DirectoryEditor,
39 ImageEnumEditor,
40 Color,
41 Font,
42 )
43
44 # -------------------------------------------------------------------------
45 # Constants:
46 # -------------------------------------------------------------------------
47
48 origin_values = ['top left', 'top right', 'bottom left', 'bottom right']
49
50 # -------------------------------------------------------------------------
51 # 'Instance' class:
52 # -------------------------------------------------------------------------
53
54
55 class Instance(HasTraits):
56
57 # -------------------------------------------------------------------------
58 # Trait definitions:
59 # -------------------------------------------------------------------------
60
61 integer_text = Int(1)
62 enumeration = Enum('one', 'two', 'three', 'four', 'five', 'six', cols=3)
63 float_range = Range(0.0, 10.0, 10.0)
64 int_range = Range(1, 5)
65 boolean = Bool(True)
66
67 view = View(
68 'integer_text', 'enumeration', 'float_range', 'int_range', 'boolean'
69 )
70
71
72 # -------------------------------------------------------------------------
73 # 'TraitsTest' class
74 # -------------------------------------------------------------------------
75
76
77 class TraitsTest(HasTraits):
78
79 # -------------------------------------------------------------------------
80 # Trait definitions:
81 # -------------------------------------------------------------------------
82
83 integer_text = Int(1)
84 enumeration = Enum('one', 'two', 'three', 'four', 'five', 'six', cols=3)
85 float_range = Range(0.0, 10.0, 10.0)
86 int_range = Range(1, 6)
87 int_range2 = Range(1, 50)
88 compound = Trait(
89 1, Range(1, 6), 'one', 'two', 'three', 'four', 'five', 'six'
90 )
91 boolean = Bool(True)
92 instance = Trait(Instance())
93 color = Color
94 font = Font
95 check_list = List(
96 editor=CheckListEditor(values=['one', 'two', 'three', 'four'], cols=4)
97 )
98 list = List(
99 Str, ['East of Eden', 'The Grapes of Wrath', 'Of Mice and Men']
100 )
101 button = Event(0, editor=ButtonEditor(label='Click'))
102 file = File()
103 directory = Directory()
104 image_enum = Trait(
105 editor=ImageEnumEditor(
106 values=origin_values, suffix='_origin', cols=4, klass=Instance
107 ),
108 *origin_values,
109 )
110
111 # -------------------------------------------------------------------------
112 # View definitions:
113 # -------------------------------------------------------------------------
114
115 view = View(
116 (
117 '|{Enum}',
118 (
119 '|<[Enumeration]',
120 'enumeration[Simple]',
121 '_',
122 'enumeration[Custom]@',
123 '_',
124 'enumeration[Text]*',
125 '_',
126 'enumeration[Readonly]~',
127 ),
128 (
129 '|<[Check List]',
130 'check_list[Simple]',
131 '_',
132 'check_list[Custom]@',
133 '_',
134 'check_list[Text]*',
135 '_',
136 'check_list[Readonly]~',
137 ),
138 ),
139 (
140 '|{Range}',
141 (
142 '|<[Float Range]',
143 'float_range[Simple]',
144 '_',
145 'float_range[Custom]@',
146 '_',
147 'float_range[Text]*',
148 '_',
149 'float_range[Readonly]~',
150 ),
151 (
152 '|<[Int Range]',
153 'int_range[Simple]',
154 '_',
155 'int_range[Custom]@',
156 '_',
157 'int_range[Text]*',
158 '_',
159 'int_range[Readonly]~',
160 ),
161 (
162 '|<[Int Range 2]',
163 'int_range2[Simple]',
164 '_',
165 'int_range2[Custom]@',
166 '_',
167 'int_range2[Text]*',
168 '_',
169 'int_range2[Readonly]~',
170 ),
171 ),
172 (
173 '|{Misc}',
174 (
175 '|<[Integer Text]',
176 'integer_text[Simple]',
177 '_',
178 'integer_text[Custom]@',
179 '_',
180 'integer_text[Text]*',
181 '_',
182 'integer_text[Readonly]~',
183 ),
184 (
185 '|<[Compound]',
186 'compound[Simple]',
187 '_',
188 'compound[Custom]@',
189 '_',
190 'compound[Text]*',
191 '_',
192 'compound[Readonly]~',
193 ),
194 (
195 '|<[Boolean]',
196 'boolean[Simple]',
197 '_',
198 'boolean[Custom]@',
199 '_',
200 'boolean[Text]*',
201 '_',
202 'boolean[Readonly]~',
203 ),
204 ),
205 (
206 '|{Color/Font}',
207 (
208 '|<[Color]',
209 'color[Simple]',
210 '_',
211 'color[Custom]@',
212 '_',
213 'color[Text]*',
214 '_',
215 'color[Readonly]~',
216 ),
217 (
218 '|<[Font]',
219 'font[Simple]',
220 '_',
221 'font[Custom]@',
222 '_',
223 'font[Text]*',
224 '_',
225 'font[Readonly]~',
226 ),
227 ),
228 (
229 '|{List}',
230 (
231 '|<[List]',
232 'list[Simple]',
233 '_',
234 'list[Custom]@',
235 '_',
236 'list[Text]*',
237 '_',
238 'list[Readonly]~',
239 ),
240 ),
241 (
242 '|{Button}',
243 ('|<[Button]', 'button[Simple]', '_', 'button[Custom]@'),
244 # 'button[Text]*',
245 # 'button[Readonly]~' ),
246 (
247 '|<[Image Enum]',
248 'image_enum[Simple]',
249 '_',
250 'image_enum[Custom]@',
251 '_',
252 'image_enum[Text]*',
253 '_',
254 'image_enum[Readonly]~',
255 ),
256 (
257 '|<[Instance]',
258 'instance[Simple]',
259 '_',
260 'instance[Custom]@',
261 '_',
262 'instance[Text]*',
263 '_',
264 'instance[Readonly]~',
265 ),
266 ),
267 (
268 '|{File}',
269 (
270 '|<[File]',
271 'file[Simple]',
272 '_',
273 'file[Custom]@',
274 '_',
275 'file[Text]*',
276 '_',
277 'file[Readonly]~',
278 ),
279 (
280 '|<[Directory]',
281 'directory[Simple]',
282 '_',
283 'directory[Custom]@',
284 '_',
285 'directory[Text]*',
286 '_',
287 'directory[Readonly]~',
288 ),
289 ),
290 buttons=['Apply', 'Revert', 'Undo', 'OK'],
291 )
292
293
294 # -------------------------------------------------------------------------
295 # 'TraitSheetApp' class:
296 # -------------------------------------------------------------------------
297
298
299 class TraitSheetApp(wx.App):
300
301 # -------------------------------------------------------------------------
302 # Initialize the object:
303 # -------------------------------------------------------------------------
304
305 def __init__(self, object):
306 self.object = object
307 wx.InitAllImageHandlers()
308 wx.App.__init__(self, 1, 'debug.log')
309 self.MainLoop()
310
311 # -------------------------------------------------------------------------
312 # Handle application initialization:
313 # -------------------------------------------------------------------------
314
315 def OnInit(self):
316 ui = self.object.edit_traits(kind='modal')
317 ui = self.object.edit_traits(kind='wizard')
318 ui = self.object.edit_traits(kind='nonmodal')
319 ui = self.object.edit_traits(kind='live')
320 self.SetTopWindow(ui.control)
321 return True
322
323
324 # -------------------------------------------------------------------------
325 # Main program:
326 # -------------------------------------------------------------------------
327
328 if __name__ == '__main__':
329 TraitSheetApp(TraitsTest())