![]() |
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") Thanks! |
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. |
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: |
Re: Shaped widgets? (transparent background)
Quote:
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. :) |
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. |
Re: Shaped widgets? (transparent background)
Quote:
|
Re: Shaped widgets? (transparent background)
Quote:
Quote:
|
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. |
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 !
|
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.
|
Re: Shaped widgets? (transparent background)
Hi,
I have not tested if I get anything appearing on the screen but at least python is happy with it: Code:
import gtk Also in pyphantom the code does not work but in the IT itself it's just fine. |
Re: Shaped widgets? (transparent background)
I know this thread started with code snippet in Python, but if you're interested, I wrote a simple example in C. It should show, among some other things, how to use real transparency in a Desktop plugin.
|
Re: Shaped widgets? (transparent background)
Quote:
I'm not a C programmer, but I've tried to sift through your code and find the Python parallels. If I'm understanding it correctly, it looks like the initialization code (__init__ in Python) is example_init(). In there, the relevant bit for transparency seems to be: Code:
rgba_colormap = gdk_screen_get_rgba_colormap(gdk_screen_get_default()); Code:
rgba_colormap = gtk.gdk.screen_get_default().get_rgba_colormap() Anyone have any thoughts? |
Re: Shaped widgets? (transparent background)
Looks like I'm stuck with this. The code is kind of alright but does not work. I need a working example of a complete plugin...
I've been reading these: GTK images: http://www.pygtk.org/pygtk2tutorial/sec-Images.html window compositing: http://library.gnome.org/devel/pygtk...gdkwindow.html Lucas's blog: http://blogs.gnome.org/lucasr/2007/0...ildon-desktop/ However Khertan used frame as the 'root' element or window and not gtk window as the base element and all these examples are based on using windows. Only the gtk tutorials have complete code and don't have the hildon features obviously and I could not find complete program from Lucas either.:confused::( Well the frame looks a bit dull but I can live with it. Anybody know how to stack two images? You know for example I have one image as background and the other image is drawn over the background image. |
Re: Shaped widgets? (transparent background)
This pygtk faq looks promising: http://faq.pygtk.org/index.py?req=sh...=faq08.018.htp
I did some tests and I think it sort of works. Ran a test on the IDE. I need to retest on the IT and also do other tests... I made a composite image of 2 png's but the other image was much smaller than the other so it appeared in the top left corner in the composite image. Anyway I'm not sure how much this concerns the original question about the background of the home plugin. And here is an example how to setup a window background:http://faq.pygtk.org/index.py?req=sh...=faq08.013.htp Except that so far we have used frames. |
Re: Shaped widgets? (transparent background)
Quote:
So replacing Button.shape_combine_mask(Mask, 0, 0) with self.shape_combine_mask(Mask, 0, 0) should do the trick, I think. |
Re: Shaped widgets? (transparent background)
1 Attachment(s)
Googling on this topic, I came across this example of semi-transparent windows with cairo, and to my utter amazement it works perfectly on OS2008!
So I went ahead and remodeled this clock widget to a desktop maemo plugin. Here's how it looks (it's resizable too!) Attachment 1060 And this is the code - following SpiritGeeks example I'll just paste it in :) /usr/share/applications/hildon-home/pyclock.desktop: Code:
[Desktop Entry] Code:
import sys |
Re: Shaped widgets? (transparent background)
Thanks a lot. I tried it out and it works! Though only in device not on pyphantom ide. Well I guess it doesn't matter as long as it works on IT.
Now just need to learn that cairo mumbo jumbo. I got a python program ready for integration with GUI and a complete GUI concept ready too but looks like it's not that trivial task after all. Anyway thanks for the example! :) |
Re: Shaped widgets? (transparent background)
Quote:
Code:
import gtk |
Re: Shaped widgets? (transparent background)
Hey great !
Just a small thing ... my plugin is just an example, but if you use it ... sometimes label is too short for displaying the entire ip. (because it can be created with 'No IP') ... so just do a set_size_request(-1,-1) on it. And THANKS ! I ll try this, maybe now will could have usefull and beautifful widget in python. |
Re: Shaped widgets? (transparent background)
Well, thanks go right back to you! I connect to the tablet via SSH all the time, and even though it's always the same 2 or 3 addresses, this little widget has made my life so much easier. :)
|
Re: Shaped widgets? (transparent background)
Hey thanks for yet another great example! :) I too will use it for sure.
Can you explain a bit this code? Is it so that the method screen_changed is executed every time the window or widget is moved on the desktop? The background method is activated once the screen dims and the IT goes to power save mode? And the foreground is activated once the user does something which brings the IT out of the power save mode? Is that unrealize method used for cleanup when terminating the widget? update is used to periodically fetch the IP. Ok... how would I execute my separate python program and wait for it to output a dictionary? It can take some time before there is any output. I use the dictionary for setting text to the labels on the desktop plugin. Found out howto display an image, though I have tested this in desktop PC and don't have access to the IT atm... anyway here's the code: Code:
image = cairo.ImageSurface.create_from_png("image.png") Almost forgot to mention that this piece of code is inserted in the expose event method. ... and compositing works so that I just draw the second image over first image. :) Dunno if that is really compositing but I get the desired effect done. |
Re: Shaped widgets? (transparent background)
Hi all,
your examples are amazing. I would want to create a application with a transparent background, but not a widget. I mean, not only on the desktop. Is it possible with python and cairo? Thanks |
Re: Shaped widgets? (transparent background)
Why not. Go see www.cairographics.org
I think they have examples there. |
Re: Shaped widgets? (transparent background)
Yes I tried cairo but it needs a compositing manager to manage the transparency, so impossible on maemo.
|
Re: Shaped widgets? (transparent background)
I hope it is not considered 'stealing' of this thread, but I have a question that is very close to the one that was posed here -- I simply want to create a button and supply my own image for it. Techniques in pygtk that I use on my desktop work just fine, but when I run them on my N800, the image is not shown (and no errors). I have tried various techniques with no luck. For example, this works on my desktop but not my N800:
path = os.path.dirname(os.path.abspath(sys.argv[0])) image_file = os.path.join(path, "mephem_672x422.jpg") image = gtk.Image() image.set_from_file(image_file) image.show b=gtk.Button() window.add(b) b.connect("clicked",chart_object_info_basic,object ,local) b.set_image(image) #b.set_image(gtk.image_new_from_file(image_file)) b.set_size_request(672,422) b.set_label('') b.show() One interesting thing I noticed is that the 'set_size_request' command is not needed on my desktop, but it is needed on the N800 -- otherwise an error occurs: GtkWarning: gtk_widget_size_allocate(): attempt to allocate widget with width -8 and height 0 Thanks EDIT: It looks like the "set_label('')" was messing me up, so I took it out! Strange that there are these subtle behavior differences between the desktop and N800... |
Re: Shaped widgets? (transparent background)
Hi, I'm starting working with N800 device.
I have read this post and I've a little trouble. I'm trying to make a desktop applet with transparent background, but it fails when I try to start it. I create a box (instead of the label in the IP example) and I fill it with gtk.Entry() and gtk.Button() objects. If I fill it with labels and no one of that objects it runs fine. Can anyone help me? Thanks! |
Re: Shaped widgets? (transparent background)
I was also looking into the exactly same thing of adding buttons to the view. With labels, it runs fine, but with buttons, it crashes the desktop.
|
Re: Shaped widgets? (transparent background)
The same problem for me, It only works well with labels: No buttons, no TreeView
What could be the problem? |
Re: Shaped widgets? (transparent background)
Hi folks:
I am also trying to write a desktop Python applet, and the 'cairo' stuff works fine -- but I want to add some 'buttons' to the application. Can anyone give me some *simple* code to show a mixture of the two in the same applet? Or am I going to run into the same label/button problem as is being mentioned above? It *appears* as though my request to add buttons is being totally ignored -- but I have noticed strange behavior (sometimes) when something is wong on an applet i.e. it almost looks like it uses a previously-worked 'cached' version instead of the current one in that case (????). |
Re: Shaped widgets? (transparent background)
All the code samples that I've seen on the net are using only labels. If I just replace the label for a simple bottom it crash, and for now, nobody reply with any solution, so maybe it's a bug on Python libhildondesktop bindings and can't be done with current version.
|
Re: Shaped widgets? (transparent background)
Hmmm...unless I am mistaken, this current 'limitation' of the Python libhildondesktop bindings means that there is no way to 'influence' the behavior of a desktop applet once it is running i.e. no buttons, menus, etc. to change settings. True?
|
Re: Shaped widgets? (transparent background)
Quote:
It has a button but it hasn't transparency. I have the code in somewhere, I will have to search and test it. If it works I will come here with an example (on the weekend). |
Re: Shaped widgets? (transparent background)
It might either be bug in the python implementation or in the actual implementation. Can't tell. I can try to ask Rodrigo though.
|
Re: Shaped widgets? (transparent background)
While we are waiting (hopefully) for a solution to this matter, I was wondering if it was possible to have the transparent widgets respond to *other* events e.g. mouse clicks, mouse drags, focus, etc.?
I am a total newbie at this stuff, but I tried adding this code to my app and it was (apparently) ignored: self.connect("button-press-event", self.toggle_text) self.connect("drag-begin", self.toggle_text) self.connect("enter-notify-event", self.toggle_text) self.connect("focus", self.toggle_text) def toggle_text(self, widget, event): if text_flag == "on": text_flag = "off" else: text_flag = "on" self.update() return Even though I could click, drag, etc the widget, it didn't appear as though my 'text_toggle' module was being called. I also tried adding this: self.add_events(gtk.gdk.KEY_PRESS_MASK | gtk.gdk.POINTER_MOTION_MASK | gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.SCROLL_MASK) ...but that didn't work either. You folks are a lot smarter than me, so what am I doing wrong? Or is this another limitation? Thanks |
Re: Shaped widgets? (transparent background)
I tested it and here are my conclusions:
* You can add buttons when you have a bored applet without transparency. * Same problem of yours if the applet have transparency. |
Re: Shaped widgets? (transparent background)
Yerga:
Using the examples of 'transparent shaped widgets' from this current thread, can you tell me (offhand) what minimal amount would need to be *removed* (i.e. 'transparency') in order for buttons to work? Also, can you post an example (code) of such a widget? My own applet is stalled out -- waiting for some sort of resolution. Otherwise, I would need to release it without any 'controls' at all (buttons, menus, etc). :( |
Re: Shaped widgets? (transparent background)
Quote:
Code:
import gtk Other thing you could look, is add an option in the Home menu to control the applet settings but I don't know how it works. |
Re: Shaped widgets? (transparent background)
You can look in source code of the last HomeIP or other Home* applet i ve made. Source is available in extras repository.
If you need explain just ask, but it s in fact very easy to do. |
Re: Shaped widgets? (transparent background)
Khertan:
I think I briefly looked at your apps in the past for the 'secret' -- but do your apps use 'shaped' widgets? I definitely want to integrate Cairo (drawing) into my own. |
All times are GMT. The time now is 11:31. |
vBulletin® Version 3.8.8