1#-------------------------------------------------------------------------
2#
3#  TableEditor test case for Traits UI
4#
5#  Written by: David C. Morrill
6#
7#  Date: 07/05/2005
8#
9#  (c) Copyright 2005 by Enthought, Inc.
10#  License: BSD Style.
11#
12#-------------------------------------------------------------------------
13
14#-------------------------------------------------------------------------
15#  Imports:
16#-------------------------------------------------------------------------
17
18from traits.api \
19    import HasTraits, List
20
21from traitsui.api \
22    import View, Item, TableEditor
23
24from traitsui.color_column \
25    import ColorColumn
26
27from enable.api \
28    import ColorTrait
29
30
31class Thingy(HasTraits):
32    color = ColorTrait('black')
33
34#-------------------------------------------------------------------------
35#  Sample data:
36#-------------------------------------------------------------------------
37
38colors = [
39    Thingy(color='red'),
40    Thingy(color='orange'),
41    Thingy(color='yellow'),
42    Thingy(color='green'),
43    Thingy(color='blue'),
44    Thingy(color='indigo'),
45    Thingy(color='violet'),
46    Thingy(color='black'),
47    Thingy(color='white'),
48]
49
50
51class TableTest(HasTraits):
52
53    #-------------------------------------------------------------------------
54    #  Trait definitions:
55    #-------------------------------------------------------------------------
56
57    colors = List(Thingy)
58
59    table_editor = TableEditor(
60        columns=[ColorColumn(name='color'),
61                 ],
62
63        editable=True,
64        deletable=True,
65        sortable=True,        #
66        sort_model=True,
67        show_lines=True,        #
68        orientation='vertical',
69        show_column_labels=True,        #
70        row_factory=Thingy
71    )
72
73    traits_view = View(
74        [Item('colors',
75              id='colors',
76              editor=table_editor),
77         '|[]<>'],
78        title='Table Editor Test',
79        id='traitsui.tests.table_editor_color_test',
80        dock='horizontal',
81        width=.4,
82        height=.3,
83        resizable=True,
84        kind='live')
85
86#-------------------------------------------------------------------------
87#  Run the tests:
88#-------------------------------------------------------------------------
89
90if __name__ == '__main__':
91    tt = TableTest(colors=colors)
92    tt.configure_traits()
93