Hello<br><br>Is there a preferred way to make threaded updates to a cairo context in a gtk window?&nbsp; I want to create smooth animations.<br>Currently, I extend gtk.DrawingArea and do something like this:<br><br><span style="font-family: courier new,monospace;">
class P5(gtk.DrawingArea):</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"></span><br style="font-family: courier new,monospace;"><div style="margin-left: 40px; font-family: courier new,monospace;">
def __init__(self):<br><div style="margin-left: 40px;">super(P5, self).__init__()<br>self._looping = True<br>self._msecUpdate = 100<br>gobject.timeout_add( self._msecUpdate, self.update )<br></div></div><br style="font-family: courier new,monospace;">
<div style="margin-left: 40px; font-family: courier new,monospace;">def update(self):<br></div><div style="margin-left: 80px; font-family: courier new,monospace;">#paint thread -- call redraw_canvas<br>self.redraw_canvas()
<br>if (self._looping):<br><div style="margin-left: 40px;">return True # keep running this event<br></div>else:<br><div style="margin-left: 40px;">return False<br></div></div><br style="font-family: courier new,monospace;">
<div style="margin-left: 40px; font-family: courier new,monospace;">#called from update<br>def redraw_canvas(self):<br><div style="margin-left: 40px;">if self.window:<br><div style="margin-left: 40px;">alloc = self.get_allocation
()<br>self.queue_draw_area(0, 0, alloc.width, alloc.height)<br>self.window.process_updates(True)<br></div></div></div><br style="font-family: courier new,monospace;"><div style="margin-left: 40px; font-family: courier new,monospace;">
#called from redraw_canvas<br></div><div style="margin-left: 40px;"><span style="font-family: courier new,monospace;">def expose(self, widget, event):</span><br style="font-family: courier new,monospace;"><div style="margin-left: 40px;">
<span style="font-family: courier new,monospace;">ctx = widget.window.cairo_create()</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
# set a clip region for the expose event</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">ctx.rectangle(event.area.x, event.area.y, event.area.width, event.area.height
)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">ctx.clip()</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
rect = widget.allocation</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">self.draw( ctx, rect.width, rect.height ) #make nice pictures...</span><br></div></div><br><br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>I am not doing any double-buffering.&nbsp; There is probably a better way to thread this.<br><br>Does goocanvas handle some of this better?&nbsp; If so, is there a good example of how to use it effectively?&nbsp; If not goocavas, then what do people recommend for efficient cairo animation on the laptop?
<br><br>Thanks,<br>Erik<br>