[sugar] cairo animation optimization

Erik Blankinship erikb
Mon Nov 13 13:20:08 EST 2006


Hello

Is there a preferred way to make threaded updates to a cairo context in a
gtk window?  I want to create smooth animations.
Currently, I extend gtk.DrawingArea and do something like this:

class P5(gtk.DrawingArea):

def __init__(self):
super(P5, self).__init__()
self._looping = True
self._msecUpdate = 100
gobject.timeout_add( self._msecUpdate, self.update )

def update(self):
#paint thread -- call redraw_canvas
self.redraw_canvas()
if (self._looping):
return True # keep running this event
else:
return False

#called from update
def redraw_canvas(self):
if self.window:
alloc = self.get_allocation()
self.queue_draw_area(0, 0, alloc.width, alloc.height)
self.window.process_updates(True)

#called from redraw_canvas
def expose(self, widget, event):
ctx = widget.window.cairo_create()

# set a clip region for the expose event
ctx.rectangle(event.area.x, event.area.y, event.area.width,
event.area.height)
ctx.clip()
rect = widget.allocation
self.draw( ctx, rect.width, rect.height ) #make nice pictures...



I am not doing any double-buffering.  There is probably a better way to
thread this.

Does goocanvas handle some of this better?  If so, is there a good example
of how to use it effectively?  If not goocavas, then what do people
recommend for efficient cairo animation on the laptop?

Thanks,
Erik
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.laptop.org/pipermail/sugar/attachments/20061113/1318d8d0/attachment.html


More information about the Sugar-devel mailing list