[pygtk] pixmap question...
Rory Walsh
rorywalsh at ear.ie
Sat Oct 13 04:29:00 WST 2007
I'm trying to animate a line being drawn across the screen. My first
attempt using only a drawingarea proved fruitless so I am now trying it
using a pixmap and a drawing area. I have the following code which is
hacked from several bits of code I found online. I'm confused as to how
I am supposed to update the the drawing area with the pixmap image?
Here's the code, can anyone spot any obvious silliness?
Rory.
import pygtk
pygtk.require('2.0')
import gtk
import gobject
import math
xcor = 0
def pix_init(d_area, width, height):
d_area.realize()
win = d_area.window
pixmap = gtk.gdk.Pixmap(win, width, height, -1)
context = win.new_gc()
cmap = d_area.get_colormap()
context.foreground = cmap.alloc_color(128*64,128*64,128*64)
for x in range(width):
pixmap.draw_point(context, x, height / 2)
d_area.connect("expose-event", pix_expose, pixmap)
return pixmap
def pix_expose(da, event, pixmap):
x, y, width, height = da.get_allocation()
da.window.draw_drawable(
da.get_style().fg_gc[0], pixmap, 0, 0, 0, 0, -1, -1)
def draw(da, pixmap):
global xcor
win = da.window
context = win.new_gc()
pixmap.draw_point(context, xcor, 100)
da.queue_draw()
xcor=xcor+1
print xcor
return True
def redraw_timeout(da, pixmap):
#da.window.invalidate_rect((0,0,200,200),False)
return True
def main():
global xcor
xcor = 0
width,height=640,480
top = gtk.Window(gtk.WINDOW_TOPLEVEL)
da = gtk.DrawingArea()
#print dir(da)
da.set_size_request(width, height)
top.add(da)
pixmap=pix_init(da, width, height)
top.show_all()
gobject.timeout_add(120,draw,da,pixmap)
gtk.main()
if __name__ =="__main__":
main()
More information about the pygtk
mailing list