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

View File

@ -17,16 +17,31 @@
import gtk import gtk
import hippo 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.iconcolor import IconColor
from sugar.graphics import style 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): class LinksView(hippo.Canvas):
def __init__(self, model, browser): def __init__(self, model, browser):
hippo.Canvas.__init__(self) hippo.Canvas.__init__(self)
self._bubbles = {} self._icons = {}
self._browser = browser self._browser = browser
self._menu_shell = MenuShell(self)
self._box = hippo.CanvasBox() self._box = hippo.CanvasBox()
style.apply_stylesheet(self._box, 'links.Box') style.apply_stylesheet(self._box, 'links.Box')
@ -39,36 +54,30 @@ class LinksView(hippo.Canvas):
model.connect('link_removed', self._link_removed_cb) model.connect('link_removed', self._link_removed_cb)
def _add_link(self, link): def _add_link(self, link):
if len(self._bubbles) == 0: if len(self._icons) == 0:
self.show() 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) self._icons[link] = icon
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): def _remove_link(self, link):
bubble = self._bubbles[link] icon = self._icons[link]
self._box.remove(bubble) self._box.remove(icon)
del self._bubbles[link] del self._icons[link]
if len(self._bubbles) == 0: if len(self._icons) == 0:
self.hide() self.hide()
def _link_added_cb(self, model, link): def _link_added_cb(self, model, link):
self._add_link(link) self._add_link(link)
def _link_removed_cb(self, model, link): def _link_removed_cb(self, model, link):
self._removed_link(link) self._remove_link(link)
def _link_activated_cb(self, link_item, link): def _link_activated_cb(self, link_item, link):
self._browser.load_url(link.url) self._browser.load_url(link.url)

View File

@ -16,19 +16,12 @@
import gtk import gtk
_screen_factor = gtk.gdk.screen_width() / 1200.0 from sugar.graphics import style
links_Bubble = { links_Icon = {
'box-width' : int(250.0 * _screen_factor) 'size' : style.standard_icon_size
}
links_Text = {
'color' : 0x000000FF,
'font' : '14px',
'padding' : 6
} }
links_Box = { links_Box = {
'background_color' : 0x646464ff, 'background_color' : 0x414141ff,
'padding' : 4
} }

View File

@ -18,71 +18,37 @@ import gtk
import hippo import hippo
from sugar.graphics.iconcolor import IconColor from sugar.graphics.iconcolor import IconColor
from sugar.graphics import style
_screen_factor = gtk.gdk.screen_width() / 1200.0
_standard_icon_size = int(75.0 * _screen_factor)
_small_icon_size = _standard_icon_size * 0.5
_medium_icon_size = _standard_icon_size * 1.5
_large_icon_size = _standard_icon_size * 2.0
_xlarge_icon_size = _standard_icon_size * 3.0
_space_unit = 9 * _screen_factor
_separator_thickness = 3 * _screen_factor
def _font_description(style, relative_size):
base_size = 18 * _screen_factor
return '%s %dpx' % (style, int(base_size * relative_size))
frame_ActivityIcon = { frame_ActivityIcon = {
'color' : IconColor('white'), 'color' : IconColor('white'),
'size' : _standard_icon_size 'size' : style.standard_icon_size
} }
frame_ZoomIcon = { frame_ZoomIcon = {
'size' : _standard_icon_size 'size' : style.standard_icon_size
} }
frame_BuddyIcon = { frame_BuddyIcon = {
'size' : _standard_icon_size 'size' : style.standard_icon_size
}
menu = {
'background_color' : 0x000000FF,
'spacing' : _space_unit,
'padding' : _space_unit
}
menu_Title = {
'color' : 0xFFFFFFFF,
'font' : _font_description('Bold', 1.2)
}
menu_Separator = {
'background_color' : 0xFFFFFFFF,
'box_height' : _separator_thickness
}
menu_ActionIcon = {
'size' : _standard_icon_size
} }
home_MyIcon = { home_MyIcon = {
'size' : _xlarge_icon_size 'size' : style.xlarge_icon_size
} }
ring_ActivityIcon = { ring_ActivityIcon = {
'size' : _medium_icon_size 'size' : style.medium_icon_size
} }
friends_MyIcon = { friends_MyIcon = {
'size' : _large_icon_size 'size' : style.large_icon_size
} }
friends_FriendIcon = { friends_FriendIcon = {
'size' : _large_icon_size 'size' : style.large_icon_size
} }
friends_ActivityIcon = { friends_ActivityIcon = {
'size' : _standard_icon_size 'size' : style.standard_icon_size
} }

View File

@ -0,0 +1,4 @@
from sugar.graphics import style
from sugar.graphics import stylesheet
style.load_stylesheet(stylesheet)

View File

@ -15,8 +15,21 @@
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
import gtk
_styles = {} _styles = {}
_screen_factor = gtk.gdk.screen_width() / 1200.0
space_unit = 9 * _screen_factor
separator_thickness = 3 * _screen_factor
standard_icon_size = int(75.0 * _screen_factor)
small_icon_size = standard_icon_size * 0.5
medium_icon_size = standard_icon_size * 1.5
large_icon_size = standard_icon_size * 2.0
xlarge_icon_size = standard_icon_size * 3.0
def load_stylesheet(module): def load_stylesheet(module):
for objname in dir(module): for objname in dir(module):
if not objname.startswith('_'): if not objname.startswith('_'):
@ -32,3 +45,7 @@ def apply_stylesheet(item, stylesheet_name):
style_sheet = _styles[stylesheet_name] style_sheet = _styles[stylesheet_name]
for name in style_sheet.keys(): for name in style_sheet.keys():
item.set_property(name, style_sheet[name]) item.set_property(name, style_sheet[name])
def get_font_description(style, relative_size):
base_size = 18 * _screen_factor
return '%s %dpx' % (style, int(base_size * relative_size))

View File

@ -0,0 +1,21 @@
from sugar.graphics import style
menu = {
'background_color' : 0x000000FF,
'spacing' : style.space_unit,
'padding' : style.space_unit
}
menu_Title = {
'color' : 0xFFFFFFFF,
'font' : style.get_font_description('Bold', 1.2)
}
menu_Separator = {
'background_color' : 0xFFFFFFFF,
'box_height' : style.separator_thickness
}
menu_ActionIcon = {
'size' : style.standard_icon_size
}