2006-10-13 18:05:48 +02:00
|
|
|
import gtk
|
2006-10-13 15:46:11 +02:00
|
|
|
import hippo
|
|
|
|
|
|
|
|
from sugar.graphics.bubble import Bubble
|
2006-10-13 18:05:48 +02:00
|
|
|
from sugar.graphics.iconcolor import IconColor
|
|
|
|
from sugar.graphics import style
|
2006-10-13 15:46:11 +02:00
|
|
|
|
|
|
|
class LinksView(hippo.Canvas):
|
2006-10-13 19:04:04 +02:00
|
|
|
def __init__(self, model, browser):
|
2006-10-13 15:46:11 +02:00
|
|
|
hippo.Canvas.__init__(self)
|
|
|
|
|
|
|
|
self._bubbles = {}
|
2006-10-13 19:04:04 +02:00
|
|
|
self._browser = browser
|
2006-10-13 15:46:11 +02:00
|
|
|
|
2006-10-13 19:52:44 +02:00
|
|
|
self._box = hippo.CanvasBox()
|
|
|
|
style.apply_stylesheet(self._box, 'links.Box')
|
2006-10-13 15:46:11 +02:00
|
|
|
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):
|
2006-10-13 20:55:33 +02:00
|
|
|
if len(self._bubbles) == 0:
|
|
|
|
self.show()
|
|
|
|
|
2006-10-13 18:05:48 +02:00
|
|
|
color = IconColor(link.buddy.get_color())
|
2006-10-13 19:04:04 +02:00
|
|
|
|
2006-10-13 18:05:48 +02:00
|
|
|
bubble = Bubble(color=color)
|
2006-10-13 19:52:44 +02:00
|
|
|
style.apply_stylesheet(bubble, 'links.Bubble')
|
2006-10-13 18:05:48 +02:00
|
|
|
self._box.append(bubble)
|
2006-10-13 15:46:11 +02:00
|
|
|
|
2006-10-13 19:04:04 +02:00
|
|
|
text = hippo.CanvasLink(text=link.title)
|
|
|
|
text.connect('activated', self._link_activated_cb, link)
|
2006-10-13 19:52:44 +02:00
|
|
|
style.apply_stylesheet(text, 'links.Text')
|
2006-10-13 19:04:04 +02:00
|
|
|
bubble.append(text, hippo.PACK_EXPAND)
|
|
|
|
|
2006-10-13 15:46:11 +02:00
|
|
|
self._bubbles[link] = bubble
|
|
|
|
|
|
|
|
def _remove_link(self, link):
|
|
|
|
bubble = self._bubbles[link]
|
|
|
|
self._box.remove(bubble)
|
|
|
|
|
|
|
|
del self._bubbles[link]
|
|
|
|
|
2006-10-13 20:55:33 +02:00
|
|
|
if len(self._bubbles) == 0:
|
|
|
|
self.hide()
|
|
|
|
|
2006-10-13 15:46:11 +02:00
|
|
|
def _link_added_cb(self, model, link):
|
|
|
|
self._add_link(link)
|
|
|
|
|
|
|
|
def _link_removed_cb(self, model, link):
|
|
|
|
self._removed_link(link)
|
2006-10-13 19:04:04 +02:00
|
|
|
|
|
|
|
def _link_activated_cb(self, link_item, link):
|
|
|
|
self._browser.load_url(link.url)
|