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