diff --git a/activities/web/linksview.py b/activities/web/linksview.py index 92d7026d..70af786a 100644 --- a/activities/web/linksview.py +++ b/activities/web/linksview.py @@ -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) diff --git a/activities/web/stylesheet.py b/activities/web/stylesheet.py index b513c143..3628818f 100644 --- a/activities/web/stylesheet.py +++ b/activities/web/stylesheet.py @@ -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, } diff --git a/shell/view/stylesheet.py b/shell/view/stylesheet.py index 26c4f636..22ce2100 100644 --- a/shell/view/stylesheet.py +++ b/shell/view/stylesheet.py @@ -18,71 +18,37 @@ import gtk import hippo from sugar.graphics.iconcolor import IconColor - -_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)) +from sugar.graphics import style frame_ActivityIcon = { 'color' : IconColor('white'), - 'size' : _standard_icon_size + 'size' : style.standard_icon_size } frame_ZoomIcon = { - 'size' : _standard_icon_size + 'size' : style.standard_icon_size } frame_BuddyIcon = { - 'size' : _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 + 'size' : style.standard_icon_size } home_MyIcon = { - 'size' : _xlarge_icon_size + 'size' : style.xlarge_icon_size } ring_ActivityIcon = { - 'size' : _medium_icon_size + 'size' : style.medium_icon_size } friends_MyIcon = { - 'size' : _large_icon_size + 'size' : style.large_icon_size } friends_FriendIcon = { - 'size' : _large_icon_size + 'size' : style.large_icon_size } friends_ActivityIcon = { - 'size' : _standard_icon_size + 'size' : style.standard_icon_size } diff --git a/sugar/graphics/__init__.py b/sugar/graphics/__init__.py index e69de29b..420e0e5e 100644 --- a/sugar/graphics/__init__.py +++ b/sugar/graphics/__init__.py @@ -0,0 +1,4 @@ +from sugar.graphics import style +from sugar.graphics import stylesheet + +style.load_stylesheet(stylesheet) diff --git a/sugar/graphics/style.py b/sugar/graphics/style.py index c211e07d..f0ab3e80 100644 --- a/sugar/graphics/style.py +++ b/sugar/graphics/style.py @@ -15,8 +15,21 @@ # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. +import gtk + _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): for objname in dir(module): if not objname.startswith('_'): @@ -32,3 +45,7 @@ def apply_stylesheet(item, stylesheet_name): style_sheet = _styles[stylesheet_name] for name in style_sheet.keys(): 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)) diff --git a/sugar/graphics/stylesheet.py b/sugar/graphics/stylesheet.py new file mode 100644 index 00000000..c387a259 --- /dev/null +++ b/sugar/graphics/stylesheet.py @@ -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 +}