[pygtk] Re: Questions about GtkDrawingArea
18 Aug 2000 17:10:48 -0400
> This produces a window which is very slow to redraw, for instance after
> a workspace or virtual screen is changed. Whenever this happens, I see
> the whole window being covered with the default gtk metal theme (which
> seems to happen quickly), and then the pixmap is redrawn on top of it.
> Is there a way not to have the metal stuff drawn underneath, or perhaps
> to put the pixmap where the metal stuff is so it doesn't need to be
> redrawn all the time?
I'm not fully sure I'm replying to your question, but a good way to update
a display is to draw it into a memory pixmap instead of in the real drawing
area, and once done in memory, fastly transfer the memory to the window.
The following lines are taken from an exercise I gave to myself:
In the initialisation section:
drawing_area = GtkDrawingArea()
self.area = drawing_area.get_window()
self.cyan_gc = self.area.new_gc()
self.cyan_gc.foreground = drawing_area.get_colormap().alloc('cyan')
self.black_gc = drawing_area.get_style().black_gc
self.white_gc = drawing_area.get_style().white_gc
Within the update function:
# Redraw everything.
pixmap = create_pixmap(self.area, xmax+1, ymax+1)
draw_rectangle(pixmap, self.white_gc, TRUE, 0,0, xmax+1,ymax+1)
draw_lines(pixmap, self.black_gc, points)
draw_pixmap(self.area, self.white_gc, pixmap, 0,0, 0,0, xmax+1,ymax+1)
François Pinard http://www.iro.umontreal.ca/~pinard