diff --git a/kivy/core/image/__init__.py b/kivy/core/image/__init__.py index 6e4a21fd0..c2d473b04 100644 --- a/kivy/core/image/__init__.py +++ b/kivy/core/image/__init__.py @@ -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') diff --git a/kivy/uix/image.py b/kivy/uix/image.py index 8cbc88bb4..b0a35b0b5 100644 --- a/kivy/uix/image.py +++ b/kivy/uix/image.py @@ -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