Hi,
The code I've been looking at is a fairly simple widget in Extras called
countdown-home. 95% of it is "fluff" and has nothing to do with this problem
so I've attached a working Python Desktop Widget (very simple, just a couple
gtk.Label's). countdown-home is available from here:
http://repository.maemo.org/extras/pool/fremantle/free/source/c/countdown-home/
(I tried attaching the C file, but the list said it was too big).
If you could try to translate the cairo code from coundown-home into the
Python example, that would be awesome!
Thanks.
On Wed, Dec 23, 2009 at 3:43 PM, Anderson Lizardo <
anderson.liza...@openbossa.org> wrote:
> On Sat, Dec 19, 2009 at 3:41 PM, Brent Chiodo <bchi...@gmail.com> wrote:
> > Hi,
> >
> > I'm trying to make the background of a Desktop Widget semi-transparent
> using
> > the cairo graphics library. The widget is written in Python and the only
> > examples of this I've found are using C (I don't know much C -- I wasn't
> > even able to apply the examples to Python).
>
> If you send the links to the C examples you found, I can try
> translating them to Python for you (I'll be able to try only on
> scratchbox though, as I'll not have a N900 accessible until next
> year).
>
> Regards,
> --
> Anderson Lizardo
>
--
Best Regards,
Brent Chiodo
import gtk
import hildondesktop
import cairo
import hildon
import gobject
class CairoExample(hildondesktop.HomePluginItem):
def __init__(self):
hildondesktop.HomePluginItem.__init__(self)
self.label1 = gtk.Label()
self.label1.set_text("Hello")
self.label1.set_padding(15, 10)
self.label2 = gtk.Label()
self.label2.set_text("World")
self.label2.set_padding(15, 10)
self.hbox = gtk.HBox()
self.hbox.pack_start(self.label1)
self.hbox.pack_end(self.label2)
screen = self.get_screen()
colormap = screen.get_rgba_colormap()
self.set_colormap(colormap)
self.connect("expose-event", self.expose)
self.hbox.show_all()
self.add(self.hbox)
def expose(self, widget, event): # This currently doesn't work
cr = self.hbox.window.cairo_create()
cr.set_source_rgba(1.0, 1.0, 1.0, 0.0) # Transparent
# Draw the background
cr.set_operator(cairo.OPERATOR_SOURCE)
cr.paint()
# draw rounded rect
width, height = self.allocation[2], self.allocation[3]
#/* a custom shape, that could be wrapped in a function */
x0 = 0 #/*< parameters like cairo_rectangle */
y0 = 0
radius = min(15, width/2, height/2) #/*< and an approximate curvature radius */
x1 = x0 + width
y1 = y0 + height
cr.move_to (x0, y0 + radius)
cr.arc (x0 + radius, y0 + radius, radius, 3.14, 1.5 * 3.14)
cr.line_to (x1 - radius, y0)
cr.arc (x1 - radius, y0 + radius, radius, 1.5 * 3.14, 0.0)
cr.line_to (x1 , y1 - radius)
cr.arc (x1 - radius, y1 - radius, radius, 0.0, 0.5 * 3.14)
cr.line_to (x0 + radius, y1)
cr.arc (x0 + radius, y1 - radius, radius, 0.5 * 3.14, 3.14)
cr.close_path ()
cr.set_source_rgba (0.5, 0.5, 0.5, 0.5)
cr.fill_preserve ()
return False
hd_plugin_type = CairoExample
if __name__ == "__main__":
gobject.type_register(hd_plugin_type)
obj = gobject.new(hd_plugin_type, plugin_id="plugin_id")
obj.show_all()
gtk.main()
_______________________________________________
maemo-developers mailing list
maemo-developers@maemo.org
https://lists.maemo.org/mailman/listinfo/maemo-developers