porting from pygtk to pygi - weird problem with pixbufs

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

porting from pygtk to pygi - weird problem with pixbufs

Giuseppe Penone
Hi,
I'm co-author of the app x-tile (graphical windows tiling) which is currently in pygtk but is already fully ported to pygi (even if not public yet).

The problem is that the pixbufs (windows icons) are rendered properly in pygtk but are not in pygi (the icons are sometimes partially rendered,
sometimes not at all, if you click F5 to refresh the list many times you can see it clearly).

the involved (pygtk) function is:

def get_icon(win):
    """   this returns a gtk.gdk.pixbuf of the windows icon
          converts argb into rgba in the process   """
    get_property("_NET_WM_ICON", win, glob.XA_CARDINAL)
    if not glob.ret_pointer : return None
    w = glob.ret_pointer[0]
    h = glob.ret_pointer[1]
    s = w*h
    buff = ""
    i = 0
    while i<s:
        argb = glob.ret_pointer[i+2]
        i += 1
        buff = buff + ("%c" % ((argb >> 16) & 0xff))
        buff = buff + ("%c" % ((argb >> 8) & 0xff))
        buff = buff + ("%c" % (argb & 0xff))
        buff = buff + ("%c" % ((argb >> 24) & 0xff))
    pxbuf = gtk.gdk.pixbuf_new_from_data(buff, gtk.gdk.COLORSPACE_RGB, True, 8, w, h, w*4)
    return pxbuf

that ported to pygi becomes:

def pixbuf_destroy_fn(pixbuf, data):
    """Function called when there are no more references of pixbuf"""
    del pixbuf

def get_icon(win):
    """   this returns a Gdk.pixbuf of the windows icon
          converts argb into rgba in the process   """
    get_property("_NET_WM_ICON", win, glob.XA_CARDINAL)
    if not glob.ret_pointer : return None
    w = glob.ret_pointer[0]
    h = glob.ret_pointer[1]
    s = w*h
    buff = ""
    i = 0
    while i<s:
        argb = glob.ret_pointer[i+2]
        i += 1
        buff = buff + ("%c" % ((argb >> 16) & 0xff))
        buff = buff + ("%c" % ((argb >> 8) & 0xff))
        buff = buff + ("%c" % (argb & 0xff))
        buff = buff + ("%c" % ((argb >> 24) & 0xff))
    pxbuf = GdkPixbuf.Pixbuf.new_from_data(buff,
                                           GdkPixbuf.Colorspace.RGB,
                                           True,
                                           8,
                                           w,
                                           h,
                                           w*4,
                                           pixbuf_destroy_fn, None)
    return pxbuf

If anybody has some hints please help us.
Everybody can run the app easily from source cloning:

hg clone https://giuspen@.../p/giuspen-x-tile/ hg_x-tile
cd hg_x-tile
./x-tile

and see the correct functionality

doing

hg update pygi
./x-tile

you run the pygi version, and can switch back to pygtk with

hg update default
./x-tile

Cheers,
Giuseppe.

_______________________________________________
pygtk mailing list   [hidden email]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/