[pygtk] gtk.gdk.Pixbuf troubles and IRC

Andrew rugby471 at gmail.com
Mon Jul 12 15:16:17 WST 2010


On 12/07/10 00:01, Tim Evans wrote:
> On 2010-07-11 4:19, Andrew wrote:
>> Hi guys,
>>
>> In this example, a small gtk.gdk.Pixbuf is copied onto a larger pixbuf
>> however where on the small pixbuf, there is transparency, this is
>> converted to the gtk background colour.
>>
>> This means when the small pixbuf is copied 3 times and overlaid (as in
>> the example), it looks incorrect. How do I make it so that the
>> transparency in the small pixbuf is not replaced with the gtkbackground
>> colour?
> 
> You need to use the 'composite' method rather than copy_area. I would 
> provide example code, but the arguments are a bit complex and I'd be 
> sure to get them wrong the first time and confuse you.
> 

I am afraid that didn't work either. It now gives me the image shown in
the screenshot attached. Below is my code.


Is there a way to do this successfully or do I need to use cairo or
something? (I must mention that the pixbufs I retrieve from a
gtk.Icontheme are SVGs, if this makes any difference)



#!/usr/bin/env python
import gtk
from gtk import gdk as gdk

small = 16
counter = 0
offset = 4
large = 24

if __name__ == "__main__":

    icon_theme = gtk.icon_theme_get_default();

    small_pixbuf = icon_theme.load_icon("image", small, ());

    large_pixbuf = icon_theme.load_icon("image", large, ());

    large_pixbuf.fill(0x000000);

    small_pixbuf_buffer = small_pixbuf.copy()
    small_pixbuf.composite(large_pixbuf, 0, 0, 24, 24, 0, 0, 1, 1,
gdk.INTERP_NEAREST, 255);
    small_pixbuf_buffer = small_pixbuf.copy()
    small_pixbuf.composite(large_pixbuf, 0, 0, 24, 24, 4, 4, 1, 1,
gdk.INTERP_NEAREST, 255);
    small_pixbuf_buffer = small_pixbuf.copy()
    small_pixbuf.composite(large_pixbuf, 0, 0, 24, 24, 8, 8, 1, 1,
gdk.INTERP_NEAREST, 255);

    window = gtk.Window()
    image = gtk.Image()
    image.set_from_pixbuf(large_pixbuf)
    window.add(image)
    window.show_all()
    window.connect("delete-event", gtk.main_quit)
    gtk.main()

-- 
Andrew
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screenshot-untitled.py.png
Type: image/png
Size: 3868 bytes
Desc: not available
Url : http://www.daa.com.au/pipermail/pygtk/attachments/20100712/ddf469ea/attachment.png 


More information about the pygtk mailing list