William R. Dieter wrote:


Thanks, I think I'll use a gdk.Pixmap instead of gdk.Drawable because I might want to do gdk.Pixmap.get_from_file in the future. The code was working showing the image, then I changed something, and now I cannot make it work. I have created several gtk.Image's with glade and I just want to draw into one of them. "image0" is the name of one of my gtk.Images. Here is the code in app.__init__:

~ self.im = self.wTree.get_widget("image0")
~ buf = 64*64*3*['\0']
~ for r in range(64):
~ for g in range(64):
~ buf[64*3*r + 3*g] = chr(r * 4)
~ buf[64*3*r + 3*g + 1] = chr(g * 4)
~ buf[64*3*r + 3*g + 2] = chr(0)
~ imbuf = string.join(buf, '')
~ gc = self.im.style.fg_gc[gtk.STATE_NORMAL]
~ pm = gtk.gdk.Pixmap(self.im.window, 64, 64, 24)
~ pm.draw_rgb_image(gc, 5, 5, 64, 64, gtk.gdk.RGB_DITHER_NONE,
~ imbuf, 64*64*3)

last param should be 64*3 its the length of one row (rowstride)


http://www.pygtk.org/pygtk2reference/class-gdkdrawable.html#method-gdkdrawable--draw-rgb-image



~ self.im.set_from_pixmap(pm, None)


It looks a lot like the tutorial, except I call self.wTree.get_widget to
get the initial object, and I have the extra step of puting the drawable
into the gtk.Image.  The error I get is:

Traceback (most recent call last):
~  File "./imops.py", line 142, in ?
~    app=appgui()
~  File "./imops.py", line 64, in __init__
~    imbuf, 64*64*3)
IndexError: rgb_buf is not large enough

If I print len(imbuf) it says 12288, which is 64*64*3.  I can even have
it print imbuf and redirect the output to a file, and the data in imbuf
looks correct (binary image data).

The frustrating part is that it was working at one point last night.  I
made a few changes I thought would be harmless, and now I cannot get it
to work.

Thanks again,
Bill.

PS, I know this is more of a GTK question, but is it normal to have to
redraw the images whenever I get an expose_event, or should the
gtk.Image take care of that for me?  The TextEntry and TextView objects
I have tried seem to do automatically update the text without outside
intervention.

Should be handled by Image


_______________________________________________
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to