diff --git a/shell/view/BuddyIcon.py b/shell/view/BuddyIcon.py index 6fbcc4ec..ab1d4fbd 100644 --- a/shell/view/BuddyIcon.py +++ b/shell/view/BuddyIcon.py @@ -19,7 +19,7 @@ class BuddyIcon(MenuIcon): return menu def _popup_action_cb(self, popup, action): - self._popdown() + self.popdown() model = self._shell.get_model() if action == BuddyPopup.ACTION_REMOVE_FRIEND: diff --git a/sugar/canvas/IconItem.py b/sugar/canvas/IconItem.py index d4be1e53..c71e79be 100644 --- a/sugar/canvas/IconItem.py +++ b/sugar/canvas/IconItem.py @@ -195,7 +195,6 @@ class IconItem(goocanvas.ItemSimple, goocanvas.Item): self.size = 24 self.color = None self.icon_name = None - self._popdown_sid = 0 goocanvas.ItemSimple.__init__(self, **kwargs) @@ -233,43 +232,7 @@ class IconItem(goocanvas.ItemSimple, goocanvas.Item): def do_create_view(self, canvas, parent_view): view = IconView(canvas, parent_view, self) view.connect('button-press-event', self._button_press_cb) - view.connect('enter-notify-event', self._enter_notify_event_cb, canvas) - view.connect('leave-notify-event', self._leave_notify_event_cb) return view def _button_press_cb(self, view, target, event): self.emit('clicked') - - def _start_popdown_timeout(self): - self._stop_popdown_timeout() - self._popdown_sid = gobject.timeout_add(1000, self._popdown_timeout_cb) - - def _stop_popdown_timeout(self): - 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() - - [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) - - [window_x, window_y] = canvas.window.get_origin() - - x1 += window_x - y1 += window_y - x2 += window_x - y2 += window_y - - self.emit('popup', int(x1), int(y1), int(x2), int(y2)) - - def _popdown_timeout_cb(self): - self._popdown_sid = 0 - self.emit('popdown') - return False - - def _leave_notify_event_cb(self, view, target, event): - self._start_popdown_timeout() diff --git a/sugar/canvas/MenuIcon.py b/sugar/canvas/MenuIcon.py index f7c6ddc2..bd5772ae 100644 --- a/sugar/canvas/MenuIcon.py +++ b/sugar/canvas/MenuIcon.py @@ -1,3 +1,6 @@ +import goocanvas +import gobject + from sugar.canvas.IconItem import IconItem from sugar.canvas.Grid import Grid @@ -10,7 +13,7 @@ class _MenuShell: self._menu_controller.popdown() self._menu_controller = controller -class MenuIcon(IconItem): +class MenuIcon(IconItem, goocanvas.Item): _menu_shell = _MenuShell() def __init__(self, grid, **kwargs): @@ -21,9 +24,7 @@ class MenuIcon(IconItem): self._menu_distance = 0 self._hover_menu = False self._popdown_on_leave = False - - self.connect('popup', self._popup_cb) - self.connect('popdown', self._popdown_cb) + self._popdown_sid = 0 def set_menu_distance(self, distance): self._menu_distance = distance @@ -33,7 +34,7 @@ class MenuIcon(IconItem): self._menu.destroy() self._menu = None - def _popup_cb(self, icon, x1, y1, x2, y2): + def _popup(self, x1, y1, x2, y2): self.popdown() MenuIcon._menu_shell.set_active(None) @@ -68,12 +69,6 @@ class MenuIcon(IconItem): MenuIcon._menu_shell.set_active(self) - def _popdown_cb(self, friend): - if not self._hover_menu: - self.popdown() - else: - self._popdown_on_leave = True - def _menu_enter_notify_event_cb(self, widget, event): self._hover_menu = True @@ -81,3 +76,48 @@ class MenuIcon(IconItem): self._hover_menu = False if self._popdown_on_leave: self.popdown() + + def do_create_view(self, canvas, parent_view): + view = IconItem.do_create_view(self, canvas, parent_view) + view.connect('enter-notify-event', self._enter_notify_event_cb, canvas) + view.connect('leave-notify-event', self._leave_notify_event_cb) + return view + + def _start_popdown_timeout(self): + self._stop_popdown_timeout() + self._popdown_sid = gobject.timeout_add(1000, self._popdown_timeout_cb) + + def _stop_popdown_timeout(self): + 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() + + [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) + + [window_x, window_y] = canvas.window.get_origin() + + x1 += window_x + y1 += window_y + x2 += window_x + y2 += window_y + + self._popup(int(x1), int(y1), int(x2), int(y2)) + + def _popdown_timeout_cb(self): + self._popdown_sid = 0 + + if not self._hover_menu: + self.popdown() + else: + self._popdown_on_leave = True + + return False + + def _leave_notify_event_cb(self, view, target, event): + self._start_popdown_timeout()