[Sugar-devel] Gtk.DrawingArea's draw signal

Benjamin Berg benzea at sugarlabs.org
Thu Jun 28 07:36:21 EDT 2012


On Thu, 2012-06-28 at 08:22 -0300, Manuel Kaufmann wrote:
> > ie.:
> >  clipped, rect = Gdk.cairo_get_clip_rectangle(cr)
> >
> > clipped will always be True in GTK+. rect then contains the affected
> > area, similar to event.area before.
> 
> So, I should ask for the affected rect and use it to re-draw just the
> affected part as it was by now using this chunk of code that you
> mentioned here. Am I right?

You don't need it at all actually. GTK+ already does the clipping of the
context, so those lines can simply be removed.

The other thing that you do is get the size. You can still do it in the
same ways before, except that self.window does not exist anymore, you
need to use self.get_window() instead.
So you get:
  width, height = self.get_window().get_size()

As an alternative you could also get the allocation with. This seems
saner to me:
  alloc = self.get_allocation()

So, your drawing function becomes:

def do_draw(self, cr):
    alloc = self.get_allocation()
    self._current_drawer.draw(cr, alloc.width, alloc.height) 

Nothing else is required.

Benjamin



More information about the Sugar-devel mailing list