From c30bb01b0e37f26190835ed6fd42b68a8a2e2ad8 Mon Sep 17 00:00:00 2001 From: Simon Schampijer Date: Tue, 28 Aug 2007 14:15:51 +0200 Subject: [PATCH] Usage of the tray widget to display activity icons ActivitiesBox patch for ticket #2713. --- shell/view/frame/ActivitiesBox.py | 32 +++++++--------- shell/view/frame/Makefile.am | 1 + shell/view/frame/activitybutton.py | 60 ++++++++++++++++++++++++++++++ sugar/graphics/Makefile.am | 1 + sugar/graphics/tray.py | 4 ++ 5 files changed, 80 insertions(+), 18 deletions(-) create mode 100644 shell/view/frame/activitybutton.py diff --git a/shell/view/frame/ActivitiesBox.py b/shell/view/frame/ActivitiesBox.py index 78d7a453..affd34dc 100644 --- a/shell/view/frame/ActivitiesBox.py +++ b/shell/view/frame/ActivitiesBox.py @@ -20,27 +20,13 @@ import logging from sugar.graphics.palette import Palette from sugar.graphics.xocolor import XoColor from sugar.graphics.iconbutton import IconButton +from sugar.graphics.tray import HTray from sugar.graphics import style from sugar import profile from sugar import activity from frameinvoker import FrameCanvasInvoker - -class ActivityButton(IconButton): - def __init__(self, activity_info): - IconButton.__init__(self, file_name=activity_info.icon, - stroke_color=style.COLOR_WHITE.get_svg(), - fill_color=style.COLOR_TRANSPARENT.get_svg()) - - palette = Palette(activity_info.name) - palette.props.invoker = FrameCanvasInvoker(self) - palette.set_group_id('frame') - self.set_palette(palette) - - self._activity_info = activity_info - - def get_bundle_id(self): - return self._activity_info.service_name +from activitybutton import ActivityButton class InviteButton(IconButton): def __init__(self, activity_model, invite): @@ -67,6 +53,10 @@ class ActivitiesBox(hippo.CanvasBox): self._invite_to_item = {} self._invites = self._shell_model.get_invites() + self.tray = HTray() + self.append(hippo.CanvasWidget(widget=self.tray)) + self.tray.show() + registry = activity.get_registry() registry.get_activities_async(reply_handler=self._get_activities_cb) @@ -96,13 +86,19 @@ class ActivitiesBox(hippo.CanvasBox): def _invite_removed_cb(self, invites, invite): self.remove_invite(invite) + def _activity_removed_cb(self, item): + index = self.tray.get_item_index(item) + self.tray.remove_item(index) + def _activity_added_cb(self, activity_registry, activity_info): self.add_activity(activity_info) def add_activity(self, activity_info): item = ActivityButton(activity_info) - item.connect('activated', self._activity_clicked_cb) - self.append(item, 0) + item.connect('clicked', self._activity_clicked_cb) + item.connect('remove_activity', self._activity_removed_cb) + self.tray.add_item(item, -1) + item.show() def add_invite(self, invite): mesh = self._shell_model.get_mesh() diff --git a/shell/view/frame/Makefile.am b/shell/view/frame/Makefile.am index 4a7083b2..e40219e5 100644 --- a/shell/view/frame/Makefile.am +++ b/shell/view/frame/Makefile.am @@ -2,6 +2,7 @@ sugardir = $(pkgdatadir)/shell/view/frame sugar_PYTHON = \ __init__.py \ ActivitiesBox.py \ + activitybutton.py \ clipboardbox.py \ clipboardpanelwindow.py \ frameinvoker.py \ diff --git a/shell/view/frame/activitybutton.py b/shell/view/frame/activitybutton.py new file mode 100644 index 00000000..f3e2b7e9 --- /dev/null +++ b/shell/view/frame/activitybutton.py @@ -0,0 +1,60 @@ +# Copyright (C) 2007, One Laptop Per Child +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. + +import gtk +import os +import gobject + +from sugar.graphics.palette import Palette +from sugar.graphics.tray import TrayButton +from sugar.graphics.icon import Icon +from sugar.graphics import style + +from gettext import gettext as _ + +class ActivityButton(TrayButton, gobject.GObject): + __gtype_name__ = 'SugarActivityButton' + __gsignals__ = { + 'remove_activity': (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, ([])) + } + + def __init__(self, activity_info): + TrayButton.__init__(self) + icon = Icon(file=activity_info.icon, + stroke_color=style.COLOR_WHITE.get_svg(), + fill_color=style.COLOR_TRANSPARENT.get_svg()) + self.set_icon_widget(icon) + icon.show() + + self._activity_info = activity_info + self.setup_rollover_options() + + def get_bundle_id(self): + return self._activity_info.service_name + + def setup_rollover_options(self): + palette = Palette(self._activity_info.name) + self.set_palette(palette) + + menu_item = gtk.MenuItem(_('Remove')) + menu_item.connect('activate', self.item_remove_cb) + palette.menu.append(menu_item) + menu_item.show() + + def item_remove_cb(self, widget): + self.emit('remove_activity') diff --git a/sugar/graphics/Makefile.am b/sugar/graphics/Makefile.am index 8911b68f..cf193795 100644 --- a/sugar/graphics/Makefile.am +++ b/sugar/graphics/Makefile.am @@ -22,5 +22,6 @@ sugar_PYTHON = \ toolbox.py \ toolbutton.py \ toolcombobox.py \ + tray.py \ window.py \ xocolor.py diff --git a/sugar/graphics/tray.py b/sugar/graphics/tray.py index cf646a6f..53a72fb6 100644 --- a/sugar/graphics/tray.py +++ b/sugar/graphics/tray.py @@ -111,8 +111,12 @@ class HTray(gtk.HBox): self._viewport.traybar.insert(item, index) def remove_item(self, index): + item = self._viewport.traybar.get_nth_item(index) self._viewport.traybar.remove(item) + def get_item_index(self, item): + return self._viewport.traybar.get_item_index(item) + class TrayButton(ToolButton): def __init__(self, **kwargs): ToolButton.__init__(self, **kwargs)