From c54be9ae8d8dc61487634580bbe39d626a8c097f Mon Sep 17 00:00:00 2001 From: Thomas Hansen Date: Fri, 10 Aug 2012 12:01:59 -0500 Subject: [PATCH] animation.py: add cancel_property and cancel_all methods. works just like stop, but will cancel, instead of stop (so no on_complete event fired) --- kivy/animation.py | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/kivy/animation.py b/kivy/animation.py index 4270d0ab3..cc8c31a57 100644 --- a/kivy/animation.py +++ b/kivy/animation.py @@ -152,6 +152,27 @@ class Animation(EventDispatcher): for animation in set(Animation._instances): animation.stop(widget) + @staticmethod + def cancel_all(widget, *largs): + '''Stop all animations that concern a specific widget / list of + properties. + + Example:: + + anim = Animation(x=50) + anim.start(widget) + + # and later + Animation.stop_all(widget, 'x') + ''' + if len(largs): + for animation in list(Animation._instances): + for x in largs: + animation.cancel_property(widget, x) + else: + for animation in set(Animation._instances): + animation.cancel(widget) + def start(self, widget): '''Start the animation on a widget ''' @@ -180,7 +201,22 @@ class Animation(EventDispatcher): def stop_property(self, widget, prop): '''Even if an animation is running, remove a property. It will not be - animated further. + animated further. If it was the only/last property being animated on. + the widget, the animation will be stopped (see :data:`stop`) + ''' + props = self._widgets.get(widget, None) + if not props: + return + props['properties'].pop(prop, None) + + # no more properties to animation ? kill the animation. + if not props['properties']: + self.stop(widget) + + def cancel_property(self, widget, prop): + '''Even if an animation is running, remove a property. It will not be + animated further. If it was the only/last property being animated on. + the widget, the animation will be canceled (see :data:`cancel`) ''' props = self._widgets.get(widget, None) if not props: