Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/examples/scene/scene.py
blob: 733b2b43c9b5bd101c988de20f6d375eaae2b2fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/python
import math

import pygtk
pygtk.require('2.0')
import gtk

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):
	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')
stage.add(PixbufActor(pixbuf))

icons_group = Group()

i = 1
while i <= 5:
	pixbuf = gtk.gdk.pixbuf_new_from_file('activity%d.png' % i)
	icons_group.add(PixbufActor(pixbuf))
	i += 1

layout = CircleLayout(100)
icons_group.set_layout(layout)

stage.add(icons_group)

window = gtk.Window()
window.set_default_size(640, 480)

drawing_area = gtk.DrawingArea()
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()