[cairo] Getting a loop to redraw a Cairo/GTK-window.

Rasmus Berlin batluder at daimi.au.dk
Tue Sep 4 00:20:56 PDT 2007

I'm having trouble making a loop to redraw a scene. How do I get the  
window to redraw?

The window is drawn perfectly once by the expose method:

     def expose(self, da, event):
         global CTXen
         global DAen

         ctx = da.window.cairo_create()

         ctx.set_source_rgb(0, 0, 0)
         ctx.set_line_width(SIZE / 4)

         ViewManager.draw(Tree.getroot(), ctx)

         CTXen = ctx
         DAen = da

I try to redraw by use of a timer:

         gobject.timeout_add(100, self.update)

It runs an update-method:

     def update(self):
         global CTXen
         global DAen
         if CTXen is not None:
             alloc = DAen.get_allocation()
             rect = gtk.gdk.Rectangle(0, 0, alloc.width, alloc.height)
             DAen.window.invalidate_rect(rect, True)
             ViewManager.draw(Tree.getroot(), CTXen)
         return True

But I get the error:

   Traceback (most recent call last):
     File "server.py", line 70, in update
       ViewManager.draw(Tree.getroot(), CTXen)
     File "../common/ViewManager.py", line 158, in draw
   cairo.Error: the target surface has been finished

I'm open to any nicer or cleaner ways to build the loop. I just want  
the window to redraw.
I hope someone here can help me out.

                    - Rasmus Berlin

More information about the cairo mailing list