Merge pull request #2718 from kivy/image_loop

uix:Image introduce `anim_loop` property
This commit is contained in:
Mathieu Virbel 2014-12-05 18:08:21 +01:00
commit f8db0b916d
2 changed files with 18 additions and 1 deletions

View File

@ -492,7 +492,6 @@ class Image(EventDispatcher):
return
textures = self.image.textures
if self._anim_index >= len(textures):
self.anim_reset(False)
self._anim_index = 0
self._texture = self.image.textures[self._anim_index]
self.dispatch('on_texture')

View File

@ -170,6 +170,15 @@ class Image(Widget):
defaults to 0.25 (4 FPS).
'''
anim_loop = NumericProperty(0)
'''Number of loops to play then stop animating. 0 means keep animating.
.. versionadded 1.9.0
:attr:`anim_loop` is a :class:`~kivy.properties.NumericProperty` defaults
to 0.
'''
nocache = BooleanProperty(False)
'''If this property is set True, the image will not be added to the
internal cache. The cache will simply ignore any calls trying to
@ -221,6 +230,7 @@ class Image(Widget):
def __init__(self, **kwargs):
self._coreimage = None
self._loops = 0
super(Image, self).__init__(**kwargs)
self.bind(source=self.texture_update,
mipmap=self.texture_update)
@ -232,6 +242,7 @@ class Image(Widget):
self.texture = None
else:
filename = resource_find(self.source)
self._loops = 0
if filename is None:
return Logger.error('Image: Error reading file {filename}'.
format(filename=self.source))
@ -251,6 +262,7 @@ class Image(Widget):
self.texture = ci.texture
def on_anim_delay(self, instance, value):
self._loop = 0
if self._coreimage is None:
return
self._coreimage.anim_delay = value
@ -264,6 +276,12 @@ class Image(Widget):
def _on_tex_change(self, *largs):
# update texture from core image
self.texture = self._coreimage.texture
ci = self._coreimage
if self.anim_loop and ci._anim_index == len(ci._image.textures) - 1:
self._loops += 1
if self.anim_loop == self._loops:
ci.anim_reset(False)
self._loops = 0
def reload(self):
'''Reload image from disk. This facilitates re-loading of