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]
name = Web
id = com.redhat.Sugar.BrowserActivity
icon = browser-activity
python_module = browser.BrowserActivity.BrowserActivity
default_type = _web_olpc._udp
show_launcher = yes

View File

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

View File

@ -3,6 +3,19 @@ import goocanvas
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):
def __init__(self):
goocanvas.Group.__init__(self)
@ -22,7 +35,7 @@ class Background(goocanvas.Group):
self.add_child(item)
class Model(goocanvas.CanvasModelSimple):
def __init__(self):
def __init__(self, shell):
goocanvas.CanvasModelSimple.__init__(self)
root = self.get_root_item()
@ -30,6 +43,9 @@ class Model(goocanvas.CanvasModelSimple):
background = Background()
root.add_child(background)
activity_bar = ActivityBar(shell.get_registry())
root.add_child(activity_bar)
class HomeWindow(gtk.Window):
def __init__(self, shell):
gtk.Window.__init__(self)
@ -39,7 +55,7 @@ class HomeWindow(gtk.Window):
self.connect('realize', self.__realize_cb)
canvas = goocanvas.CanvasView()
canvas_model = Model()
canvas_model = Model(shell)
canvas.set_bounds(0, 0, 1200, 900)
canvas.set_scale(float(800) / float(1200))
canvas.set_size_request(800, 600)

View File

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