Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/activities/web/linksview.py
blob: 92d7026d79b5d5caf0cb608614040d4804412025 (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# Copyright (C) 2006, Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

import gtk
import hippo

from sugar.graphics.bubble import Bubble
from sugar.graphics.iconcolor import IconColor
from sugar.graphics import style

class LinksView(hippo.Canvas):
	def __init__(self, model, browser):
		hippo.Canvas.__init__(self)

		self._bubbles = {}
		self._browser = browser

		self._box = hippo.CanvasBox()
		style.apply_stylesheet(self._box, 'links.Box')
		self.set_root(self._box)

		for link in model:
			self._add_link(link)

		model.connect('link_added', self._link_added_cb)
		model.connect('link_removed', self._link_removed_cb)

	def _add_link(self, link):
		if len(self._bubbles) == 0:
			self.show()

		color = IconColor(link.buddy.get_color())

		bubble = Bubble(color=color)
		style.apply_stylesheet(bubble, 'links.Bubble')
		self._box.append(bubble)

		text = hippo.CanvasLink(text=link.title)
		text.connect('activated', self._link_activated_cb, link)
		style.apply_stylesheet(text, 'links.Text')
		bubble.append(text, hippo.PACK_EXPAND)

		self._bubbles[link] = bubble

	def _remove_link(self, link):
		bubble = self._bubbles[link]
		self._box.remove(bubble)

		del self._bubbles[link]

		if len(self._bubbles) == 0:
			self.hide()

	def _link_added_cb(self, model, link):
		self._add_link(link)

	def _link_removed_cb(self, model, link):
		self._removed_link(link)

	def _link_activated_cb(self, link_item, link):
		self._browser.load_url(link.url)