Some work to implement the activity bar

This commit is contained in:
Marco Pesenti Gritti 2006-08-16 23:20:22 +02:00
parent 47f25f234e
commit dae3d2be2b
4 changed files with 64 additions and 21 deletions

View File

@ -1,6 +1,7 @@
[Activity] [Activity]
name = Web name = Web
id = com.redhat.Sugar.BrowserActivity id = com.redhat.Sugar.BrowserActivity
icon = browser-activity
python_module = browser.BrowserActivity.BrowserActivity python_module = browser.BrowserActivity.BrowserActivity
default_type = _web_olpc._udp default_type = _web_olpc._udp
show_launcher = yes show_launcher = yes

View File

@ -8,6 +8,7 @@ class ActivityModule:
def __init__(self, name, activity_id, directory): def __init__(self, name, activity_id, directory):
self._name = name self._name = name
self._icon = None
self._id = activity_id self._id = activity_id
self._directory = directory self._directory = directory
self._show_launcher = False self._show_launcher = False
@ -20,6 +21,14 @@ class ActivityModule:
"""Get the activity identifier""" """Get the activity identifier"""
return self._id return self._id
def get_icon(self):
"""Get the activity icon name"""
return self._icon
def set_icon(self, icon):
"""Set the activity icon name"""
self._icon = icon
def get_directory(self): def get_directory(self):
"""Get the path to activity directory.""" """Get the path to activity directory."""
return self._directory return self._directory
@ -97,6 +106,9 @@ class ActivityRegistry:
if cp.has_option('Activity', 'show_launcher'): if cp.has_option('Activity', 'show_launcher'):
module.set_show_launcher(True) module.set_show_launcher(True)
if cp.has_option('Activity', 'icon'):
module.set_icon(cp.get('Activity', 'icon'))
module.set_default_type(default_type) module.set_default_type(default_type)
return True return True

View File

@ -3,6 +3,19 @@ import goocanvas
from sugar.canvas.IconItem import IconItem from sugar.canvas.IconItem import IconItem
class ActivityBar(goocanvas.Group):
def __init__(self, registry):
goocanvas.Group.__init__(self)
for activity in registry.list_activities():
if activity.get_show_launcher():
self.add_activity(activity)
def add_activity(self, activity):
item = IconItem(icon_name=activity.get_icon(),
color='white', width=42, height=42)
self.add_child(item)
class Background(goocanvas.Group): class Background(goocanvas.Group):
def __init__(self): def __init__(self):
goocanvas.Group.__init__(self) goocanvas.Group.__init__(self)
@ -22,7 +35,7 @@ class Background(goocanvas.Group):
self.add_child(item) self.add_child(item)
class Model(goocanvas.CanvasModelSimple): class Model(goocanvas.CanvasModelSimple):
def __init__(self): def __init__(self, shell):
goocanvas.CanvasModelSimple.__init__(self) goocanvas.CanvasModelSimple.__init__(self)
root = self.get_root_item() root = self.get_root_item()
@ -30,6 +43,9 @@ class Model(goocanvas.CanvasModelSimple):
background = Background() background = Background()
root.add_child(background) root.add_child(background)
activity_bar = ActivityBar(shell.get_registry())
root.add_child(activity_bar)
class HomeWindow(gtk.Window): class HomeWindow(gtk.Window):
def __init__(self, shell): def __init__(self, shell):
gtk.Window.__init__(self) gtk.Window.__init__(self)
@ -39,7 +55,7 @@ class HomeWindow(gtk.Window):
self.connect('realize', self.__realize_cb) self.connect('realize', self.__realize_cb)
canvas = goocanvas.CanvasView() canvas = goocanvas.CanvasView()
canvas_model = Model() canvas_model = Model(shell)
canvas.set_bounds(0, 0, 1200, 900) canvas.set_bounds(0, 0, 1200, 900)
canvas.set_scale(float(800) / float(1200)) canvas.set_scale(float(800) / float(1200))
canvas.set_size_request(800, 600) canvas.set_size_request(800, 600)

View File

@ -1,28 +1,44 @@
import re import re
import gobject
import gtk import gtk
import goocanvas 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
def do_paint(self, cr, bounds, scale):
self._handle.render_cairo(cr)
return self.bounds
class IconItem(goocanvas.Image): class IconItem(goocanvas.Image):
def __init__(self, icon_name): __gproperties__ = {
goocanvas.Image.__init__(self) 'icon-name': (str, None, None, None, gobject.PARAM_READWRITE),
'color': (str, None, None, None, gobject.PARAM_READWRITE)
}
self._icon_name = icon_name def __init__(self, **kwargs):
self._color = None goocanvas.Image.__init__(self, **kwargs)
# FIXME changing the icon color will cause def do_set_property(self, pspec, value):
# the svg to be read in memory and rendered if pspec.name == 'icon-name':
# two times. self._icon_name = value
self._update_pixbuf() elif pspec.name == 'color':
self._color = value
else:
raise AttributeError, 'unknown property %s' % pspec.name
def set_parent(self, parent): def do_get_property(self, pspec):
goocanvas.Image.set_parent(self, parent) if pspec.name == 'icon-name':
return self._icon_name
if pspec.name == 'color':
return self._color
def set_color(self, color): def create_view(self, canvas_view, parent_view):
self._color = color print 'Create view'
self._update_pixbuf()
def _update_pixbuf(self):
theme = gtk.icon_theme_get_default() theme = gtk.icon_theme_get_default()
info = theme.lookup_icon(self._icon_name, 48, 0) info = theme.lookup_icon(self._icon_name, 48, 0)
icon_file = open(info.get_filename(), 'r') icon_file = open(info.get_filename(), 'r')
@ -33,8 +49,6 @@ class IconItem(goocanvas.Image):
style = '.icon-color {fill: %s;}' % self._color style = '.icon-color {fill: %s;}' % self._color
data = re.sub('\.icon-color \{.*\}', style, data) data = re.sub('\.icon-color \{.*\}', style, data)
loader = gtk.gdk.pixbuf_loader_new_with_mime_type('image/svg+xml') handle = rsvg.Handle(data=data)
loader.write(data)
loader.close()
self.set_property('pixbuf', loader.get_pixbuf()) return IconView(handle, canvas_view, parent_view)