Completed animated GIFs. Support for time_between_frames
This commit is contained in:
parent
607bccac64
commit
dac1dbd084
|
@ -1846,6 +1846,7 @@ class Image(Element):
|
|||
self.AnimatedFrames = None
|
||||
self.CurrentFrameNumber = 0
|
||||
self.TotalAnimatedFrames = 0
|
||||
self.LastFrameTime = 0
|
||||
|
||||
super().__init__(ELEM_TYPE_IMAGE, size=size, background_color=background_color, pad=pad, key=key,
|
||||
tooltip=tooltip, visible=visible)
|
||||
|
@ -1870,7 +1871,7 @@ class Image(Element):
|
|||
elif visible is True:
|
||||
self.tktext_label.pack()
|
||||
|
||||
def UpdateAnimation(self, source, size=(None, None)):
|
||||
def UpdateAnimation(self, source, size=(None, None), time_between_frames=0):
|
||||
if self.AnimatedFrames is None:
|
||||
self.AnimatedFrames = []
|
||||
for i in range(1000):
|
||||
|
@ -1887,8 +1888,20 @@ class Image(Element):
|
|||
if size != (None, None):
|
||||
self.AnimatedFrames[i].configure
|
||||
self.TotalAnimatedFrames += 1
|
||||
self.LastFrameTime = time.time()
|
||||
# show the frame
|
||||
self.CurrentFrameNumber = self.CurrentFrameNumber + 1 if self.CurrentFrameNumber+1< self.TotalAnimatedFrames else 0
|
||||
|
||||
now = time.time()
|
||||
|
||||
if time_between_frames:
|
||||
if (now - self.LastFrameTime) * 1000 > time_between_frames:
|
||||
self.LastFrameTime = now
|
||||
self.CurrentFrameNumber = self.CurrentFrameNumber + 1 if self.CurrentFrameNumber+1< self.TotalAnimatedFrames else 0
|
||||
else: # don't reshow the frame again if not time for new frame
|
||||
return
|
||||
else:
|
||||
self.CurrentFrameNumber = self.CurrentFrameNumber + 1 if self.CurrentFrameNumber+1< self.TotalAnimatedFrames else 0
|
||||
|
||||
self.tktext_label.configure(image=self.AnimatedFrames[self.CurrentFrameNumber])
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue