Re: [pygtk] Switching pixmaps using GtkPixmap.set()
> 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
Re: [pygtk] Switching pixmaps using GtkPixmap.set()
On Monday, Martin Grimme mumbled: > You could use GdkPixmaps and double buffering to avoid flickering. Can you give an example of how to do this? I'd love to find a Python-only solution for avoiding flickering. --Tessa ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk
Re: [pygtk] Switching pixmaps using GtkPixmap.set()
Tessa Lau wrote: > > There seems to be another problem. When I do the following, I get > unexpected output: > > >>> img = GdkImlib.Image(filename) > >>> img.render() > 1 > >>> pix = img.make_pixmap() > >>> print pix > > >>> pmap, mask = img.get_pixmap() > Gdk-CRITICAL **: file gdkwindow.c: line 716 (gdk_window_ref): assertion > `window != NULL' failed. > > Do I have to do something to the image before getting its pixmap? > This apparently is a bug in PyGTK's GdkImlib module (or in Imlib itself). It should work fine if you add a "img.render()" just before the "get_pixmap"- line. Maybe "make_pixmap" does some changes to the image which shouldn't be... > Also, I looked at two Imlib-based image viewers written in C, and they both > set the backing pixmap using gdk_window_set_back_pixmap and > gdk_window_clear. Why aren't these functions available in the Python > wrapper? Yes, why? I am missing them, too! > > I'm trying to make a slideshow app, and using the gtk_pixmap_set method to > switch images results in flickering in the display, whereas the C image > viewers (electric eyes and gqview) don't have any flickering when they > change images. > You could use GdkPixmaps and double buffering to avoid flickering. Martin Grimme - http://www.pycage.de ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk
Re: [pygtk] Switching pixmaps using GtkPixmap.set()
There seems to be another problem. When I do the following, I get unexpected output: >>> img = GdkImlib.Image(filename) >>> img.render() 1 >>> pix = img.make_pixmap() >>> print pix >>> pmap, mask = img.get_pixmap() Gdk-CRITICAL **: file gdkwindow.c: line 716 (gdk_window_ref): assertion `window != NULL' failed. Do I have to do something to the image before getting its pixmap? Also, I looked at two Imlib-based image viewers written in C, and they both set the backing pixmap using gdk_window_set_back_pixmap and gdk_window_clear. Why aren't these functions available in the Python wrapper? I'm trying to make a slideshow app, and using the gtk_pixmap_set method to switch images results in flickering in the display, whereas the C image viewers (electric eyes and gqview) don't have any flickering when they change images. --Tessa ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk
Re: [pygtk] Switching pixmaps using GtkPixmap.set()
> This looks like a bug in pygtk. You should be able to fix it by editing > generate/gtkmisc.defs, and finding the following section: > (define-func gtk_pixmap_set > none > ((GtkPixmap pixmap) >(GdkPixmap val) >(GdkBitmap mask))) > and change it to: > (define-func gtk_pixmap_set > none > ((GtkPixmap pixmap) >(GdkPixmap val) >(GdkBitmap mask (null-ok Another way without hacking into pygtk and thus making your program incompatible for the rest of the world would be to check if Imlib returns None for the mask. If this happens, you can create a mask by yourself: width, height = (img2.rgb_width, img2.rgb_height) mask = create_pixmap(None, width, height, 1) gc = mask.new_gc() gc.foreground = GdkColor(0, 0, 0, 0) draw_rectangle(mask, gc, TRUE, 0, 0, width, height) This is the way I handle this. Martin Grimme - http://www.pycage.de ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk
Re: [pygtk] Switching pixmaps using GtkPixmap.set()
On Mon, 30 Oct 2000, Tessa Lau wrote: > > > Use "pix2, mask = img2.get_pixmap()" here instead of > > make_pixmap(). Make_pixmap returns a new GtkPixmap widget rather than a > > GdkPixmap/GdkBitmap pair. > > That's closer... but that gives me this error: > TypeError: gtk_pixmap_set, argument 3: expected GdkWindow, None found This looks like a bug in pygtk. You should be able to fix it by editing generate/gtkmisc.defs, and finding the following section: (define-func gtk_pixmap_set none ((GtkPixmap pixmap) (GdkPixmap val) (GdkBitmap mask))) and change it to: (define-func gtk_pixmap_set none ((GtkPixmap pixmap) (GdkPixmap val) (GdkBitmap mask (null-ok James. ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk
Re: [pygtk] Switching pixmaps using GtkPixmap.set()
So I'm still trying to write an image viewer with PyGtk and Imlib. I looked at the source to Electric Eyes, and this is what it does (im is the GdkImlibImage created by a call to gdk_imlib_load_image()): gdk_imlib_render(im, width, height); pmap = gdk_imlib_move_image(im); mask = gdk_imlib_move_mask(im); gdk_window_set_back_pixmap(a->window, pmap, FALSE); gdk_window_clear(a->window); gdk_window_shape_combine_mask(a->window, mask, 0, 0); gdk_imlib_free_pixmap(pmap); The two interesting calls are the gdk_imlib_move_image and move_mask, neither or which appears to be wrapped in the GdkImlib module. But they seem to be an alternate means of getting a pixmap and a mask from Imlib, other than get_pixmap. Am I asking the wrong list? Is there a list specifically for the GdkImlib wrapper? It doesn't seem like it should be this hard to write an image viewer. Tessa Lau [EMAIL PROTECTED] ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk
Re: [pygtk] Switching pixmaps using GtkPixmap.set()
> Use "pix2, mask = img2.get_pixmap()" here instead of > make_pixmap(). Make_pixmap returns a new GtkPixmap widget rather than a > GdkPixmap/GdkBitmap pair. That's closer... but that gives me this error: TypeError: gtk_pixmap_set, argument 3: expected GdkWindow, None found The mask returned by get_pixmap() is None. Is that supposed to happen? --Tessa ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk
Re: [pygtk] Switching pixmaps using GtkPixmap.set()
On Mon, 30 Oct 2000, Tessa Lau wrote: > > Hi all, > > I'm having trouble writing a simple image viewer using PyGtk and Imlib. I > can load the first image fine, but I don't know how to display the second > image into the first pixmap without creating and showing a completely new > Pixmap widget for it (thus causing terrible flicker as the widget is erased > and redrawn). From reading the source, I see that the GtkPixmap.set() > method might be what I want, but I can't get it to work. > > Here's what I'm trying: > > def next(window, event): > img2 = GdkImlib.Image('page02.gif') > img2.render() > pix2 = img2.make_pixmap() Use "pix2, mask = img2.get_pixmap()" here instead of make_pixmap(). Make_pixmap returns a new GtkPixmap widget rather than a GdkPixmap/GdkBitmap pair. > pix = window.get_data('user_data') > pix.set(pix2, None) and then change this to "pix.set(pix2, mask)" > > def main(): > window = gtk.GtkWindow() > window.connect('key_press_event', next) > img = GdkImlib.Image('page01.gif') > img.render() > pix = img.make_pixmap() > window.set_data('user_data', pix) > window.add(pix) > pix.show() > window.show() > > gtk.mainloop() > > And this is the error I get: > > Traceback (innermost last): > File "/usr/lib/python1.5/site-packages/gtk.py", line 125, in __call__ > ret = apply(self.func, a) > File "../test.py", line 11, in next > pix.set(pix2, None) > File "/usr/lib/python1.5/site-packages/gtk.py", line 2225, in set > _gtk.gtk_pixmap_set(self._o, pixmap, mask) > TypeError: gtk_pixmap_set, argument 2: expected GdkWindow, instance found > > Obviously I'm trying to use pix.set() incorrectly. What's the right way? James. ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk
[pygtk] Switching pixmaps using GtkPixmap.set()
Hi all, I'm having trouble writing a simple image viewer using PyGtk and Imlib. I can load the first image fine, but I don't know how to display the second image into the first pixmap without creating and showing a completely new Pixmap widget for it (thus causing terrible flicker as the widget is erased and redrawn). From reading the source, I see that the GtkPixmap.set() method might be what I want, but I can't get it to work. Here's what I'm trying: def next(window, event): img2 = GdkImlib.Image('page02.gif') img2.render() pix2 = img2.make_pixmap() pix = window.get_data('user_data') pix.set(pix2, None) def main(): window = gtk.GtkWindow() window.connect('key_press_event', next) img = GdkImlib.Image('page01.gif') img.render() pix = img.make_pixmap() window.set_data('user_data', pix) window.add(pix) pix.show() window.show() gtk.mainloop() And this is the error I get: Traceback (innermost last): File "/usr/lib/python1.5/site-packages/gtk.py", line 125, in __call__ ret = apply(self.func, a) File "../test.py", line 11, in next pix.set(pix2, None) File "/usr/lib/python1.5/site-packages/gtk.py", line 2225, in set _gtk.gtk_pixmap_set(self._o, pixmap, mask) TypeError: gtk_pixmap_set, argument 2: expected GdkWindow, instance found Obviously I'm trying to use pix.set() incorrectly. What's the right way? Tessa Lau [EMAIL PROTECTED] ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk