[caribou/introspection: 8/10] animation wip



commit b9ec5c467231f863f85aff82c7d43638b7197ea7
Author: Eitan Isaacson <eitan monotonous org>
Date:   Wed Jan 5 16:26:26 2011 -0800

    animation wip

 caribou/ui/animation.py |   91 +++++++++++++++++++++++++++++++++++++---------
 1 files changed, 73 insertions(+), 18 deletions(-)
---
diff --git a/caribou/ui/animation.py b/caribou/ui/animation.py
index c382929..fb546bc 100644
--- a/caribou/ui/animation.py
+++ b/caribou/ui/animation.py
@@ -27,37 +27,92 @@ class AnimatedWindowBase(object):
                 "AnimatedWindowBase is an abstract class, " \
                 "must be subclassed with a Gtk.Window"
 
-        self._actor = Clutter.Rectangle()
         self.ease = ease
-
-    def _on_new_frame(self, timeline, timing):
-        x, y = self._actor.get_position()
-        self.move(int(x), int(y))
+        self._stage = Clutter.Stage.get_default()
+        self._animation = None
 
     def animated_move(self, x, y):
-        orig_x, orig_y = self.get_position()
-        self._actor.set_position(orig_x, orig_y)
-        #allocation = self.get_allocation()
-        #print allocation.width, allocation.height
-        #self._actor.set_size(self.allocation.width, self.allocation.height)
-        animation = self._actor.animatev(self.ease, 250, ["x", "y"])
-        timeline = animation.get_timeline()
-        timeline.connect('new-frame', self._on_new_frame)
-        
-        return animation
-        
+        self._animation = Clutter.Animation(object=self, mode=self.ease,
+                                            duration=2500)
+        self._animation.bind("window-position", (x, y))
+
+        timeline = self._animation.get_timeline()
+        timeline.start()
+
+        return self._animation
+
 if __name__ == "__main__":
     import gobject
     from gi.repository import Gtk
-    class AnimatedWindow(Gtk.Window, AnimatedWindowBase):
+    import signal
+    signal.signal(signal.SIGINT, signal.SIG_DFL)
+
+    Clutter.init("caribou")
+
+    class AnimatedWindow(Gtk.Window, Clutter.Animatable, AnimatedWindowBase):
+        __gtype_name__ = "AnimatedWindowBase"
+        __gproperties__ = { 
+             'xpos' : (gobject.TYPE_INT, 'X coordinate of window',
+                       'blah', gobject.G_MININT, gobject.G_MAXINT, 0,
+                       gobject.PARAM_READWRITE),
+             'ypos' : (gobject.TYPE_INT, 'Y coordinate of window',
+                       'blah', gobject.G_MININT, gobject.G_MAXINT, 0,
+                       gobject.PARAM_READWRITE),
+             'window-position' : (gobject.TYPE_PYOBJECT, 'Window position',
+                                  'Window position in X, Y coordinates',
+                                  gobject.PARAM_READWRITE)
+                                  
+             }
+        
         def __init__(self):
             gobject.GObject.__init__(self)
             AnimatedWindowBase.__init__(self)
 
+        def do_get_property(self, property):
+            if property.name == "xpos":
+                x, _ = self.get_position()
+                return x
+            elif property.name == "ypos":
+                _, y = self.get_position()
+                return y
+            elif property.name == "window-position":
+                return self.get_position()
+            else:
+                raise AttributeError, 'unknown property %s' % property.name
+
+        def do_set_property(self, property, value):
+            #print 'setting', property.name, value
+            if property.name in ("xpos", "ypos", "window-position"):
+                x, y = self.get_position()
+                if property.name == "xpos":
+                    self.move(value, y)
+                elif property.name == "ypos":
+                    self.move(x, value)
+            elif property.name == "window-position":
+                x, y = value
+                self.move(x, value)
+            else:
+                raise AttributeError, 'unknown property %s' % property.name
+
+        def do_animate_property(self, animation, prop_name, initial_value,
+                                final_value, progress, gvalue):
+            if prop_name != "window-position": return False
+
+            ix, iy = initial_value
+            fx, fy = final_value
+            dx = int((fx - ix) * progress)
+            dy = int((fy - iy) * progress)
+            new_value = (ix + dx, iy + dy)
+            self.move(*new_value)
+
+    def idle_cb(aw):
+        #aw.props.xpos = 500
+        aw.animated_move(200, 200)
+
     aw = AnimatedWindow()
     aw.show_all()
     aw.move(100, 100)
-    #aw.animated_move(200, 200)
+    gobject.timeout_add_seconds(3, idle_cb, aw)
     Gtk.main()
 
 



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