maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   Shaped widgets? (transparent background) (https://talk.maemo.org/showthread.php?t=16720)

SpiritGeek 2008-02-16 13:33

Shaped widgets? (transparent background)
 
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 2008-02-18 09:33

Re: Shaped widgets? (transparent background)
 
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.

icer 2008-02-19 12:32

Re: Shaped widgets? (transparent background)
 
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. :confused:

SpiritGeek 2008-02-19 12:41

Re: Shaped widgets? (transparent background)
 
Quote:

Originally Posted by icer (Post 144588)
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. :confused:

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. :)

icer 2008-02-20 10:51

Re: Shaped widgets? (transparent background)
 
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 2008-02-20 11:20

Re: Shaped widgets? (transparent background)
 
Quote:

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 !

SpiritGeek 2008-02-20 11:34

Re: Shaped widgets? (transparent background)
 
Quote:

Originally Posted by icer (Post 145177)
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

Quote:

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?

icer 2008-02-20 13:46

Re: Shaped widgets? (transparent background)
 
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 2008-02-20 15:18

Re: Shaped widgets? (transparent background)
 
But if you find a solution spiritgeek i 'm interested, i m looking how to do transparent python applet since a few weeks now !

SpiritGeek 2008-02-20 22:01

Re: Shaped widgets? (transparent background)
 
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.


All times are GMT. The time now is 04:14.

vBulletin® Version 3.8.8