PyGTK and draw_array

Esko Lehtonen esko.lehtonen at pp.htv.fi
Sun Jul 2 05:34:30 EDT 2000


I am trying to manipulate an image and then draw it to GtkDrawingArea
using PyGtk and Numerical Python. 

Here is description of draw_array function from file gtk.py. (I don't
know exactly what is that hassattr thing.)

   # this function renders an unsigned byte (type code 'b') numpy array
to a
   # drawable.  If it is a MxN or MxNx1 array, it is assumed to be a
grey image.
   # If it is a MxNx3 or MxNx4 array, it is assumed to be an rgb image.
   # It should accept images that have been sliced along their first two
axes,
   # if you want to only draw part of the image.
   if hasattr(_gtk, "gdk_draw_array"):
           def draw_array(drawable, gc, x, y, dither, array):
                   _gtk.gdk_draw_array(drawable, gc, x, y, dither,
array)

So I made following code:

WIDTH = 30
HEIGHT = 20
D = 3
# create rgb image as array, every value 100
img = ones((WIDTH, HEIGHT, D), 'b')
img = img * 100
----
darea = GtkDrawingArea()
---- 
draw_array(darea.get_window(),
	   widget.get_style().black_gc, x, y, 
           GDK.RGB_DITHER_NORMAL, img)


I still have a problem, because then a got: "TypeError: array data must
be unsigned bytes" when I'm trying to use the draw_array function. 

What is problem here? Or do you know alternative ways to do this using
PyGTK or some other graphics library?

Thanks in advance



--------------------------------------------------------------------
 Esko Lehtonen                   WYSINWYG -              
                                 What You See Is Never What You Get



More information about the Python-list mailing list