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

This is the current code (that doesn't work -- the background appears as a
black box)


   def __init__(self):
      hildondesktop.HomePluginItem.__init__(self)
...
      self.connect("screen-changed", self.screen_changed)
      self.connect("expose-event", self.expose)


   def expose(self, widget, event):
      cr = self.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 ()

      bg_color=gtk.gdk.color_parse("#000000")

      cr.set_source_rgba (bg_color.red / 65535.0, bg_color.green/65535.0,
bg_color.blue/65535.0, float(32767/65535.0))
      cr.fill_preserve ()
      # cr.set_source_rgba (0.5, 0.5, 1.0, 0.8)
      # cr.stroke ()

   def screen_changed(self, widget):
      screen = self.get_screen()
      colormap = screen.get_rgba_colormap()
      self.set_colormap(colormap)

      return False


What I'm trying to do is have the widget appear semi-transparent with
rounded corners (like most widgets look) but the above code does not work at
all. I do not know much about cairo and got most of that code from Khertan's
HomeIP widget for Diablo/Chinook and only modified it a little to work with
Maemo 5.

Any help would be greatly appreciated. I've been "banging my head against a
wall" for a while with this one.

-- 
Best Regards,

Brent Chiodo
_______________________________________________
maemo-developers mailing list
maemo-developers@maemo.org
https://lists.maemo.org/mailman/listinfo/maemo-developers

Reply via email to