Implement a stage view

This commit is contained in:
Marco Pesenti Gritti 2006-07-24 12:15:52 +02:00
parent 5cec8f9734
commit e4a87bea06
3 changed files with 33 additions and 11 deletions

View File

@ -7,26 +7,20 @@ import gtk
from sugar.scene.Stage import Stage from sugar.scene.Stage import Stage
from sugar.scene.Group import Group from sugar.scene.Group import Group
from sugar.scene.View import View
from sugar.scene.PixbufActor import PixbufActor from sugar.scene.PixbufActor import PixbufActor
from sugar.scene.CircleLayout import CircleLayout from sugar.scene.CircleLayout import CircleLayout
from sugar.scene.Timeline import Timeline 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): def __next_frame_cb(timeline, frame_num, group):
angle = math.pi * 2 * frame_num / timeline.get_n_frames() angle = math.pi * 2 * frame_num / timeline.get_n_frames()
group.get_layout().set_angle(angle) group.get_layout().set_angle(angle)
group.do_layout() group.do_layout()
drawing_area.window.invalidate_rect(None, False)
def __completed_cb(timeline, group): def __completed_cb(timeline, group):
group.get_layout().set_angle(0) group.get_layout().set_angle(0)
group.do_layout() group.do_layout()
drawing_area.window.invalidate_rect(None, False)
stage = Stage() stage = Stage()
pixbuf = gtk.gdk.pixbuf_new_from_file('background.png') pixbuf = gtk.gdk.pixbuf_new_from_file('background.png')
@ -49,10 +43,9 @@ stage.add(icons_group)
window = gtk.Window() window = gtk.Window()
window.set_default_size(640, 480) window.set_default_size(640, 480)
drawing_area = gtk.DrawingArea() view = View(stage)
drawing_area.connect('expose_event', __drawing_area_expose_cb, stage) window.add(view)
window.add(drawing_area) view.show()
drawing_area.show()
window.show() window.show()

View File

@ -20,6 +20,7 @@ class Actor(gobject.GObject):
def set_position(self, x, y): def set_position(self, x, y):
self._x = x self._x = x
self._y = y self._y = y
self.notify_changed()
def _get_parents(self): def _get_parents(self):
parents = [] parents = []
@ -39,9 +40,16 @@ class Actor(gobject.GObject):
transf = actor._transf transf = actor._transf
return transf.get_position(x, y) return transf.get_position(x, y)
def notify_changed(self):
if self._parent:
self._parent.notify_changed()
else:
self.emit('changed')
def set_size(self, width, height): def set_size(self, width, height):
self._width = width self._width = width
self._height = height self._height = height
self.notify_changed()
def render(self, drawable): def render(self, drawable):
pass pass

21
sugar/scene/View.py Normal file
View File

@ -0,0 +1,21 @@
import gtk
from sugar.scene.Stage import Stage
class View(gtk.DrawingArea):
def __init__(self, stage):
gtk.DrawingArea.__init__(self)
self._stage = stage
self._stage.connect('changed', self.__stage_changed_cb)
self.connect('expose_event', self.__expose_cb)
def __stage_changed_cb(self, stage):
if self.window:
self.window.invalidate_rect(None, False)
def __expose_cb(self, widget, event):
self._stage.render(widget.window)
def get_stage(self):
return self._stage