[pyclutter/wip/introspection] Allow using the implicit animation api with a contex manager



commit 744b5e0d597db0f5891a4c1e63aa734af19a28ba
Author: Bastian Winkler <buz netbuz org>
Date:   Tue Apr 17 13:22:56 2012 +0200

    Allow using the implicit animation api with a contex manager
    
    A clean way to use the implicit animation api:
    
     >>> with actor.animated(2000, delay=250):
     ...     actor.set_size(200.0, 200.0)

 introspection/Clutter.py |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)
---
diff --git a/introspection/Clutter.py b/introspection/Clutter.py
index f77abe7..328c286 100644
--- a/introspection/Clutter.py
+++ b/introspection/Clutter.py
@@ -24,6 +24,7 @@ import sys
 from ..overrides import override
 from ..importer import modules
 from gi.repository import GObject
+from contextlib import contextmanager
 
 Clutter = modules['Clutter']._introspection_module
 
@@ -641,6 +642,24 @@ class Actor(Clutter.Actor):
         def __iter__(self):
             return iter(self.get_children())
 
+        @contextmanager
+        def animated(self, duration=None, mode=None, delay=None):
+            """
+            Use the implicit animation api
+            >>> my_actor.set_size(100.0, 100.0)
+            >>> with my_actor.animated():
+            ...     my_actor.set_size(200.0, 200.0)
+            """
+            self.save_easing_state()
+            if duration is not None:
+                self.set_easing_duration(duration)
+            if mode is not None:
+                self.set_easing_mode(mode)
+            if delay is not None:
+                self.set_easing_delay(delay)
+            yield
+            self.restore_easing_state()
+
 Actor = override(Actor)
 __all__.append('Actor')
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]