1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| import gtk
import gtk.gdk
class GtkNotif:
def __init__(self):
self.status = gtk.StatusIcon()
self.status.set_from_icon_name("start-here")
self.status.set_tooltip("Clique-moi!")
self.status.connect('activate', self.ev_clic_icon)
self.status.connect('popup-menu', self.ev_right_clic_icon)
self.status.set_visible(True)
def ev_clic_icon(self, icon):
print "Clic !"
win = gtk.Window(gtk.WINDOW_POPUP)
r = self.status.get_geometry()[1]
pos_x = r.x
pos_y = r.y + r.height
l = gtk.Label(" Hello ! ")
b = gtk.Button()
b.set_image(gtk.image_new_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU))
b.set_relief(gtk.RELIEF_NONE)
b.connect('clicked', self.ev_close_win, win)
hb = gtk.HBox()
hb.pack_start(l, True, True)
hb.pack_start(b, False, True)
win.set_decorated(False)
win.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse('#ffff77'))
win.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_NOTIFICATION)
win.add(hb)
win.show_all()
win.move(pos_x, pos_y)
win.set_keep_above(True)
return
def ev_close_win(self, button, window):
window.destroy()
return
def ev_right_clic_icon(self, icon, event_button, event_time):
item_quit = gtk.ImageMenuItem(gtk.STOCK_QUIT)
item_quit.connect('activate', gtk.main_quit)
menu = gtk.Menu()
menu.append(item_quit)
menu.show_all()
menu.popup(None, None, gtk.status_icon_position_menu, event_button, event_time, icon)
return
def main(self):
gtk.main()
return 0
# Lancer le programme
GtkNotif().main() |
Partager