Implement basic animation

This commit is contained in:
Marco Pesenti Gritti
2006-07-22 13:48:47 +02:00
parent a292b642e1
commit 1e3af85c40
5 changed files with 79 additions and 13 deletions
+23 -3
View File
@@ -1,4 +1,5 @@
#!/usr/bin/python
import math
import pygtk
pygtk.require('2.0')
@@ -8,10 +9,24 @@ from sugar.scene.Stage import Stage
from sugar.scene.Group import Group
from sugar.scene.PixbufActor import PixbufActor
from sugar.scene.CircleLayout import CircleLayout
from sugar.scene.Timeline import Timeline
def drawing_area_expose_cb(widget, event, stage):
def __drawing_area_expose_cb(widget, event, stage):
stage.render(widget.window)
def __next_frame_cb(timeline, frame_num, group):
angle = math.pi * 2 / timeline.get_n_frames() * frame_num
group.get_layout().set_angle(angle)
group.do_layout()
drawing_area.window.invalidate_rect(None, False)
def __completed_cb(timeline, group):
group.get_layout().set_angle(0)
group.do_layout()
drawing_area.window.invalidate_rect(None, False)
stage = Stage()
pixbuf = gtk.gdk.pixbuf_new_from_file('background.png')
@@ -26,7 +41,7 @@ while i <= 5:
i += 1
layout = CircleLayout(100)
icons_group.set_layout_manager(layout)
icons_group.set_layout(layout)
stage.add(icons_group)
@@ -34,10 +49,15 @@ window = gtk.Window()
window.set_default_size(640, 480)
drawing_area = gtk.DrawingArea()
drawing_area.connect('expose_event', drawing_area_expose_cb, stage)
drawing_area.connect('expose_event', __drawing_area_expose_cb, stage)
window.add(drawing_area)
drawing_area.show()
window.show()
timeline = Timeline(stage, 100)
timeline.connect('next-frame', __next_frame_cb, icons_group)
timeline.connect('completed', __completed_cb, icons_group)
timeline.start()
gtk.main()