diff --git a/shell/Invites.py b/shell/Invites.py index 22598efc..24f99134 100644 --- a/shell/Invites.py +++ b/shell/Invites.py @@ -46,5 +46,9 @@ class Invites(gobject.GObject): self._list.append(invite) self.emit('invite-added', invite) + def remove_invite(self, invite): + self._list.remove(invite) + self.emit('invite-removed', invite) + def __iter__(self): return self._list.__iter__() diff --git a/shell/frame/BottomPanel.py b/shell/frame/BottomPanel.py index 00a3b802..0348ccf0 100644 --- a/shell/frame/BottomPanel.py +++ b/shell/frame/BottomPanel.py @@ -30,11 +30,16 @@ class InviteItem(IconItem): def get_bundle_id(self): return self._invite.get_bundle_id() + def get_invite(self): + return self._invite + class BottomPanel(GridBox): def __init__(self, shell, invites): GridBox.__init__(self, GridBox.HORIZONTAL, 14, 6) self._shell = shell + self._invite_to_item = {} + self._invites = invites registry = conf.get_activity_registry() for activity in registry.list_activities(): @@ -44,17 +49,22 @@ class BottomPanel(GridBox): for invite in invites: self.add_invite(invite) invites.connect('invite-added', self.__invite_added_cb) + invites.connect('invite-removed', self.__invite_removed_cb) def __activity_clicked_cb(self, icon): self._shell.start_activity(icon.get_bundle_id()) def __invite_clicked_cb(self, icon): + self._invites.remove_invite(icon.get_invite()) self._shell.join_activity(icon.get_bundle_id(), icon.get_activity_id()) def __invite_added_cb(self, invites, invite): self.add_invite(invite) + def __invite_removed_cb(self, invites, invite): + self.remove_invite(invite) + def add_activity(self, activity): item = ActivityItem(activity) item.connect('clicked', self.__activity_clicked_cb) @@ -64,3 +74,9 @@ class BottomPanel(GridBox): item = InviteItem(invite) item.connect('clicked', self.__invite_clicked_cb) self.add_child(item, 0) + + self._invite_to_item[invite] = item + + def remove_invite(self, invite): + self.remove_child(self._invite_to_item[invite]) + del self._invite_to_item[invite] diff --git a/sugar/canvas/GridBox.py b/sugar/canvas/GridBox.py index 2dc24b48..d665c886 100644 --- a/sugar/canvas/GridBox.py +++ b/sugar/canvas/GridBox.py @@ -4,6 +4,8 @@ from sugar.canvas.GridLayout import GridGroup from sugar.canvas.GridLayout import GridConstraints class GridBox(GridGroup, goocanvas.Item): + __gtype_name__ = 'GridBox' + VERTICAL = 0 HORIZONTAL = 1 @@ -27,7 +29,7 @@ class GridBox(GridGroup, goocanvas.Item): constraints = GridConstraints(col, row, 1, 1, self._padding) self._layout.set_constraints(item, constraints) - def add_child(self, item, position=-1): + def do_add_child(self, item, position=-1): if position == -1: position = self.get_n_children() @@ -38,4 +40,12 @@ class GridBox(GridGroup, goocanvas.Item): self._update_constraints(self.get_child(i), i + 1) i += 1 - GridGroup.add_child(self, item, position) + GridGroup.do_add_child(self, item, position) + + def do_remove_child(self, position): + GridGroup.do_remove_child(self, position) + + i = position + while i < self.get_n_children(): + self._update_constraints(self.get_child(i), i) + i += 1