[cairo] problem refreshing cairo surface

Kalle Vahlman kalle.vahlman at gmail.com
Sun Nov 13 07:42:08 PST 2011

2011/11/13 Zoltán Vörös <zvoros at gmail.com>:
> On 11/13/2011 06:47 AM, Kalle Vahlman wrote:
>> I don't immediately spot the error, though there is a possible race
>> condition between configure_event (which is an asynchronous event by nature)
>> and trying to use the context it creates in on_load(). That should probably
>> give an error though.
> I think your suspicion was correct. This works, although I am not sure
> whether this is how it should be done:
>        self.DA = Preview()
>        self.widget('box_preview').pack_start(self.DA.da, True, True, 0)
>        while Gtk.events_pending():
>            Gtk.main_iteration()
>        self.draw_note(self.DA.da, self.DA.surface)

What I meant was that you should not create the context in
configure_event, but only when you draw (and destroy it when
finished). Contexes are lightweight enough to make any drawing
operation drown the (potentially frequent) creation performance-wise,
so there is no reason to keep it around. And many not to, for example
this problem you are having, also the fact that if the context goes
into an error state (wrong parameters etc), you need to re-create it
or you won't be able to draw anything anymore.

> What is a bit odd, however, is that if I move the Gtk.main_iteration() to
> the __init__ or the configuration function, then it doesn't work.
> Anyway, I would still be interested in the "proper" way of handling this.

I suppose what happens in those stages is that the event queue is not
flushed yet so there are no events pending to process, but that's just
a guess...

Kalle Vahlman, zuh at iki.fi
Powered by http://movial.com
Interesting stuff at http://sandbox.movial.com

More information about the cairo mailing list