[pygtk] pixmap question...
Gustavo J. A. M. Carneiro
gjc at inescporto.pt
Sun Oct 14 20:53:59 WST 2007
On Sat, 2007-10-13 at 11:58 +0100, Rory Walsh wrote:
> 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?
I don't know what's wrong with your code, but I know you are using
outdated APIs to draw; you should be using cairo instead.
This example of animation using cairo might help you:
http://www.gnome.org/~gjc/merrychristmas.py
>
> Rory.
>
> p.s. I posted this yesterday but I think it got caught up somewhere in a
> different thread, sorry about the noise..
>
>
> 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()
> _______________________________________________
> pygtk mailing list pygtk at daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
--
Gustavo J. A. M. Carneiro
<gjc at inescporto.pt> <gustavo at users.sourceforge.net>
"The universe is always one step beyond logic" -- Frank Herbert
More information about the pygtk
mailing list