From 6971ddb9a44782cd525d6a0f416bdf3cdb82d346 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 12 Jan 2007 20:35:53 +0000 Subject: Support for activity icons inside the bundle. Patch by Gonzalo Odiard Modified by me to allow icon theme to override the bundle one. --- diff --git a/shell/view/BuddyIcon.py b/shell/view/BuddyIcon.py index 38f8277..8e910ed 100644 --- a/shell/view/BuddyIcon.py +++ b/shell/view/BuddyIcon.py @@ -19,7 +19,7 @@ from view.BuddyMenu import BuddyMenu class BuddyIcon(MenuIcon): def __init__(self, shell, menu_shell, buddy): - MenuIcon.__init__(self, menu_shell, icon_name='stock-buddy', + MenuIcon.__init__(self, menu_shell, icon_name='theme:stock-buddy', color=buddy.get_color()) self._shell = shell diff --git a/shell/view/BuddyMenu.py b/shell/view/BuddyMenu.py index 82e58c2..2909fd9 100644 --- a/shell/view/BuddyMenu.py +++ b/shell/view/BuddyMenu.py @@ -82,10 +82,10 @@ class BuddyMenu(Menu): friends = shell_model.get_friends() if friends.has_buddy(self._buddy): - icon = CanvasIcon(icon_name='stock-remove') + icon = CanvasIcon(icon_name='theme:stock-remove') self.add_action(icon, BuddyMenu.ACTION_REMOVE_FRIEND) else: - icon = CanvasIcon(icon_name='stock-add') + icon = CanvasIcon(icon_name='theme:stock-add') self.add_action(icon, BuddyMenu.ACTION_MAKE_FRIEND) activity = shell_model.get_home().get_current_activity() @@ -94,7 +94,7 @@ class BuddyMenu(Menu): # FIXME check that the buddy is not in the activity already - icon = CanvasIcon(icon_name='stock-invite') + icon = CanvasIcon(icon_name='theme:stock-invite') self.add_action(icon, BuddyMenu.ACTION_INVITE) def __buddy_icon_changed_cb(self, buddy): diff --git a/shell/view/clipboardmenu.py b/shell/view/clipboardmenu.py index 178edef..5472e4b 100644 --- a/shell/view/clipboardmenu.py +++ b/shell/view/clipboardmenu.py @@ -53,7 +53,7 @@ class ClipboardMenu(Menu): if percent == 100 and activity: if not self._remove_icon: - self._remove_icon = CanvasIcon(icon_name='stock-remove') + self._remove_icon = CanvasIcon(icon_name='theme:stock-remove') self.add_action(self._remove_icon, ClipboardMenu.ACTION_DELETE) if not self._open_icon: @@ -77,7 +77,7 @@ class ClipboardMenu(Menu): self._stop_icon = None else: if not self._stop_icon: - self._stop_icon = CanvasIcon(icon_name='stock-close') + self._stop_icon = CanvasIcon(icon_name='theme:stock-close') self.add_action(self._stop_icon, ClipboardMenu.ACTION_STOP_DOWNLOAD) if self._remove_icon: diff --git a/shell/view/frame/ZoomBox.py b/shell/view/frame/ZoomBox.py index 484ee4e..ed10374 100644 --- a/shell/view/frame/ZoomBox.py +++ b/shell/view/frame/ZoomBox.py @@ -37,11 +37,11 @@ class ActivityMenu(Menu): self._add_close_action() def _add_mesh_action(self): - icon = CanvasIcon(icon_name='stock-share-mesh') + icon = CanvasIcon(icon_name='theme:stock-share-mesh') self.add_action(icon, ActivityMenu.ACTION_SHARE) def _add_close_action(self): - icon = CanvasIcon(icon_name='stock-close') + icon = CanvasIcon(icon_name='theme:stock-close') self.add_action(icon, ActivityMenu.ACTION_CLOSE) class ActivityIcon(MenuIcon): @@ -81,22 +81,22 @@ class ZoomBox(hippo.CanvasBox): self._menu_shell = menu_shell self._activity_icon = None - icon = CanvasIcon(icon_name='stock-zoom-mesh') + icon = CanvasIcon(icon_name='theme:stock-zoom-mesh') style.apply_stylesheet(icon, 'frame.ZoomIcon') icon.connect('activated', self._level_clicked_cb, sugar.ZOOM_MESH) self.append(icon) - icon = CanvasIcon(icon_name='stock-zoom-friends') + icon = CanvasIcon(icon_name='theme:stock-zoom-friends') style.apply_stylesheet(icon, 'frame.ZoomIcon') icon.connect('activated', self._level_clicked_cb, sugar.ZOOM_FRIENDS) self.append(icon) - icon = CanvasIcon(icon_name='stock-zoom-home') + icon = CanvasIcon(icon_name='theme:stock-zoom-home') style.apply_stylesheet(icon, 'frame.ZoomIcon') icon.connect('activated', self._level_clicked_cb, sugar.ZOOM_HOME) self.append(icon) - icon = CanvasIcon(icon_name='stock-zoom-activity') + icon = CanvasIcon(icon_name='theme:stock-zoom-activity') style.apply_stylesheet(icon, 'frame.ZoomIcon') icon.connect('activated', self._level_clicked_cb, sugar.ZOOM_ACTIVITY) self.append(icon) diff --git a/shell/view/frame/overlaybox.py b/shell/view/frame/overlaybox.py index 406173a..fed1139 100644 --- a/shell/view/frame/overlaybox.py +++ b/shell/view/frame/overlaybox.py @@ -9,7 +9,7 @@ class OverlayBox(hippo.CanvasBox): self._shell = shell - icon = CanvasIcon(icon_name='stock-chat') + icon = CanvasIcon(icon_name='theme:stock-chat') style.apply_stylesheet(icon, 'frame.OverlayIcon') icon.connect('activated', self._overlay_clicked_cb) self.append(icon) diff --git a/shell/view/home/MyIcon.py b/shell/view/home/MyIcon.py index 80e3a04..94d919c 100644 --- a/shell/view/home/MyIcon.py +++ b/shell/view/home/MyIcon.py @@ -19,5 +19,5 @@ from sugar import profile class MyIcon(CanvasIcon): def __init__(self): - CanvasIcon.__init__(self, icon_name='stock-buddy', + CanvasIcon.__init__(self, icon_name='theme:stock-buddy', color=profile.get_color()) diff --git a/sugar/activity/bundle.py b/sugar/activity/bundle.py index d9fd0bf..3951c42 100644 --- a/sugar/activity/bundle.py +++ b/sugar/activity/bundle.py @@ -3,6 +3,8 @@ import os from ConfigParser import ConfigParser +import gtk + class Bundle: """Info about an activity bundle. Wraps the activity.info file.""" def __init__(self, path): @@ -21,6 +23,8 @@ class Bundle: self._valid = False def _parse_info(self, info_path): + base_path = os.path.dirname(info_path) + cp = ConfigParser() cp.read([info_path]) @@ -49,7 +53,11 @@ class Bundle: self._show_launcher = False if cp.has_option(section, 'icon'): - self._icon = cp.get(section, 'icon') + icon = cp.get(section, 'icon') + if gtk.icon_theme_get_default().has_icon(icon): + self._icon = 'theme:' + icon + else: + self._icon = os.path.join(base_path, icon + ".svg") if cp.has_option(section, 'activity_version'): self._activity_version = int(cp.get(section, 'activity_version')) diff --git a/sugar/graphics/canvasicon.py b/sugar/graphics/canvasicon.py index 125ddf9..05d3b21 100644 --- a/sugar/graphics/canvasicon.py +++ b/sugar/graphics/canvasicon.py @@ -52,7 +52,14 @@ class _IconCache: return rsvg.Handle(data=data) def get_handle(self, name, color, size): - info = self._theme.lookup_icon(name, int(size), 0) + if name[0:6] == "theme:": + icon = self._read_icon_from_name(name[6:], color, size) + else: + icon = self._read_icon(name, color) + return icon + + def _read_icon_from_name(self, name, color, size): + info = self._theme.lookup_icon(name, size, 0) if not info: raise "Icon '" + name + "' not found." -- cgit v0.9.1