Debian Codegraph @

traitsui/examples/demo/Advanced/ListStrEditor_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 Edit a List of Strings
13
14 Simple demonstration of the ListStrEditor, which can be used for editing and
15 displaying lists of strings, or other data that can be logically mapped to a
16 list of strings.
17 """
18
19 from traits.api import HasTraits, List, Str
20 from traitsui.api import View, Item, ListStrEditor
21
22 # -- ShoppingListDemo Class -----------------------------------------------
23
24
25 class ShoppingListDemo(HasTraits):
26
27 # The list of things to buy at the store:
28 shopping_list = List(Str)
29
30 # -- Traits View Definitions ----------------------------------------------
31
32 view = View(
33 Item(
34 'shopping_list',
35 show_label=False,
36 editor=ListStrEditor(title='Shopping List', auto_add=True),
37 ),
38 title='Shopping List',
39 width=0.2,
40 height=0.5,
41 resizable=True,
42 )
43
44
45 # -- Set up the Demo ------------------------------------------------------
46
47 demo = ShoppingListDemo(
48 shopping_list=[
49 'Carrots',
50 'Potatoes (5 lb. bag)',
51 'Cocoa Puffs',
52 'Ice Cream (French Vanilla)',
53 'Peanut Butter',
54 'Whole wheat bread',
55 'Ground beef (2 lbs.)',
56 'Paper towels',
57 'Soup (3 cans)',
58 'Laundry detergent',
59 ]
60 )
61
62 # Run the demo (in invoked from the command line):
63 if __name__ == '__main__':
64 demo.configure_traits()