By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,673 Members | 1,249 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,673 IT Pros & Developers. It's quick & easy.

made a eventbox invisible in a transparent window??

P: 1
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

Expand|Select|Wrap|Line Numbers
  1. import sys
  2. import gobject
  3. import pango
  4. sys.path[:0] = ['/usr/local/lib/python2.4/site-packages/gtk-2.0']
  5. import pygtk
  6. pygtk.require('2.0')
  7. import gtk
  8. from gtk import gdk
  9. import cairo
  10.  
  11. if gtk.pygtk_version < (2,9,0):
  12.     print "PyGtk 2.9.0 or later required"
  13.     raise SystemExit
  14. supports_alpha = False
  15.  
  16. def ejemplo(widget,event,data="....."):
  17.     print data
  18.  
  19. def expose(widget, event):
  20.     global supports_alpha
  21.  
  22.     cr = widget.window.cairo_create()
  23.  
  24.     if supports_alpha == True:
  25.         cr.set_source_rgba(0, 0, 0, 0.6) # Transparent
  26.     else:
  27.         cr.set_source_rgb(1.0, 1.0, 1.0) # Opaque white
  28.  
  29.     # Draw the background
  30.     cr.set_operator(cairo.OPERATOR_SOURCE)
  31.     cr.paint()
  32.  
  33.     cr.fill()
  34.     cr.stroke()
  35.     return False
  36.  
  37. def screen_changed(widget, old_screen=None):
  38.  
  39.     global supports_alpha
  40.  
  41.     # To check if the display supports alpha channels, get the colormap
  42.     screen = widget.get_screen()
  43.     colormap = screen.get_rgba_colormap()
  44.     if colormap == None:
  45.         print 'Your screen does not support alpha channels!'
  46.         colormap = screen.get_rgb_colormap()
  47.         supports_alpha = False
  48.     else:
  49.         print 'Your screen supports alpha channels!'
  50.         supports_alpha = True
  51.  
  52.     # Now we have a colormap appropriate for the screen, use it
  53.     widget.set_colormap(colormap)
  54.  
  55.     return False
  56.  
  57. def main(args):
  58.     win = gtk.Window()
  59.  
  60.     win.set_title('Alpha Demo')
  61.     win.connect('delete-event', gtk.main_quit)
  62.     win.set_app_paintable(True)
  63.     win.connect('expose-event', expose)
  64.     win.connect('screen-changed', screen_changed)
  65.     win.set_decorated(True)
  66.     win.add_events(gdk.BUTTON_PRESS_MASK)
  67.     win.set_default_size(920,460) 
  68.     #win.connect('button-press-event', clicked)    
  69.     screen_changed(win)
  70.     hbox = gtk.HBox(False,0)
  71.     ima = gtk.Image()
  72.     ima.set_from_file("folder_orange_open.png")
  73.     bot = gtk.Button()
  74.     bot.connect("clicked",ejemplo,"folder_orange_open.png")
  75.     bot.add(ima)
  76.     hbox.pack_start(bot,False,False,20)
  77.  
  78.     ima2 = gtk.Image()
  79.     ima2.set_from_file("folder_orange_open.png")
  80.     hbox.pack_start(ima2,False,False,20)
  81.  
  82.     ima3 = gtk.Image()
  83.     ima3.set_from_file("folder_orange_open.png")
  84.     e = gtk.EventBox()
  85.     e.add(ima3)
  86.     e.connect("button_press_event",ejemplo,"eventbox")
  87.     hbox.pack_start(e,False,False,20)
  88.  
  89.  
  90.     vbox = gtk.VBox(False,0)
  91.     vbox.pack_start(hbox,False,True,50)    
  92.     win.add(vbox)
  93.     win.show_all()
  94.     gtk.main()
  95.  
  96.     return True
  97.  
  98. if __name__ == '__main__':
  99.     sys.exit(main(sys.argv))    
  100.  
  101.  
Attached Images
File Type: png folder_orange_open.png (3.2 KB, 141 views)
Aug 26 '12 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.