Make the popup logic more solid

This commit is contained in:
Marco Pesenti Gritti 2006-09-14 14:24:14 +02:00
parent fe69dec4ad
commit d053a7f219
2 changed files with 25 additions and 4 deletions

View File

@ -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()

View File

@ -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()