From d053a7f2191033922445ed5d2e566a0ac7a428be Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Thu, 14 Sep 2006 14:24:14 +0200 Subject: [PATCH] Make the popup logic more solid --- shell/home/FriendsGroup.py | 12 +++++++++--- sugar/canvas/IconItem.py | 17 ++++++++++++++++- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/shell/home/FriendsGroup.py b/shell/home/FriendsGroup.py index 2ff9a032..7ba1a3b7 100644 --- a/shell/home/FriendsGroup.py +++ b/shell/home/FriendsGroup.py @@ -21,6 +21,7 @@ class FriendsGroup(goocanvas.Group): def __init__(self, shell, friends): goocanvas.Group.__init__(self) + self._popup = None self._shell = shell self._icon_layout = IconLayout(1200, 900) self._friends = friends @@ -50,7 +51,8 @@ class FriendsGroup(goocanvas.Group): def _friend_popup_cb(self, icon, x1, y1, x2, y2): grid = Grid() - self._popup = BuddyPopup(self._shell, grid, icon.get_friend()) + if not self._popup: + self._popup = BuddyPopup(self._shell, grid, icon.get_friend()) [grid_x1, grid_y1] = grid.convert_from_screen(x1, y1) [grid_x2, grid_y2] = grid.convert_from_screen(x2, y2) @@ -72,6 +74,10 @@ class FriendsGroup(goocanvas.Group): self._popup.show() - def _friend_popdown_cb(self, friend): - self._popup.popdown() + def _popup_destroy_cb(self, popup): self._popup = None + + def _friend_popdown_cb(self, friend): + if self._popup: + self._popup.connect('destroy', self._popup_destroy_cb) + self._popup.popdown() diff --git a/sugar/canvas/IconItem.py b/sugar/canvas/IconItem.py index 8405ba31..38850f1d 100644 --- a/sugar/canvas/IconItem.py +++ b/sugar/canvas/IconItem.py @@ -195,6 +195,7 @@ class IconItem(goocanvas.ItemSimple, goocanvas.Item): self.size = 24 self.color = None self.icon_name = None + self._popdown_timeout = 0 goocanvas.ItemSimple.__init__(self, **kwargs) @@ -239,15 +240,29 @@ class IconItem(goocanvas.ItemSimple, goocanvas.Item): def _button_press_cb(self, view, target, event): self.emit('clicked') + def _start_popup_timeout(self): + self._stop_popup_timeout() + self._popdown_timeout = gobject.timeout_add(1000, self._popdown) + + def _stop_popup_timeout(self): + if self._popdown_timeout > 0: + gobject.source_remove(self._popdown_timeout) + self._popdown_timeout = 0 + def _enter_notify_event_cb(self, view, target, event, canvas): + self._stop_popup_timeout() + [x1, y1] = canvas.convert_to_pixels(view.get_bounds().x1, view.get_bounds().y1) [x2, y2] = canvas.convert_to_pixels(view.get_bounds().x2, view.get_bounds().y2) + self.emit('popup', int(x1), int(y1), int(x2), int(y2)) def _popdown(self): + self._popdown_timeout = 0 self.emit('popdown') + return False def _leave_notify_event_cb(self, view, target, event): - gobject.timeout_add(1000, self._popdown) + self._start_popup_timeout()