[gcompris-devel] how to add alpha to rgb color

Fionn Ziegler fionnziegler at gmail.com
Tue Aug 24 15:55:58 UTC 2010


I changed it using the stroke_color property:
 def get_selected_color(self):
      color = self.colorpicker.get_color();
      g= int((color.green / 65535.0) *255)
      r= int((color.red   / 65535.0) *255)
      b= int((color.blue  / 65535.0) *255)
      return self.tohex(r, g, b)

  def tohex(self,r,g,b):
    hexchars = "0123456789ABCDEF"
    return "#" + hexchars[r / 16] + hexchars[r % 16] + hexchars[g / 16] +
hexchars[g % 16] + hexchars[b / 16] + hexchars[b % 16]

  def draw_point(self,x,y):
      return goocanvas.Rect(parent = self.rootitem,
        x=x,
        y=y,
        width=1,
        height=1,
        stroke_color *= self.get_selected_color()*)


On Sun, Aug 22, 2010 at 10:49 PM, Fionn Ziegler <fionnziegler at gmail.com>wrote:

> Hi,
> I have a gtk.ColorButton() and I want to draw a goocanvas line with the
> selected color (I need a 32 bit rgba color). My problem how to get the rgba
> color-code of the rgb color. Here my test code:
>                 print "gtk.gdk.Color->to_string: %s" % (color.to_string())
>                 print "gtk.gdk.Color: %s" % (color)
>                 print "self.colorpicker.get_alpha(): %s " %
> (self.colorpicker.get_alpha())
> output black:
> gtk.gdk.Color->to_string: #000000000000
> gtk.gdk.Color: #000
> self.colorpicker.get_alpha(): 65535
> output blue:
> gtk.gdk.Color->to_string: #28b2229eca30
> gtk.gdk.Color: #28b2229eca30
> self.colorpicker.get_alpha(): 65535
>
> how to get a rgba code like this:*
> self.rgba_colors['line'] = 0xFFFF40FF*
>
> sorry maybe there is a lack of basic knowlegde but I have no idea how to do
> this,
>
>
> Thanks for any help,
>
> Fionn Ziegler
>



More information about the Gcompris-devel mailing list