-
Notifications
You must be signed in to change notification settings - Fork 0
/
notify.py
105 lines (86 loc) · 3.73 KB
/
notify.py
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# coding: utf-8
import pygtk
pygtk.require('2.0')
import gtk
class Notify(gtk.HBox):
def __init__(self):
super(Notify, self).__init__()
self.icons = []
self.contents = None
self.changing_style = False
self.main_hbox = gtk.HBox(False, 8)
self.main_hbox.set_border_width(4)
self.icon_area = gtk.HBox(True, 2)
self.main_hbox.pack_start (self.icon_area, False, True, 2)
self.msg_area = gtk.HBox(True, 2)
self.main_hbox.pack_start (self.msg_area, False, True, 0)
self.action_area = gtk.HBox(True, 2)
self.main_hbox.pack_end (self.action_area, False, True, 0)
self.pack_start(self.main_hbox, True, True, 0)
self.set_app_paintable(True)
self.connect("expose-event", self.paint)
self.main_hbox.connect("style-set", self.on_style_set)
def add_icon(self, icon):
"""Adiciona um icone ao notify"""
self.remove_icon()
if icon == 'erro':
self.erro = gtk.image_new_from_stock(gtk.STOCK_DIALOG_ERROR, gtk.ICON_SIZE_MENU)
self.icons.append(self.erro)
self.icon_area.pack_start (self.erro, False, True, 2)
elif icon == 'apply':
self.apply = gtk.image_new_from_stock(gtk.STOCK_APPLY, gtk.ICON_SIZE_MENU)
self.icons.append(self.apply)
self.icon_area.pack_start (self.apply, False, True, 2)
elif icon == 'info':
self.info = gtk.image_new_from_stock(gtk.STOCK_DIALOG_INFO, gtk.ICON_SIZE_MENU)
self.icons.append(self.info)
self.icon_area.pack_start (self.info, False, True, 2)
elif icon == 'warning':
self.warning = gtk.image_new_from_stock(gtk.STOCK_DIALOG_WARNING, gtk.ICON_SIZE_MENU)
self.icons.append(self.warning)
self.icon_area.pack_start (self.warning, False, True, 2)
def remove_icon(self):
if self.icons:
for icon in self.icons:
self.icon_area.remove (icon)
self.icons = []
def add_msg(self):
"""Adiciona um label ao notify"""
self.msg = gtk.Label()
self.msg_area.pack_start (self.msg, False, True, 0)
return self.msg
def add_button(self):
"""Adiciona botão de fechar ao notify"""
close_button = gtk.Button()
close = gtk.image_new_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU)
close_button.add(close)
close_button.set_relief(gtk.RELIEF_NONE)
self.action_area.pack_start (close_button, False, True, 0)
return close_button
def paint(self, w, event):
"""Aplica um style no objeto para que ele tenha borda com a cor do tooltip"""
gtk.Style.paint_flat_box(w.style,
w.window,
gtk.STATE_NORMAL,
gtk.SHADOW_OUT,
None,
w,
"tooltip",
w.allocation.x + 1,
w.allocation.y + 1,
w.allocation.width - 2,
w.allocation.height - 2)
return False
def on_style_set(self, w, style):
"""Implementa um hack necessario para usar as cores de fundo do tooltip"""
if self.changing_style:
return
window = gtk.Window(gtk.WINDOW_POPUP);
window.set_name("gtk-tooltip")
window.ensure_style()
style = window.get_style()
self.changing_style = True
self.set_style(style)
self.changing_style = False
window.destroy()
self.queue_draw()