[pygtk] gtk.DrawingArea
Danny Milosavljevic
danny.milo at gmx.net
Mon Feb 13 02:53:28 WST 2006
Hi,
Am Freitag, den 10.02.2006, 10:44 +0100 schrieb Luigi Paioro:
> [...]
> While I can draw a line on a gtk.gdk.Drawable object, it looks that I
> cannot delete it. For example I can draw a line using:
>
> area = gtk.DrawingArea()
> area.window.draw_line(gc, x1, y1, x2, y2)
>
> but I cannot delete such line... a line isn't identified by an object or
> an ID and it doesn't exist a proper method to delete it!
What you describe is called a "Canvas". While there are canvas
implementations (DiaCanvas, for example), for this use case, a drawing
area is more than enough.
The way is that the system tells you to repaint a certain area of the
drawing area by emitting a signal ("expose-event"), and in there, you
(clear the area with draw_rectangle and) repaint whatever is "supposed"
to be shown.
If you want to force repaint, call widget.queue_draw().
So what you would do is:
in your button-motion-event:
set self.x = x, self.y = y
call widget.queue_draw()
in your expose-event:
call widget.get_window().draw_rectangle(0, 0, widget.allocation.width,
widget.allocation.height) for clearing the background
call widget.get_window().draw_line(self.x, self.y, ...) for the line
cheers,
Danny
More information about the pygtk
mailing list