Skip to content Skip to sidebar Skip to footer

How To Make Gtk.layout Transparent

don be afraid of that big class - it was interesting for me to write so it could work in that universal way. it could be the parent-class for transparent elements, and not-parent.

Solution 1:

Very nice... I've been learning this stuff and I like your code.

From the pygtk manual (emphasis added):

The gtk.Layout can also be drawn on similar to drawing on a gtk.DrawingArea. When handling expose events on a gtk.Layout, you must draw to the window specified by the bin_window attribute rather than the widget window attribute.

I think in your function you are getting the window attribute not the bin_window for cairo to draw on.

Modify the expose function to this:

@staticmethoddefexpose (widget, event):
    if'gtk.Layout'instr(type(widget)):
        cr=widget.bin_window.cairo_create()
    else:
        cr = widget.window.cairo_create()
    cr.set_operator(cairo.OPERATOR_CLEAR)
    cr.rectangle(event.area)
    cr.fill()
    cr.set_operator(cairo.OPERATOR_OVER)
    try:
        widget.rgba
    except AttributeError:
        widget.rgba=(0.0,0.0,0.0,0.0)
    cr.set_source_rgba(*widget.rgba)
    cr.rectangle(event.area)
    cr.fill()  

Post a Comment for "How To Make Gtk.layout Transparent"