2006-08-16 19:55:13 +02:00
|
|
|
import re
|
|
|
|
|
2006-08-16 23:20:22 +02:00
|
|
|
import gobject
|
2006-08-16 19:55:13 +02:00
|
|
|
import gtk
|
|
|
|
import goocanvas
|
2006-08-16 23:20:22 +02:00
|
|
|
import rsvg
|
2006-08-16 19:55:13 +02:00
|
|
|
|
2006-08-16 23:20:22 +02:00
|
|
|
class IconView(goocanvas.ItemViewSimple):
|
|
|
|
def __init__(self, handle, canvas_view, parent_view):
|
|
|
|
goocanvas.SimpleItemView.__init__(self, canvas_view, parent_view)
|
|
|
|
self._handle = handle
|
2006-08-16 19:55:13 +02:00
|
|
|
|
2006-08-16 23:20:22 +02:00
|
|
|
def do_paint(self, cr, bounds, scale):
|
|
|
|
self._handle.render_cairo(cr)
|
|
|
|
return self.bounds
|
2006-08-16 19:55:13 +02:00
|
|
|
|
2006-08-16 23:20:22 +02:00
|
|
|
class IconItem(goocanvas.Image):
|
|
|
|
__gproperties__ = {
|
|
|
|
'icon-name': (str, None, None, None, gobject.PARAM_READWRITE),
|
|
|
|
'color': (str, None, None, None, gobject.PARAM_READWRITE)
|
|
|
|
}
|
|
|
|
|
|
|
|
def __init__(self, **kwargs):
|
|
|
|
goocanvas.Image.__init__(self, **kwargs)
|
|
|
|
|
|
|
|
def do_set_property(self, pspec, value):
|
|
|
|
if pspec.name == 'icon-name':
|
|
|
|
self._icon_name = value
|
|
|
|
elif pspec.name == 'color':
|
|
|
|
self._color = value
|
|
|
|
else:
|
|
|
|
raise AttributeError, 'unknown property %s' % pspec.name
|
|
|
|
|
|
|
|
def do_get_property(self, pspec):
|
|
|
|
if pspec.name == 'icon-name':
|
|
|
|
return self._icon_name
|
|
|
|
if pspec.name == 'color':
|
|
|
|
return self._color
|
|
|
|
|
|
|
|
def create_view(self, canvas_view, parent_view):
|
|
|
|
print 'Create view'
|
2006-08-16 19:55:13 +02:00
|
|
|
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)
|
|
|
|
|
2006-08-16 23:20:22 +02:00
|
|
|
handle = rsvg.Handle(data=data)
|
2006-08-16 19:55:13 +02:00
|
|
|
|
2006-08-16 23:20:22 +02:00
|
|
|
return IconView(handle, canvas_view, parent_view)
|