diff --git a/shell/FriendIcon.py b/shell/FriendIcon.py index 8d1017c2..0c6b1e67 100644 --- a/shell/FriendIcon.py +++ b/shell/FriendIcon.py @@ -45,7 +45,8 @@ class FriendIcon(IconItem): FriendIcon._popup_shell.set_active(None) grid = Grid() - self._popup = FriendPopup(self._shell, grid, icon.get_friend()) + self._popup = FriendPopup(grid, icon.get_friend()) + self._popup.connect('action', self._popup_action_cb) self._popup.connect('enter-notify-event', self._popup_enter_notify_event_cb) self._popup.connect('leave-notify-event', @@ -74,9 +75,25 @@ class FriendIcon(IconItem): FriendIcon._popup_shell.set_active(self) + def _popup_action_cb(self, popup, action): + self._popdown() + + buddy = self._friend.get_buddy() + if buddy == None: + return + + if action == FriendPopup.ACTION_INVITE: + activity = self._shell.get_current_activity() + activity.invite(buddy) + elif action == FriendPopup.ACTION_MAKE_FRIEND: + friends = self._shell.get_owner().get_friends() + friends.add_buddy(buddy) + def _popdown_cb(self, friend): if not self._hover_popup: self._popdown() + else: + self._popdown_on_leave = True def _popup_enter_notify_event_cb(self, widget, event): self._hover_popup = True diff --git a/shell/FriendPopup.py b/shell/FriendPopup.py index 4a2cd1b1..e2085942 100644 --- a/shell/FriendPopup.py +++ b/shell/FriendPopup.py @@ -1,15 +1,23 @@ import gtk import goocanvas +import gobject from sugar.canvas.CanvasView import CanvasView from sugar.canvas.CanvasBox import CanvasBox from sugar.canvas.IconItem import IconItem class FriendPopup(gtk.Window): - def __init__(self, shell, grid, friend): + ACTION_MAKE_FRIEND = 0 + ACTION_INVITE = 0 + + __gsignals__ = { + 'action': (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, ([int])), + } + + def __init__(self, grid, friend): gtk.Window.__init__(self, gtk.WINDOW_POPUP) - self._shell = shell self._friend = friend self._hover = False self._popdown_on_leave = False @@ -46,7 +54,8 @@ class FriendPopup(gtk.Window): grid.set_constraints(box, 0, 5) icon = IconItem(icon_name='stock-make-friend') - icon.connect('clicked', self._make_friend_clicked_cb) + icon.connect('clicked', self._action_clicked_cb, + FriendPopup.ACTION_MAKE_FRIEND) box.set_constraints(icon, 3, 3) box.add_child(icon) @@ -55,7 +64,8 @@ class FriendPopup(gtk.Window): box.add_child(icon) icon = IconItem(icon_name='stock-invite') - icon.connect('clicked', self._invite_clicked_cb) + icon.connect('clicked', self._action_clicked_cb, + FriendPopup.ACTION_INVITE) box.set_constraints(icon, 3, 3) box.add_child(icon) @@ -63,17 +73,8 @@ class FriendPopup(gtk.Window): canvas.set_model(model) - def _invite_clicked_cb(self, icon): - activity = self._shell.get_current_activity() - buddy = self._friend.get_buddy() - if buddy != None: - activity.invite(buddy) - - def _make_friend_clicked_cb(self, icon): - friends = self._shell.get_owner().get_friends() - buddy = self._friend.get_buddy() - if buddy != None: - friends.add_buddy(buddy) + def _action_clicked_cb(self, icon, action): + self.emit('action', action) def get_width(self): return self._width diff --git a/sugar/canvas/IconItem.py b/sugar/canvas/IconItem.py index dcc65cdb..d4be1e53 100644 --- a/sugar/canvas/IconItem.py +++ b/sugar/canvas/IconItem.py @@ -195,7 +195,7 @@ class IconItem(goocanvas.ItemSimple, goocanvas.Item): self.size = 24 self.color = None self.icon_name = None - self._popdown_timeout = 0 + self._popdown_sid = 0 goocanvas.ItemSimple.__init__(self, **kwargs) @@ -242,12 +242,12 @@ class IconItem(goocanvas.ItemSimple, goocanvas.Item): def _start_popdown_timeout(self): self._stop_popdown_timeout() - self._popdown_timeout = gobject.timeout_add(1000, self._popdown) + self._popdown_sid = gobject.timeout_add(1000, self._popdown_timeout_cb) def _stop_popdown_timeout(self): - if self._popdown_timeout > 0: - gobject.source_remove(self._popdown_timeout) - self._popdown_timeout = 0 + if self._popdown_sid > 0: + gobject.source_remove(self._popdown_sid) + self._popdown_sid = 0 def _enter_notify_event_cb(self, view, target, event, canvas): self._stop_popdown_timeout() @@ -266,8 +266,8 @@ class IconItem(goocanvas.ItemSimple, goocanvas.Item): self.emit('popup', int(x1), int(y1), int(x2), int(y2)) - def _popdown(self): - self._popdown_timeout = 0 + def _popdown_timeout_cb(self): + self._popdown_sid = 0 self.emit('popdown') return False