Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/sugar/browser/NotificationBar.py
blob: c9b3b8aff0508d69c61c465c6bcdd7b8039e9f67 (plain)
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
import pygtk
pygtk.require('2.0')
import gtk
import gobject

class NotificationBar(gtk.HBox):
	__gsignals__ = {
		'action': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
				  ([gobject.TYPE_STRING]))
	}

	def __init__(self):
		gtk.HBox.__init__(self, False, 12)

		self.set_name("notif bar")
		self.set_border_width(3)
		
		self._icon = gtk.Image()
		self.pack_start(self._icon, False)
				
		self._text_label = gtk.Label()
		self._text_label.set_alignment(0.0, 0.5)
		self.pack_start(self._text_label)
		self._text_label.show()

		self._action_button = gtk.Button()
		self._action_button.connect('clicked', self.__button_clicked)
		self.pack_start(self._action_button, False)
		self._action_button.show()

		self.connect('expose_event', self.expose)

	def expose(self, widget, event):
		rect = self.get_allocation()
		ctx = widget.window.cairo_create()
		
		ctx.new_path()
		ctx.rectangle(rect.x, rect.y, rect.width, rect.height)
		ctx.set_source_rgb(0.56 , 0.75 , 1)
		ctx.fill_preserve()
		ctx.set_source_rgb(0.16 , 0.35 , 0.6)
		ctx.stroke()
		
		return False

	def set_icon(self, icon_name):
		self._icon.set_from_icon_name(icon_name, gtk.ICON_SIZE_BUTTON)
		self._icon.show()
	
	def set_text(self, text):
		self._text_label.set_markup(text)
	
	def set_action(self, action_id, action_text):
		self._action_id = action_id
		self._action_button.set_label(action_text)
		
	def __button_clicked(self, button):
		self.emit("action", self._action_id)