[cairo] Getting a loop to redraw a Cairo/GTK-window.
Kalle Vahlman
kalle.vahlman at gmail.com
Tue Sep 4 05:21:35 PDT 2007
2007/9/4, Rasmus Berlin <batluder at daimi.au.dk>:
> 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)
> ctx.set_tolerance(0.1)
> ctx.set_line_join(cairo.LINE_JOIN_ROUND)
>
> 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)
So apparently you try here to use the context you create on expose?
That won't work since as the error message tells you, the surface
target is already gone (it is usually a temporary pixmap GTK+ has
redirected the drawing to).
The good news is that you shouldn't be drawing anything here anyway,
only in the expose handler. The invalidate_rect() will generate the
expose event and thus trigger the drawing. So even if the extra
drawing would succeed, it would be immediately overwritten by the
expose handler.
--
Kalle Vahlman, zuh at iki.fi
Powered by http://movial.fi
Interesting stuff at http://syslog.movial.fi
More information about the cairo
mailing list