[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)
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)
DAen.window.process_updates(True)
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
ctx.fill_preserve()
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