File: SetEditor_demo.py

package info (click to toggle)
python-traitsui 4.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 13,292 kB
  • sloc: python: 39,867; makefile: 120; sh: 5
file content (90 lines) | stat: -rw-r--r-- 3,378 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
"""
Implementation of a SetEditor demo plugin for the Traits UI demo program.

The four tabs of this demo show variations on the interface as follows:

   Unord I:  Creates an alphabetized subset, has no "move all" options
   Unord II: Creates an alphabetized subset, has "move all" options
   Ord I:    Creates a set whose order is specified by the user, no "move all"
   Ord II:   Creates a set whose order is specifed by the user, has "move all"
"""

from traits.api import HasTraits, List
from traitsui.api import Item, Group, View, SetEditor

#-------------------------------------------------------------------------------
#  Demo Class
#-------------------------------------------------------------------------------

class SetEditorDemo ( HasTraits ):
    """ This class specifies the details of the SetEditor demo.
    """

    # Define a trait each for four variants
    unord_nma_set = List( editor = SetEditor(
                              values = [ 'kumquats', 'pomegranates', 'kiwi' ],
                              can_move_all = False,
                              left_column_title  = 'Available Fruit',
                              right_column_title = 'Exotic Fruit Bowl' ) )

    unord_ma_set = List( editor = SetEditor(
                              values = [ 'kumquats', 'pomegranates', 'kiwi' ],
                              left_column_title  = 'Available Fruit',
                              right_column_title = 'Exotic Fruit Bowl' ) )

    ord_nma_set = List( editor = SetEditor(
                            values  = ['apples', 'berries', 'cantaloupe' ],
                            ordered = True,
                            can_move_all = False,
                            left_column_title  = 'Available Fruit',
                            right_column_title = 'Fruit Bowl' ) )

    ord_ma_set = List( editor = SetEditor(
                       values  = ['apples', 'berries', 'cantaloupe' ],
                       ordered = True,
                       left_column_title  = 'Available Fruit',
                       right_column_title = 'Fruit Bowl' ) )


    # SetEditor display, unordered, no move-all buttons.
    no_nma_group = Group( Item('unord_nma_set', style='simple'),
                          label='Unord I',
                          show_labels=False)


    # SetEditor display, unordered, move-all buttons.
    no_ma_group = Group( Item('unord_ma_set', style='simple'),
                         label='Unord II',
                         show_labels=False)


    # SetEditor display, ordered, no move-all buttons.
    o_nma_group = Group( Item('ord_nma_set', style='simple'),
                         label='Ord I',
                         show_labels=False)


    # SetEditor display, ordered, move-all buttons.
    o_ma_group = Group( Item('ord_ma_set', style='simple'),
                        label='Ord II',
                        show_labels=False)



    # The view includes one group per data type.  These will be displayed
    # on separate tabbed panels.
    view1 = View( no_nma_group,
                  no_ma_group,
                  o_nma_group,
                  o_ma_group,
                  title = 'SetEditor',
                  buttons = ['OK'])


# Create the demo:
popup =  SetEditorDemo()

# Run the demo (if invoked from the command line):
if __name__ == '__main__':
    popup.configure_traits()