Refactor stylsheets code a bit to load the global stylsheet

for all modules.
Implement the links sidebar per discussion with Eben.
This commit is contained in:
Marco Pesenti Gritti
2006-10-19 11:54:51 +02:00
parent e098bdf8eb
commit fafa1ae35e
6 changed files with 83 additions and 73 deletions
+28 -19
View File
@@ -17,16 +17,31 @@
import gtk
import hippo
from sugar.graphics.bubble import Bubble
from sugar.graphics.menu import Menu
from sugar.graphics.menushell import MenuShell
from sugar.graphics.menuicon import MenuIcon
from sugar.graphics.iconcolor import IconColor
from sugar.graphics import style
class LinkIcon(MenuIcon):
def __init__(self, menu_shell, link):
color = IconColor(link.buddy.get_color())
MenuIcon.__init__(self, menu_shell, color=color,
icon_name='activity-web')
self._link = link
def create_menu(self):
menu = Menu(self._link.title)
return menu
class LinksView(hippo.Canvas):
def __init__(self, model, browser):
hippo.Canvas.__init__(self)
self._bubbles = {}
self._icons = {}
self._browser = browser
self._menu_shell = MenuShell(self)
self._box = hippo.CanvasBox()
style.apply_stylesheet(self._box, 'links.Box')
@@ -39,36 +54,30 @@ class LinksView(hippo.Canvas):
model.connect('link_removed', self._link_removed_cb)
def _add_link(self, link):
if len(self._bubbles) == 0:
if len(self._icons) == 0:
self.show()
color = IconColor(link.buddy.get_color())
icon = LinkIcon(self._menu_shell, link)
icon.connect('activated', self._link_activated_cb, link)
style.apply_stylesheet(icon, 'links.Icon')
self._box.append(icon)
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
self._icons[link] = icon
def _remove_link(self, link):
bubble = self._bubbles[link]
self._box.remove(bubble)
icon = self._icons[link]
self._box.remove(icon)
del self._bubbles[link]
del self._icons[link]
if len(self._bubbles) == 0:
if len(self._icons) == 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)
self._remove_link(link)
def _link_activated_cb(self, link_item, link):
self._browser.load_url(link.url)
+4 -11
View File
@@ -16,19 +16,12 @@
import gtk
_screen_factor = gtk.gdk.screen_width() / 1200.0
from sugar.graphics import style
links_Bubble = {
'box-width' : int(250.0 * _screen_factor)
}
links_Text = {
'color' : 0x000000FF,
'font' : '14px',
'padding' : 6
links_Icon = {
'size' : style.standard_icon_size
}
links_Box = {
'background_color' : 0x646464ff,
'padding' : 4
'background_color' : 0x414141ff,
}