[pygtk] Questions about GtkDrawingArea

2000-08-18 Thread Ben Escoto


 Hi, I have been using GtkDrawingArea by following the example
simple/scribble.py in the pygtk distribution.  Basically, the only
thing drawn into the window is a pixmap the size of the window.  All
drawing happens onto the pixmap, and the relevant parts of the pixmap
are drawn onto the GtkDrawingArea through an expose_event callback.

 Is this the right way to do things if you just want to be able to
use the gdk drawing functions and catch, for instance, mouse button
signals?  This is what the example seems to be doing, but I am
wondering because

1) GtkDrawingArea has other methods when it seems that this use will
always only involve displaying a pixmap

2) 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?


--
Ben Escoto

___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk



[pygtk] Re: Questions about GtkDrawingArea

2000-08-18 Thread François Pinard

[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

___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk



Re: [pygtk] Questions about GtkDrawingArea

2000-08-18 Thread Scott F. Johnston

If you look at the GtkDrawingArea widget, you'll see that
it exposes a bunch of drawing methods:

  draw_point
  draw_line
  draw_rectangle
  draw_arc
  draw_polygon
  draw_string
  draw_pixmap
  draw_points
  draw_segments
  draw_lines

The scribble example is choosing to paint into a pixmap and then
present that pixmap on a drawingarea.

Your application can draw directly onto the drawing area without
using a pixmap, if that is preferred.
Pixmaps are just amoung the things you can draw onto a drawingarea.

DrawingArea's are good for prototyping new widgets.

Good luck!

--S

___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk