> Can you give an example of how to do this?  I'd love to find a Python-only
> solution for avoiding flickering.

I think I can. Maybe it helps.

Martin Grimme - http://www.pycage.de


-----8<-----------------------------------------------------------------------

# This is only a quick hack of 15 minutes and not the best programming style.
# But I hope it will help illustrating the technique.

from gtk import *
import GdkImlib


class Example(GtkWindow):
    def __init__(self):
        win = GtkWindow()
        win.connect("destroy", mainquit)

        self.pic = GtkDrawingArea()
        self.pic.show()
        win.add(self.pic)

        self.pic.connect("expose_event", self.on_exposure)
        # change images on mouse button press
        self.pic.connect("button_press_event", self.nextPic)
        self.pic.set_events(GDK.EXPOSURE_MASK | GDK.BUTTON_PRESS_MASK)

        # create three GdkPixmaps, one for buffering and two for both images
        self.buffer = create_pixmap(win, 500, 500)
        self.pic1 = create_pixmap(win, 500, 500)
        self.pic2 = create_pixmap(win, 500, 500)

        # create image 1
        img = GdkImlib.Image("/home/mg/Pics/asuka.jpg") # use your image here
        img.render()
        p, m = img.get_pixmap()
        gc = self.pic1.new_gc()
        draw_pixmap(self.pic1, gc, p, 0, 0, 0, 0, 500, 500)

        # create image 2
        img = GdkImlib.Image("/home/mg/Pics/flute.jpg") # use your image here
        img.render()
        p, m = img.get_pixmap()
        gc = self.pic2.new_gc()
        draw_pixmap(self.pic2, gc, p, 0, 0, 0, 0, 500, 500)

        gc = self.buffer.new_gc()
        draw_pixmap(self.buffer, gc, self.pic1, 0, 0, 0, 0, 500, 500)

        self._o = win._o



    # update drawing area when necessary
    def on_exposure(self, widget, event):
        gc = self.pic.get_style().fg_gc[STATE_NORMAL]
        self.pic.draw_pixmap(gc, self.buffer, 0, 0, 0, 0, 500, 500)


    # show 2nd image
    def nextPic(self, widget, event):
        gc = self.buffer.new_gc()
        draw_pixmap(self.buffer, gc, self.pic2, 0, 0, 0, 0, 500, 500)
        # redraw drawing area
        self.pic.queue_draw()



# instantiate an object of the class
example = Example()
example.show()

mainloop()



_______________________________________________
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk

Reply via email to