| 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 |
This demo shows you how to use animated GIF files in a traits user interface. |
| 13 |
Note that this demo only works with wx backend. |
| 14 |
""" |
| 15 |
|
| 16 |
from os.path import join, dirname, abspath |
| 17 |
|
| 18 |
from traits.api import HasTraits, File, Bool |
| 19 |
|
| 20 |
from traitsui.api import View, VGroup, HGroup, Item, EnumEditor |
| 21 |
|
| 22 |
from traitsui.wx.animated_gif_editor import AnimatedGIFEditor |
| 23 |
|
| 24 |
|
| 25 |
# Some sample animated GIF files: |
| 26 |
base_path = join(dirname(__file__), 'images') |
| 27 |
|
| 28 |
files = [ |
| 29 |
abspath(join(base_path, 'logo_64x64.gif')), |
| 30 |
abspath(join(base_path, 'logo_48x48.gif')), |
| 31 |
abspath(join(base_path, 'logo_32x32.gif')), |
| 32 |
] |
| 33 |
|
| 34 |
|
| 35 |
class AnimatedGIFDemo(HasTraits): |
| 36 |
|
| 37 |
# The animated GIF file to display: |
| 38 |
gif_file = File(files[0]) |
| 39 |
|
| 40 |
# Is the animation playing or not? |
| 41 |
playing = Bool(True) |
| 42 |
|
| 43 |
# The traits view: |
| 44 |
view = View( |
| 45 |
VGroup( |
| 46 |
HGroup( |
| 47 |
Item( |
| 48 |
'gif_file', |
| 49 |
editor=AnimatedGIFEditor(playing='playing'), |
| 50 |
show_label=False, |
| 51 |
), |
| 52 |
Item('playing'), |
| 53 |
), |
| 54 |
'_', |
| 55 |
Item( |
| 56 |
'gif_file', label='GIF File', editor=EnumEditor(values=files) |
| 57 |
), |
| 58 |
), |
| 59 |
title='Animated GIF Demo', |
| 60 |
buttons=['OK'], |
| 61 |
) |
| 62 |
|
| 63 |
|
| 64 |
# Create the demo: |
| 65 |
demo = AnimatedGIFDemo() |
| 66 |
|
| 67 |
# Run the demo (if invoked from the command line): |
| 68 |
if __name__ == '__main__': |
| 69 |
demo.configure_traits() |