1# Copyright (c) 2007, Enthought, Inc. 2# License: BSD Style. 3 4""" 5**WARNING** 6 7 This demo might not work as expected and some documented features might be 8 missing. 9 10------------------------------------------------------------------------------- 11 12Implementation of an ImageEnumEditor demo plugin for the Traits UI demo 13program. 14 15This demo shows each of the four styles of the ImageEnumEditor. 16""" 17# Issues related to the demo warning: 18# enthought/traitsui#947 19 20 21from traits.api import Enum, HasTraits, Str 22 23from traitsui.api import Item, Group, View, ImageEnumEditor 24 25# This list of image names (with the standard suffix "_origin") is used to 26# construct an image enumeration trait to demonstrate the ImageEnumEditor: 27image_list = ['top left', 'top right', 'bottom left', 'bottom right'] 28 29 30class Dummy(HasTraits): 31 """ Dummy class for ImageEnumEditor 32 """ 33 x = Str() 34 35 traits_view = View() 36 37 38class ImageEnumEditorDemo(HasTraits): 39 """ Defines the ImageEnumEditor demo class. 40 """ 41 42 # Define a trait to view: 43 image_from_list = Enum( 44 *image_list, 45 editor=ImageEnumEditor( 46 values=image_list, 47 prefix='@icons:', 48 suffix='_origin', 49 cols=4, 50 klass=Dummy 51 ) 52 ) 53 54 # Items are used to define the demo display, one Item per editor style: 55 img_group = Group( 56 Item('image_from_list', style='simple', label='Simple'), 57 Item('_'), 58 Item('image_from_list', style='text', label='Text'), 59 Item('_'), 60 Item('image_from_list', style='readonly', label='ReadOnly'), 61 Item('_'), 62 Item('image_from_list', style='custom', label='Custom') 63 ) 64 65 # Demo view: 66 traits_view = View( 67 img_group, 68 title='ImageEnumEditor', 69 buttons=['OK'], 70 resizable=True 71 ) 72 73 74# Create the demo: 75demo = ImageEnumEditorDemo() 76 77# Run the demo (if invoked from the command line): 78if __name__ == '__main__': 79 demo.configure_traits() 80