[pygtk] Re: Questions about GtkDrawingArea

=?ISO-8859-1?Q?Fran=E7ois_Pinard?= pinard@iro.umontreal.ca
18 Aug 2000 17:10:48 -0400


[Ben Escoto]

> 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()
        drawing_area.size(400, 400)
        frame.add(drawing_area)
        drawing_area.show()

        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