hi everyone
im making a transparent window. look pretty cool (python gtk cairo)
i added some buttons and they look very ugly
so add just images instead buttons, look grate again,even the animated and transparent images look ok, but image don't have "clicked" events
then put images into eventbox, work, but a rectangle surround the image, eventbox is not transparent
there is some way to make them transparent?
i lend here an example script and a image. hope some one can help me =3
im making a transparent window. look pretty cool (python gtk cairo)
i added some buttons and they look very ugly
so add just images instead buttons, look grate again,even the animated and transparent images look ok, but image don't have "clicked" events
then put images into eventbox, work, but a rectangle surround the image, eventbox is not transparent
there is some way to make them transparent?
i lend here an example script and a image. hope some one can help me =3
Code:
import sys
import gobject
import pango
sys.path[:0] = ['/usr/local/lib/python2.4/site-packages/gtk-2.0']
import pygtk
pygtk.require('2.0')
import gtk
from gtk import gdk
import cairo
if gtk.pygtk_version < (2,9,0):
print "PyGtk 2.9.0 or later required"
raise SystemExit
supports_alpha = False
def ejemplo(widget,event,data="....."):
print data
def expose(widget, event):
global supports_alpha
cr = widget.window.cairo_create()
if supports_alpha == True:
cr.set_source_rgba(0, 0, 0, 0.6) # Transparent
else:
cr.set_source_rgb(1.0, 1.0, 1.0) # Opaque white
# Draw the background
cr.set_operator(cairo.OPERATOR_SOURCE)
cr.paint()
cr.fill()
cr.stroke()
return False
def screen_changed(widget, old_screen=None):
global supports_alpha
# To check if the display supports alpha channels, get the colormap
screen = widget.get_screen()
colormap = screen.get_rgba_colormap()
if colormap == None:
print 'Your screen does not support alpha channels!'
colormap = screen.get_rgb_colormap()
supports_alpha = False
else:
print 'Your screen supports alpha channels!'
supports_alpha = True
# Now we have a colormap appropriate for the screen, use it
widget.set_colormap(colormap)
return False
def main(args):
win = gtk.Window()
win.set_title('Alpha Demo')
win.connect('delete-event', gtk.main_quit)
win.set_app_paintable(True)
win.connect('expose-event', expose)
win.connect('screen-changed', screen_changed)
win.set_decorated(True)
win.add_events(gdk.BUTTON_PRESS_MASK)
win.set_default_size(920,460)
#win.connect('button-press-event', clicked)
screen_changed(win)
hbox = gtk.HBox(False,0)
ima = gtk.Image()
ima.set_from_file("folder_orange_open.png")
bot = gtk.Button()
bot.connect("clicked",ejemplo,"folder_orange_open.png")
bot.add(ima)
hbox.pack_start(bot,False,False,20)
ima2 = gtk.Image()
ima2.set_from_file("folder_orange_open.png")
hbox.pack_start(ima2,False,False,20)
ima3 = gtk.Image()
ima3.set_from_file("folder_orange_open.png")
e = gtk.EventBox()
e.add(ima3)
e.connect("button_press_event",ejemplo,"eventbox")
hbox.pack_start(e,False,False,20)
vbox = gtk.VBox(False,0)
vbox.pack_start(hbox,False,True,50)
win.add(vbox)
win.show_all()
gtk.main()
return True
if __name__ == '__main__':
sys.exit(main(sys.argv))