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

« back to all changes in this revision

Viewing changes to examples/demo/Standard_Editors/ImageEnumEditor_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 an ImageEnumEditor demo plugin for the Traits UI demo program.
 
6
 
 
7
This demo shows each of the four styles of the ImageEnumEditor.
 
8
"""
 
9
 
 
10
# Imports:
 
11
from traits.api \
 
12
    import HasTraits, Str, Trait
 
13
 
 
14
from traitsui.api \
 
15
    import Item, Group, View, ImageEnumEditor
 
16
 
 
17
# This list of image names (with the standard suffix "_origin") is used to
 
18
# construct an image enumeration trait to demonstrate the ImageEnumEditor:
 
19
image_list = [ 'top left', 'top right', 'bottom left', 'bottom right' ]
 
20
 
 
21
class Dummy ( HasTraits ):
 
22
    """ Dummy class for ImageEnumEditor
 
23
    """
 
24
    x = Str
 
25
 
 
26
    view = View()
 
27
 
 
28
class ImageEnumEditorDemo ( HasTraits ):
 
29
    """ Defines the ImageEnumEditor demo class.
 
30
    """
 
31
 
 
32
    # Define a trait to view:
 
33
    image_from_list = Trait( editor = ImageEnumEditor( values = image_list,
 
34
                                                       prefix = '@icons:',
 
35
                                                       suffix = '_origin',
 
36
                                                       cols   = 4,
 
37
                                                       klass  = Dummy ),
 
38
                             *image_list )
 
39
 
 
40
    # Items are used to define the demo display, one Item per editor style:
 
41
    img_group = Group(
 
42
        Item( 'image_from_list', style = 'simple',   label = 'Simple' ),
 
43
        Item( '_' ),
 
44
        Item( 'image_from_list', style = 'custom',   label = 'Custom' ),
 
45
        Item( '_' ),
 
46
        Item( 'image_from_list', style = 'text',     label = 'Text' ),
 
47
        Item( '_' ),
 
48
        Item( 'image_from_list', style = 'readonly', label = 'ReadOnly' )
 
49
    )
 
50
 
 
51
    # Demo view:
 
52
    view = View(
 
53
        img_group,
 
54
        title     = 'ImageEnumEditor',
 
55
        buttons   = [ 'OK' ],
 
56
        resizable = True
 
57
    )
 
58
 
 
59
# Create the demo:
 
60
demo = ImageEnumEditorDemo()
 
61
 
 
62
# Run the demo (if invoked from the command line):
 
63
if __name__ == '__main__':
 
64
    demo.configure_traits()
 
65