Support for activity icons inside the bundle.

Patch by Gonzalo Odiard <godiard@gmail.com>
Modified by me to allow icon theme to override the bundle one.
This commit is contained in:
Marco Pesenti Gritti 2007-01-12 21:35:53 +01:00
parent 55339d4bea
commit 6971ddb9a4
8 changed files with 31 additions and 16 deletions

View File

@ -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

View File

@ -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):

View File

@ -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:

View File

@ -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)

View File

@ -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)

View File

@ -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())

View File

@ -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'))

View File

@ -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."