tags:

views:

191

answers:

1

Here is the code that I have so far to define the icon:

icon_bg = gtk.gdk.pixbuf_new_from_file('gmail.png')
w, h = icon_bg.get_width(), icon_bg.get_height()
cmap = gtk.gdk.Colormap(gtk.gdk.visual_get_system(), False)

drawable = gtk.gdk.Pixmap(None, w, h, 24)
drawable.set_colormap = cmap
gc = drawable.new_gc()
drawable.draw_pixbuf(gc, icon_bg, 0, 0, 0, 0, w, h)

drawn_icon = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, w, h)
drawn_icon.get_from_drawable(drawable, cmap, 0, 0, 0, 0, w, h)
icon = gtk.status_icon_new_from_pixbuf(drawn_icon)

This works to get the png into the icon, but falls short in two areas. First, transparency is not working. If I use a 22x22 png with transparent background and the image centered, I end up with sections of other active icons showing up inside of mine, like this:

http://i237.photobucket.com/albums/ff311/Raugturi/22x22_image_with_transparency.png

The icon it choose to steal from is somewhat random. Sometimes it's part of the dropbox icon, others the NetworkManager Applet.

If I instead use this code:

icon_bg = gtk.gdk.pixbuf_new_from_file('gmail.png')
w, h = icon_bg.get_width(), icon_bg.get_height()
cmap = gtk.gdk.Colormap(gtk.gdk.visual_get_system(), False)

drawable = gtk.gdk.Pixmap(None, w, h, 24)
drawable.set_colormap = cmap
gc = drawable.new_gc()
drawable.draw_pixbuf(gc, icon_bg, 0, 0, 0, 0, w, h)

drawn_icon = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, 22, 22)
drawn_icon.get_from_drawable(drawable, cmap, 0, 0, 3, 6, w, h)
icon = gtk.status_icon_new_from_pixbuf(drawn_icon)

And an image that is only 16x11 with the transparent edges removed, what I end up with is this:

Same URL but file is 16x11_image_positioned_in_middle.png

So how do I end up with a transparent block like the 1st one that doesn't pull in stuff from other icons?

As for the second problem, I need the ability to write on the image before converting it to the icon. I tried using draw_glyphs and it told me I should be using Pango layout/context instead. Unfortunately all the Pango tutorials I could find deal with actual windows, not the status icon. Is there a good tutorial out there for Pango that would apply to this issue (and also maybe have at least some explanation of how to tell it what font to use as all of them that I found seem to lack this and it won't write anything without it).

Note: Sorry for the lack of actual images and only one working link, apparently this is a spam prevention feature due to my lack of reputation.

A: 

Is there a reason you can't just use gtk.StatusIcon.set_from_file? It works fine with transparent images.

As for your second question, I highly doubt that it is possible to use pango on a gtk.StatusIcon.
Why do you need to write text on the icon?

DoR
I'm writing an application to check Google services and put the count of unread messages onto the status icon, so you can see at a glance how many messages there are. So far as I know that only gives me two options: write on the icon or load images of numbers. I'd rather write if at all possible to let the user customize the font.
Raugturi
I think I came up with a solution but won't be able to test it until tonight. I should be able to load the background image, write on it, save that to a temp file and then use set_from_file on that.
Raugturi