Debian Codegraph @

traitsui/examples/demo/Standard_Editors/SetEditor_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 SetEditor demo plugin for the Traits UI demo program.
13
14 The four tabs of this demo show variations on the interface as follows:
15
16 - Unord I: Creates an alphabetized subset, has no "move all" options
17 - Unord II: Creates an alphabetized subset, has "move all" options
18 - Ord I: Creates a set whose order is specified by the user, no "move all"
19 - Ord II: Creates a set whose order is specifed by the user, has "move all"
20
21 Please refer to the `SetEditor API docs`_ for further information.
22
23 .. _SetEditor API docs: https://docs.enthought.com/traitsui/api/traitsui.editors.set_editor.html#traitsui.editors.set_editor.SetEditor
24 """
25
26 from traits.api import HasTraits, List
27
28 from traitsui.api import Item, Group, View, SetEditor
29
30
31 # Define the main demo class:
32 class SetEditorDemo(HasTraits):
33 """Defines the SetEditor demo class."""
34
35 # Define a trait each for four SetEditor variants:
36 unord_nma_set = List(
37 editor=SetEditor(
38 values=['kumquats', 'pomegranates', 'kiwi'],
39 left_column_title='Available Fruit',
40 right_column_title='Exotic Fruit Bowl',
41 can_move_all=False,
42 )
43 )
44
45 unord_ma_set = List(
46 editor=SetEditor(
47 values=['kumquats', 'pomegranates', 'kiwi'],
48 left_column_title='Available Fruit',
49 right_column_title='Exotic Fruit Bowl',
50 )
51 )
52
53 ord_nma_set = List(
54 editor=SetEditor(
55 values=['apples', 'berries', 'cantaloupe'],
56 left_column_title='Available Fruit',
57 right_column_title='Fruit Bowl',
58 ordered=True,
59 can_move_all=False,
60 )
61 )
62
63 ord_ma_set = List(
64 editor=SetEditor(
65 values=['apples', 'berries', 'cantaloupe'],
66 left_column_title='Available Fruit',
67 right_column_title='Fruit Bowl',
68 ordered=True,
69 )
70 )
71
72 # SetEditor display, unordered, no move-all buttons:
73 no_nma_group = Group(
74 Item('unord_nma_set', style='simple'),
75 label='Unord I',
76 show_labels=False,
77 )
78
79 # SetEditor display, unordered, move-all buttons:
80 no_ma_group = Group(
81 Item('unord_ma_set', style='simple'),
82 label='Unord II',
83 show_labels=False,
84 )
85
86 # SetEditor display, ordered, no move-all buttons:
87 o_nma_group = Group(
88 Item('ord_nma_set', style='simple'), label='Ord I', show_labels=False
89 )
90
91 # SetEditor display, ordered, move-all buttons:
92 o_ma_group = Group(
93 Item('ord_ma_set', style='simple'), label='Ord II', show_labels=False
94 )
95
96 # The view includes one group per data type. These will be displayed
97 # on separate tabbed panels:
98 traits_view = View(
99 no_nma_group,
100 no_ma_group,
101 o_nma_group,
102 o_ma_group,
103 title='SetEditor',
104 buttons=['OK'],
105 )
106
107
108 # Create the demo:
109 demo = SetEditorDemo()
110
111 # Run the demo (if invoked from the command line):
112 if __name__ == '__main__':
113 demo.configure_traits()