From 030ba2b56d1a698e3bb4a8dfb5843302e3c7569c Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Wed, 30 Aug 2006 12:22:01 +0200 Subject: [PATCH] Clicking on the friend icon in the frame add it to friends. --- shell/Friends.py | 31 +++++++++++++++++++++++++++---- shell/Makefile.am | 1 + shell/Shell.py | 2 +- shell/home/FriendsGroup.py | 17 +++-------------- shell/home/HomeWindow.py | 4 ++-- shell/home/MeshGroup.py | 2 +- shell/panel/FriendsPanel.py | 13 ++++++++++--- shell/panel/PanelManager.py | 4 ++-- 8 files changed, 47 insertions(+), 27 deletions(-) diff --git a/shell/Friends.py b/shell/Friends.py index 261074a5..22909b38 100644 --- a/shell/Friends.py +++ b/shell/Friends.py @@ -1,3 +1,5 @@ +import gobject + from sugar.canvas.IconColor import IconColor class Friend: @@ -6,14 +8,35 @@ class Friend: self._color = color def get_name(self): - return name + return self._name def get_color(self): return IconColor(self._color) -class Friends(list): +class Friends(gobject.GObject): + __gsignals__ = { + 'friend-added': (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, ([object])), + 'friend-removed': (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, ([object])), + } + def __init__(self): - list.__init__(self) + gobject.GObject.__init__(self) + + self._list = [] + + def has_buddy(self, buddy): + for friend in self: + if friend.get_name() == buddy.get_name(): + return True + return False def add_buddy(self, buddy): - self.add(Friend(buddy.get_name(), buddy.get_color())) + if not self.has_buddy(buddy): + friend = Friend(buddy.get_name(), buddy.get_color()) + self._list.append(friend) + self.emit('friend-added', friend) + + def __iter__(self): + return self._list.__iter__() diff --git a/shell/Makefile.am b/shell/Makefile.am index 85669526..eaa0672d 100644 --- a/shell/Makefile.am +++ b/shell/Makefile.am @@ -14,6 +14,7 @@ sugar_PYTHON = \ ChatController.py \ ConsoleWindow.py \ FirstTimeDialog.py \ + Friends.py \ Owner.py \ Shell.py diff --git a/shell/Shell.py b/shell/Shell.py index 2d239fd9..0dd03794 100755 --- a/shell/Shell.py +++ b/shell/Shell.py @@ -110,7 +110,7 @@ class Shell(gobject.GObject): self._chat_controller = ChatController(self) self._chat_controller.listen() - self._panel_manager = PanelManager(self) + self._panel_manager = PanelManager(self, self._owner) self._panel_manager.show_and_hide(10) self.set_zoom_level(sugar.ZOOM_HOME) diff --git a/shell/home/FriendsGroup.py b/shell/home/FriendsGroup.py index 15feffdc..48a55a07 100644 --- a/shell/home/FriendsGroup.py +++ b/shell/home/FriendsGroup.py @@ -34,11 +34,10 @@ class FriendsGroup(goocanvas.Group): radius_x=60, radius_y=60) self.add_child(self._friends_rect) -# for friend in data_model: -# self.add_friend(friend) + for friend in self._friends: + self.add_friend(friend) -# data_model.connect('friend-added', self.__friend_added_cb) -# data_model.connect('friend-removed', self.__friend_removed_cb) + friends.connect('friend-added', self.__friend_added_cb) def __theme_changed_cb(self, theme): color = self._theme.get_home_friends_color() @@ -47,17 +46,7 @@ class FriendsGroup(goocanvas.Group): def add_friend(self, friend): icon = FriendIcon(friend) self.add_child(icon) - self._friend_to_child[friend] = icon self._icon_layout.add_icon(icon) - def remove_friend(self, friend): - icon = self._friend_to_child[friend] - self._icon_layout.remove_icon(icon) - self.remove_child(self.find_child(icon)) - del self._friend_to_child[friend] - def __friend_added_cb(self, data_model, friend): self.add_friend(friend) - - def __friend_removed_cb(self, data_model, friend): - self.remove_friend(friend) diff --git a/shell/home/HomeWindow.py b/shell/home/HomeWindow.py index f1d444d4..4e4049c2 100644 --- a/shell/home/HomeWindow.py +++ b/shell/home/HomeWindow.py @@ -38,7 +38,7 @@ class HomeWindow(gtk.Window): y2 = y1 + FriendsGroup.HEIGHT icon_layout.set_bounds(x1, y1, x2, y2) - self._mesh_group = MeshGroup(self._shell, owner, icon_layout) + self._mesh_group = MeshGroup(self._shell, icon_layout) root.add_child(self._mesh_group) icon_layout = IconLayout(FriendsGroup.WIDTH, FriendsGroup.HEIGHT) @@ -48,7 +48,7 @@ class HomeWindow(gtk.Window): y2 = y1 + HomeGroup.HEIGHT icon_layout.set_bounds(x1, y1, x2, y2) - self._friends_group = FriendsGroup(owner, icon_layout) + self._friends_group = FriendsGroup(owner.get_friends(), icon_layout) self._friends_group.translate((self._width - FriendsGroup.WIDTH) / 2, (self._height - FriendsGroup.HEIGHT) / 2) root.add_child(self._friends_group) diff --git a/shell/home/MeshGroup.py b/shell/home/MeshGroup.py index 3bb9747d..7cd032c7 100644 --- a/shell/home/MeshGroup.py +++ b/shell/home/MeshGroup.py @@ -34,7 +34,7 @@ class MeshGroup(goocanvas.Group): WIDTH = 1200.0 * 3.5 HEIGHT = 900.0 * 3.5 - def __init__(self, shell, owner, icon_layout): + def __init__(self, shell, icon_layout): goocanvas.Group.__init__(self) self._shell = shell self._icon_layout = icon_layout diff --git a/shell/panel/FriendsPanel.py b/shell/panel/FriendsPanel.py index e4191b74..53fa8471 100644 --- a/shell/panel/FriendsPanel.py +++ b/shell/panel/FriendsPanel.py @@ -8,9 +8,10 @@ from sugar.presence import PresenceService class FriendsGroup(goocanvas.Group): N_BUDDIES = 10 - def __init__(self, shell, width): + def __init__(self, shell, friends, width): goocanvas.Group.__init__(self) self._shell = shell + self._friends = friends self._width = width self._activity_ps = None self._joined_hid = -1 @@ -60,6 +61,7 @@ class FriendsGroup(goocanvas.Group): icon = IconItem(icon_name='stock-buddy', color=IconColor(buddy.get_color()), size=self._width, y=self._get_y(i)) + icon.connect('clicked', self.__buddy_clicked_cb, buddy) self.add_child(icon, i) self._buddies[i] = buddy.get_name() @@ -112,6 +114,9 @@ class FriendsGroup(goocanvas.Group): def __buddy_left_cb(self, activity, buddy): self.remove(buddy) + def __buddy_clicked_cb(self, icon, buddy): + self._friends.add_buddy(buddy) + class ActionsBar(goocanvas.Group): def __init__(self, shell, width): goocanvas.Group.__init__(self) @@ -149,9 +154,10 @@ class ActionsBar(goocanvas.Group): pass class FriendsPanel(Panel): - def __init__(self, shell): + def __init__(self, shell, friends): Panel.__init__(self) self._shell = shell + self._friends = friends def construct(self): Panel.construct(self) @@ -161,6 +167,7 @@ class FriendsPanel(Panel): actions_bar = ActionsBar(self._shell, self.get_width()) root.add_child(actions_bar) - friends_group = FriendsGroup(self._shell, self.get_width()) + friends_group = FriendsGroup(self._shell, self._friends, + self.get_width()) friends_group.translate(0, 150) root.add_child(friends_group) diff --git a/shell/panel/PanelManager.py b/shell/panel/PanelManager.py index fdccf658..40e79457 100644 --- a/shell/panel/PanelManager.py +++ b/shell/panel/PanelManager.py @@ -7,7 +7,7 @@ from panel.TopPanel import TopPanel from panel.Panel import Panel class PanelManager: - def __init__(self, shell): + def __init__(self, shell, owner): size = 30 self._verbs_panel = VerbsPanel(shell) @@ -15,7 +15,7 @@ class PanelManager: self._verbs_panel.move(0, gtk.gdk.screen_height() - size) self._verbs_panel.resize(gtk.gdk.screen_width(), size) - self._friends_panel = FriendsPanel(shell) + self._friends_panel = FriendsPanel(shell, owner.get_friends()) self._friends_panel.move(gtk.gdk.screen_width() - size, size) self._friends_panel.resize(size, gtk.gdk.screen_height() - size * 2)