Debian Codegraph @

integrationtests/ui/check_list_editor_test2.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
16 from traits.api import Enum, List, Str
17
18 from traitsui.api import Handler, View, Item, CheckListEditor
19
20 # -------------------------------------------------------------------------
21 # 'CheckListTest' class:
22 # -------------------------------------------------------------------------
23
24
25 class CheckListTest(Handler):
26
27 # -------------------------------------------------------------------------
28 # Trait definitions:
29 # -------------------------------------------------------------------------
30
31 value = List(editor=CheckListEditor(name='values', cols=5))
32 values = List(Str)
33 values_text = Str('red orange yellow green blue indigo violet')
34
35 # -------------------------------------------------------------------------
36 # Traits view definitions:
37 # -------------------------------------------------------------------------
38
39 simple_view = View('value', 'values_text@')
40 custom_view = View('value@', 'values_text@')
41
42 # -------------------------------------------------------------------------
43 # 'Initializes the object:
44 # -------------------------------------------------------------------------
45
46 def __init__(self, **traits):
47 super().__init__(**traits)
48 self._values_text_changed()
49
50 # -------------------------------------------------------------------------
51 # Event handlers:
52 # -------------------------------------------------------------------------
53
54 def _values_text_changed(self):
55 self.values = self.values_text.split()
56
57
58 # -------------------------------------------------------------------------
59 # Run the tests:
60 # -------------------------------------------------------------------------
61
62 if __name__ == '__main__':
63 clt = CheckListTest()
64 clt.configure_traits(view='simple_view')
65 print('value:', clt.value)
66 clt.configure_traits(view='custom_view')
67 print('value:', clt.value)