Reply
Thread Tools
Posts: 25 | Thanked: 8 times | Joined on Feb 2008
#1
I'm trying to create a button that is the shape of its image (instead of rectangular). From my research, it seems that the way to do this is with shape_combine_mask, which makes all the non-mask parts of the button transparent and thus displays in the desired shape.

However, I'm not getting anywhere in actually making it work. Here's my best guess (in Python):

Code:
PixBuf = gtk.gdk.pixbuf_new_from_file("image.png")
Image = gtk.image_new_from_pixbuf(PixBuf)
Button = gtk.Button()
Button.set_image(Image)
MapMask = PixBuf.render_pixmap_and_mask()
Mask = MapMask[1]
self.add(Button)
Button.shape_combine_mask(Mask, 0, 0)
Button.show()
self.show()
This gets me a button with the correct image, but no masking. Can anybody spot what I'm doing wrong?

Thanks!
 
pycage's Avatar
Posts: 3,404 | Thanked: 4,474 times | Joined on Oct 2005 @ Germany
#2
Make sure that the Pixbuf has an alpha channel. And you may have to give some alpha threshold value in render_pixmap_and_mask(threshold).
Pixbufs support 256 levels of transparency while a mask only knows two levels (transparent and opaque).
The threshold determines where the distinction is made between transparent and opaque. The default value that is used when not specifiying a threshold is 127, which means that only pixels below 50% transparency will be transparent in the mask.
 
Posts: 35 | Thanked: 5 times | Joined on Sep 2007
#3
Hi, did you get it working? Can you explain what you did to us?

How would I setup a frame background so that it is semitransparent? I'm thinking about desktop homeitem now. Hmm... I think I have to test what happens when I add labels on that frame box too.
 
Posts: 25 | Thanked: 8 times | Joined on Feb 2008
#4
Originally Posted by icer View Post
Hi, did you get it working? Can you explain what you did to us?

How would I setup a frame background so that it is semitransparent? I'm thinking about desktop homeitem now. Hmm... I think I have to test what happens when I add labels on that frame box too.
My hope was also for a desktop applet, but I still haven't been able to get anything working.

I'm wondering if perhaps it's a limitation of the platform. I notice that the weather applet seems to capture the surrounding background and draw it across itself, so perhaps that is a possible solution.

If anybody finds a working setup, we'd love to hear about it.
 
Posts: 35 | Thanked: 5 times | Joined on Sep 2007
#5
This is not directly related to this issue but I thought I post this here anyway.

So I was struggling to get an image to show up on the applet. I used the set_from_file method and pyphantom IDE(see maemo garage if you want to use it) for developing the home item. While developing in IDE I put the images on src or pixmaps directory. If I put the images on src then I just used the image name: image.set_from_file("lake.png"). However if I used the pixmaps folder I had to supply a relative path: image.set_from_file("../pixmaps/lake.png"). Then the images would show up on the IDE.

Now I ran a test on the IT and the images did not show up. I opened the python file with vi and setup an absolute path for the images. Now they show up on IT too. IIRC the images were installed on the /usr/share/pixmaps/applicationname folder.

Ok... back to topic. I read on Khertans blog that he is studying the transparency too.

I tried to fiddle with the transparency too. There are some examples for python applications about it. Though not directly for home applets. What I found out is that in one step I was setting a rgba colormap but that method did not work. Here are few lines as an example:
e = gtk.EventBox()
rgba = gtk.gdk.Screen().get_rgba_colormap()
e.set_colormap(rgba)

So the code breaks on that last line. and the error I get is:
TypeError: GtkWidget.set_colormap() argument 1 must be gtk.gdk.Colormap, not None

So maybe the colormap methods are not ready or that particular way of coding cannot be applied in this context. I don't know.
 
Khertan's Avatar
Posts: 1,012 | Thanked: 817 times | Joined on Jul 2007 @ France
#6
rgba = gtk.gdk.Screen().get_rgba_colormap()
e.set_colormap(rgba)
Hum you are lucky ... gtk.gdk.Screen().get_rgba_colormap() give me a segfault !
 
Posts: 25 | Thanked: 8 times | Joined on Feb 2008
#7
Originally Posted by icer View Post
I tried to fiddle with the transparency too. There are some examples for python applications about it. Though not directly for home applets. What I found out is that in one step I was setting a rgba colormap but that method did not work. Here are few lines as an example:
e = gtk.EventBox()
rgba = gtk.gdk.Screen().get_rgba_colormap()
e.set_colormap(rgba)

So the code breaks on that last line. and the error I get is:
TypeError: GtkWidget.set_colormap() argument 1 must be gtk.gdk.Colormap, not None

So maybe the colormap methods are not ready or that particular way of coding cannot be applied in this context. I don't know.
From the documentation for gtk.gdk.Screen.get_rgba_colormap

Returns : a gtk.gdk.Colormap for use with windows with an alpha channel or None if the capability is not available.
It's returning None, so it sounds like the IT doesn't support gtk.gdk.Screen alphas. But other desktop applets have transparent backgrounds (or are at least emulating them somehow), so we know it can be done. It's just a question of can it be done via the Python bindings?
 
Posts: 35 | Thanked: 5 times | Joined on Sep 2007
#8
Lol... ok. I tried it as you said:
...
rgba = gtk.gdk.Screen.get_rgba_colormap()

Now it says:
TypeError: descriptor 'get_rgba_colormap' of 'gtk.gdk.Screen' object needs an argument

But in the API it does not say anything about arguments. So doesn't look good really.
 
Khertan's Avatar
Posts: 1,012 | Thanked: 817 times | Joined on Jul 2007 @ France
#9
But if you find a solution spiritgeek i 'm interested, i m looking how to do transparent python applet since a few weeks now !
 
Posts: 25 | Thanked: 8 times | Joined on Feb 2008
#10
It looks like the IT is handling the "home" portion of the desktop different than other areas of the desktop. The code for my task navigator panel sample produces a button with a transparent background without any problem. But the exact same code as a home applet (just changing hildondesktop.TaskNavigatorItem to hildondesktop.HomeItem) produces a button with a white background. I don't know why it's different, but we may have to figure that out to see if there's a way around it.
 
Reply


 
Forum Jump


All times are GMT. The time now is 05:56.