Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@localhost.localdomain>2006-09-10 22:36:12 (GMT)
committer Marco Pesenti Gritti <marco@localhost.localdomain>2006-09-10 22:36:12 (GMT)
commit9aaaa500a6506a9196ecc47c742e22431d50991d (patch)
tree68d76849f3129166da0eaee46daced37ca6414d4
parenta33cce71b60bebf59d6ff7e27347a108f2c823a8 (diff)
Optimize cache a bit and cleanup code
-rw-r--r--sugar/canvas/IconItem.py33
1 files changed, 17 insertions, 16 deletions
diff --git a/sugar/canvas/IconItem.py b/sugar/canvas/IconItem.py
index 310be27..43a1570 100644
--- a/sugar/canvas/IconItem.py
+++ b/sugar/canvas/IconItem.py
@@ -14,14 +14,17 @@ class _IconCache:
def __init__(self):
self._icons = {}
- def _create_icon(self, name, color):
+ def _read_icon(self, name, color):
theme = gtk.icon_theme_get_default()
info = theme.lookup_icon(name, _ICON_SIZE, 0)
icon_file = open(info.get_filename(), 'r')
- data = icon_file.read()
- icon_file.close()
- if color != None:
+ if color == None:
+ return rsvg.Handle(file=info.get_filename())
+ else:
+ data = icon_file.read()
+ icon_file.close()
+
fill = color.get_fill_color()
stroke = color.get_stroke_color()
@@ -34,21 +37,25 @@ class _IconCache:
style = '.shape-and-fill {fill:%s; stroke:%s;}' % (fill, stroke)
data = re.sub('\.shape-and-fill \{.*\}', style, data)
- return data
+ return rsvg.Handle(data=data)
+
+ def get_handle(self, name, color):
+ if color:
+ key = (name, color.to_string())
+ else:
+ key = name
- def get_icon(self, name, color):
- key = (name, color.get_fill_color())
if self._icons.has_key(key):
icon = self._icons[key]
else:
- icon = self._create_icon(name, color)
+ icon = self._read_icon(name, color)
self._icons[key] = icon
return icon
class IconView(goocanvas.ItemViewSimple, goocanvas.ItemView):
__gtype_name__ = 'IconView'
- _icon_cache = _IconCache()
+ _cache = _IconCache()
def __init__(self, canvas_view, parent_view, item):
goocanvas.ItemViewSimple.__init__(self)
@@ -112,13 +119,7 @@ class IconView(goocanvas.ItemViewSimple, goocanvas.ItemView):
if icon_name == None:
icon_name = 'stock-missing'
- if self.item.color == None:
- theme = gtk.icon_theme_get_default()
- info = theme.lookup_icon(icon_name, self.item.size, 0)
- handle = rsvg.Handle(file=info.get_filename())
- else:
- icon = IconView._icon_cache.get_icon(icon_name, self.item.color)
- handle = rsvg.Handle(data=icon)
+ handle = IconView._cache.get_handle(icon_name, self.item.color)
cr.save()