Thanks to all for the comments! I have attached the completed example below
(for future reference for people like myself). Now, my goal is to move the
Python code for drawing in the array to C code. I hope to have a simple 3D
engine soon...
Thanks again, especially James Henstridge, for all of the work on this system.
-Doug Blank
# Draw an array-based image in a gtk window
# D.S. Blank, with help from the pygtk mailing list
import Numeric
from gtk import *
class DrawPixmap(GtkWindow):
def __init__(self):
# ---------------- initialize window instance:
GtkWindow.__init__(self)
self.width = 200 # my own var
self.height = 100 # my own var
self.set_default_size(self.width, self.height)
# ---------------- Now create a drawing area:
self.pic = GtkDrawingArea()
self.pic.show()
self.add(self.pic)
# ---------------- Set Callbacks, and event handlers:
self.pic.connect("expose_event", self.on_exposure)
self.connect("destroy", mainquit)
self.pic.set_events(GDK.EXPOSURE_MASK | GDK.DESTROY)
def on_exposure(self, widget, event):
# create a pixmap, just once:
if not hasattr(self, 'pixmap'):
self.pixmap = create_pixmap(self, self.width, self.height)
self.gc = self.pixmap.new_gc()
# create a numeric array filled with zeros of type 8 bit int:
self.buff = Numeric.zeros((self.height, self.width, 3), 'b')
# draw a design:
for x in range(0, self.width):
for y in range(0, self.height):
try:
if ((x % y == 0) or (y % x == 0)):
self.buff[y][x] = [255, 255, 0] # yellow (r, g, b)
except ZeroDivisionError:
pass
# put the array on the pixmap:
draw_array(self.pixmap, self.gc, 0, 0, GDK.RGB_DITHER_NONE, \
self.buff)
# draw it:
self.pic.draw_pixmap(self.gc, self.pixmap, 0, 0, 0, 0, \
self.width, self.height)
if __name__ == '__main__':
push_rgb_visual()
example = DrawPixmap()
pop_visual()
example.show()
mainloop()
_______________________________________________
pygtk mailing list [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk