~ubuntu-branches/ubuntu/utopic/python-traitsui/utopic

« back to all changes in this revision

Viewing changes to examples/demo/Standard_Editors/CheckListEditor_demo.py

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath
  • Date: 2011-07-09 13:57:39 UTC
  • Revision ID: james.westby@ubuntu.com-20110709135739-x5u20q86huissmn1
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#  Copyright (c) 2007, Enthought, Inc.
 
2
#  License: BSD Style.
 
3
 
 
4
"""
 
5
Implementation of a CheckListEditor demo plugin for the Traits UI demo program.
 
6
 
 
7
For each of three CheckListEditor column formations, this demo shows
 
8
each of the four styles of the CheckListEditor.
 
9
"""
 
10
 
 
11
# Imports:
 
12
from traits.api \
 
13
    import HasTraits, List
 
14
 
 
15
from traitsui.api \
 
16
    import Item, Group, View, CheckListEditor
 
17
 
 
18
# Define the demo class:
 
19
class CheckListEditorDemo ( HasTraits ):
 
20
    """ Define the main CheckListEditor demo class. """
 
21
 
 
22
    # Define a trait for each of three formations:
 
23
    checklist_4col = List( editor = CheckListEditor(
 
24
                           values = [ 'one', 'two', 'three', 'four' ],
 
25
                           cols   = 4 ) )
 
26
 
 
27
    checklist_2col = List( editor = CheckListEditor(
 
28
                           values = [ 'one', 'two', 'three', 'four' ],
 
29
                           cols   = 2 ) )
 
30
 
 
31
    checklist_1col = List( editor = CheckListEditor(
 
32
                           values = [ 'one', 'two', 'three', 'four' ],
 
33
                           cols   = 1 ) )
 
34
 
 
35
    # CheckListEditor display with four columns:
 
36
    cl_4_group = Group(
 
37
        Item( 'checklist_4col', style = 'simple',   label = 'Simple' ),
 
38
        Item( '_' ),
 
39
        Item( 'checklist_4col', style = 'custom',   label = 'Custom' ),
 
40
        Item( '_' ),
 
41
        Item( 'checklist_4col', style = 'text',     label = 'Text' ),
 
42
        Item( '_' ),
 
43
        Item( 'checklist_4col', style = 'readonly', label = 'ReadOnly' ),
 
44
        label = '4-column'
 
45
    )
 
46
 
 
47
    # CheckListEditor display with two columns:
 
48
    cl_2_group = Group(
 
49
        Item( 'checklist_2col', style = 'simple',   label = 'Simple' ),
 
50
        Item( '_' ),
 
51
        Item( 'checklist_2col', style = 'custom',   label = 'Custom' ),
 
52
        Item( '_' ),
 
53
        Item( 'checklist_2col', style = 'text',     label = 'Text' ),
 
54
        Item( '_' ),
 
55
        Item( 'checklist_2col', style = 'readonly', label = 'ReadOnly' ),
 
56
        label = '2-column'
 
57
    )
 
58
 
 
59
    # CheckListEditor display with one column:
 
60
    cl_1_group = Group(
 
61
        Item( 'checklist_1col', style = 'simple',   label = 'Simple' ),
 
62
        Item( '_' ),
 
63
        Item( 'checklist_1col', style = 'custom',   label = 'Custom' ),
 
64
        Item( '_' ),
 
65
        Item( 'checklist_1col', style = 'text',     label = 'Text' ),
 
66
        Item( '_' ),
 
67
        Item( 'checklist_1col', style = 'readonly', label = 'ReadOnly' ),
 
68
        label = '1-column'
 
69
    )
 
70
 
 
71
    # The view includes one group per column formation.  These will be displayed
 
72
    # on separate tabbed panels.
 
73
    view1 = View(
 
74
        cl_4_group,
 
75
        cl_2_group,
 
76
        cl_1_group,
 
77
        title     = 'CheckListEditor',
 
78
        buttons   = [ 'OK' ],
 
79
        resizable = True
 
80
    )
 
81
 
 
82
# Create the demo:
 
83
demo = CheckListEditorDemo()
 
84
 
 
85
# Run the demo (if invoked from the command line):
 
86
if __name__ == '__main__':
 
87
    demo.configure_traits()
 
88