forked from wxWidgets/Phoenix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnimationCtrl.py
104 lines (82 loc) · 3.44 KB
/
AnimationCtrl.py
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
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env python
import wx
from wx.adv import Animation
UseNative = True
if UseNative:
# Use the native classes, if the platform has a native widget. It will fall
# back to the generic version if there isn't a native one available.
from wx.adv import AnimationCtrl
else:
# Or we can force use of the generic widget on all platforms
from wx.adv import GenericAnimationCtrl as AnimationCtrl
from Main import opj
GIFNames = [
'bitmaps/AG00178_.gif',
'bitmaps/BD13656_.gif',
'bitmaps/AG00185_.gif',
'bitmaps/AG00039_.gif',
'bitmaps/AG00183_.gif',
'bitmaps/AG00028_.gif',
]
#----------------------------------------------------------------------
class TestPanel(wx.Panel):
def __init__(self, parent, log):
self.log = log
wx.Panel.__init__(self, parent, -1)
sizer = wx.FlexGridSizer(cols=3, hgap=5, vgap=5)
for name in GIFNames:
# There are a few usage patterns for creating the control and the
# animation object. They're more-or-less equivalent, but if you have
# non-standard needs in your application then one pattern may make
# more sense for you to use.
if False:
# If you need a separate animation object then you can have the
# control create one for you.
ctrl = AnimationCtrl(self)
ani = ctrl.CreateAnimation()
ani.LoadFile(opj(name))
ctrl.SetAnimation(ani)
elif False:
# if you need to have the animation object before the control is
# created, then you can do it like this:
ani = AnimationCtrl.CreateCompatibleAnimation()
ani.LoadFile(opj(name))
ctrl = AnimationCtrl(self, -1, ani)
else:
# Or you can keep it simple and just have the control make and
# use its own animation object internally.
ctrl = AnimationCtrl(self)
ctrl.LoadFile(opj(name))
ctrl.SetBackgroundColour(self.GetBackgroundColour())
ctrl.Play()
sizer.Add(ctrl, 0, wx.ALL, 10)
if UseNative and 'wxGTK' in wx.PlatformInfo:
# See comment in updateBestSizes below
wx.CallAfter(self.updateBestSizes)
border = wx.BoxSizer()
border.Add(sizer, 1, wx.EXPAND | wx.ALL, 20)
self.SetSizer(border)
def updateBestSizes(self):
# The native control on GTK is not able to set the BestSize of the
# animation widget until after it has finished loading the animation
# images. So here we will invalidate the initial best size, so it will
# be recalculated on the next layout of the sizer.
for child in self.GetChildren():
if isinstance(child, AnimationCtrl):
child.InvalidateBestSize()
self.Layout()
#----------------------------------------------------------------------
def runTest(frame, nb, log):
win = TestPanel(nb, log)
return win
#----------------------------------------------------------------------
overview = """<html><body>
<h2><center>wx.adv.AnimationCtrl</center></h2>
wx.adv.AnimationCtrl is like a wx.StaticBitmap but is able to
display an animation by extracting frames from a multi-image GIF file.
</body></html>
"""
if __name__ == '__main__':
import sys,os
import run
run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])