From ab7767b943efc1800da4f5a3d09315356bdb357b Mon Sep 17 00:00:00 2001 From: akshayaurora Date: Wed, 3 Dec 2014 01:28:18 +0530 Subject: [PATCH 1/2] uix:Image introduce `anim_loop` property --- kivy/core/image/__init__.py | 1 - kivy/uix/image.py | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) 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..36bfb67ff 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) + '''No 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 From 6dbaf558579e9d0656a637fee2d0318222560bf5 Mon Sep 17 00:00:00 2001 From: Akshay Arora Date: Thu, 4 Dec 2014 00:39:25 +0530 Subject: [PATCH 2/2] Update image.py --- kivy/uix/image.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kivy/uix/image.py b/kivy/uix/image.py index 36bfb67ff..b0a35b0b5 100644 --- a/kivy/uix/image.py +++ b/kivy/uix/image.py @@ -171,7 +171,7 @@ class Image(Widget): ''' anim_loop = NumericProperty(0) - '''No of loops to play then stop animating. 0 means keep animating. + '''Number of loops to play then stop animating. 0 means keep animating. .. versionadded 1.9.0