views:

110

answers:

1

Is there a way to make a PyGTK widget partly transparent, so that the widgets behind it can be seen through it? Specifically I'm trying to do this on a label, for typographic effect; I don't want to change the color instead, as it may not look right on all themes.

+2  A: 

No, not possible. It is possible to make entire windows partially transparent, if window manager supports compositing, but not individual widgets.

I guess what you want can be achieved differently by "blending" colors:

def blend (color1, color2, weight = 0.5):
    return gtk.gdk.Color (
        color1.red_float   * weight + color2.red_float   * (1 - weight),
        color1.green_float * weight + color2.green_float * (1 - weight),
        color1.blue_float  * weight + color2.blue_float  * (1 - weight))

for state in gtk.StateType.__enum_values__:
    label.modify_fg (state, blend (label.style.fg[state], label.style.bg[state]))

To make it completely correct you can also listen to "style-set" signal.

doublep
Thanks, I'll try that.
snostorm
You can make gdk windows transparent using shape combine masks in non-composited window managers. It's pretty ugly, but you could mimic a label by using pixmaps drawn on windows with their inverse as the combine mask.
Ali A