Get activity bar and activity creation to work
This commit is contained in:
+32
-37
@@ -3,52 +3,47 @@ import re
|
||||
import gobject
|
||||
import gtk
|
||||
import goocanvas
|
||||
import rsvg
|
||||
|
||||
class IconView(goocanvas.ItemViewSimple):
|
||||
def __init__(self, handle, canvas_view, parent_view):
|
||||
goocanvas.SimpleItemView.__init__(self, canvas_view, parent_view)
|
||||
self._handle = handle
|
||||
from sugar.util import GObjectSingletonMeta
|
||||
|
||||
def do_paint(self, cr, bounds, scale):
|
||||
self._handle.render_cairo(cr)
|
||||
return self.bounds
|
||||
class IconCache(gobject.GObject):
|
||||
__metaclass__ = GObjectSingletonMeta
|
||||
|
||||
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):
|
||||
gobject.GObject.__init__(self)
|
||||
self._icons = {}
|
||||
|
||||
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'
|
||||
def _create_icon(self, name, color, size):
|
||||
theme = gtk.icon_theme_get_default()
|
||||
info = theme.lookup_icon(self._icon_name, 48, 0)
|
||||
info = theme.lookup_icon(name, size, 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
|
||||
if color != None:
|
||||
style = '.icon-color {fill: %s;}' % color
|
||||
data = re.sub('\.icon-color \{.*\}', style, data)
|
||||
|
||||
handle = rsvg.Handle(data=data)
|
||||
loader = gtk.gdk.pixbuf_loader_new_with_mime_type('image/svg-xml')
|
||||
loader.set_size(size, size)
|
||||
loader.write(data)
|
||||
loader.close()
|
||||
|
||||
return loader.get_pixbuf()
|
||||
|
||||
return IconView(handle, canvas_view, parent_view)
|
||||
def get_icon(self, name, color, size):
|
||||
key = (name, color, size)
|
||||
if self._icons.has_key(key):
|
||||
return self._icons[key]
|
||||
else:
|
||||
icon = self._create_icon(name, color, size)
|
||||
self._icons[key] = icon
|
||||
return icon
|
||||
|
||||
class IconItem(goocanvas.Image):
|
||||
def __init__(self, icon_name, color, size, **kwargs):
|
||||
goocanvas.Image.__init__(self, **kwargs)
|
||||
|
||||
icon_cache = IconCache()
|
||||
pixbuf = icon_cache.get_icon(icon_name, color, size)
|
||||
self.set_property('pixbuf', pixbuf)
|
||||
|
||||
Reference in New Issue
Block a user