Usage of the tray widget to display activity icons
ActivitiesBox patch for ticket #2713.
This commit is contained in:
parent
44d2bb6ffb
commit
c30bb01b0e
@ -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()
|
||||
|
@ -2,6 +2,7 @@ sugardir = $(pkgdatadir)/shell/view/frame
|
||||
sugar_PYTHON = \
|
||||
__init__.py \
|
||||
ActivitiesBox.py \
|
||||
activitybutton.py \
|
||||
clipboardbox.py \
|
||||
clipboardpanelwindow.py \
|
||||
frameinvoker.py \
|
||||
|
60
shell/view/frame/activitybutton.py
Normal file
60
shell/view/frame/activitybutton.py
Normal file
@ -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')
|
@ -22,5 +22,6 @@ sugar_PYTHON = \
|
||||
toolbox.py \
|
||||
toolbutton.py \
|
||||
toolcombobox.py \
|
||||
tray.py \
|
||||
window.py \
|
||||
xocolor.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)
|
||||
|
Loading…
Reference in New Issue
Block a user