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 )
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):
self.redraw_canvas()
if (self._looping):
return True # keep running this event
else:return False
#called from update
def redraw_canvas(self):
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)
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...
# 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
_______________________________________________ Sugar mailing list [email protected] http://mailman.laptop.org/mailman/listinfo/sugar
