diff options
author | Marco Pesenti Gritti <marco@localhost.localdomain> | 2006-08-16 17:55:13 (GMT) |
---|---|---|
committer | Marco Pesenti Gritti <marco@localhost.localdomain> | 2006-08-16 17:55:13 (GMT) |
commit | 115eefb4c2bb8154f6834caa62be2bcba80f70dc (patch) | |
tree | fb52038ae2c2773fb274fa494ef88ef99f3dcc6e /sugar | |
parent | fa90ec41aa79d349406dd1fd0084da061627bb2b (diff) |
Implement a canvas element that can draw svg icons
with different colors.
Diffstat (limited to 'sugar')
-rw-r--r-- | sugar/canvas/IconItem.py | 40 | ||||
-rw-r--r-- | sugar/canvas/Makefile.am | 4 | ||||
-rw-r--r-- | sugar/canvas/__init__.py | 0 |
3 files changed, 44 insertions, 0 deletions
diff --git a/sugar/canvas/IconItem.py b/sugar/canvas/IconItem.py new file mode 100644 index 0000000..54697b6 --- /dev/null +++ b/sugar/canvas/IconItem.py @@ -0,0 +1,40 @@ +import re + +import gtk +import goocanvas + +class IconItem(goocanvas.Image): + def __init__(self, icon_name): + goocanvas.Image.__init__(self) + + self._icon_name = icon_name + self._color = None + + # FIXME changing the icon color will cause + # the svg to be read in memory and rendered + # two times. + self._update_pixbuf() + + def set_parent(self, parent): + goocanvas.Image.set_parent(self, parent) + + def set_color(self, color): + self._color = color + self._update_pixbuf() + + def _update_pixbuf(self): + theme = gtk.icon_theme_get_default() + info = theme.lookup_icon(self._icon_name, 48, 0) + icon_file = open(info.get_filename(), 'r') + data = icon_file.read() + icon_file.close() + + if self._color != None: + style = '.icon-color {fill: %s;}' % self._color + data = re.sub('\.icon-color \{.*\}', style, data) + + loader = gtk.gdk.pixbuf_loader_new_with_mime_type('image/svg+xml') + loader.write(data) + loader.close() + + self.set_property('pixbuf', loader.get_pixbuf()) diff --git a/sugar/canvas/Makefile.am b/sugar/canvas/Makefile.am new file mode 100644 index 0000000..9120ba2 --- /dev/null +++ b/sugar/canvas/Makefile.am @@ -0,0 +1,4 @@ +sugardir = $(pythondir)/sugar/canvas +sugar_PYTHON = \ + __init__.py \ + IconItem.py diff --git a/sugar/canvas/__init__.py b/sugar/canvas/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/sugar/canvas/__init__.py |