Improve popup/popdown logic

This commit is contained in:
Marco Pesenti Gritti 2006-09-15 00:34:42 +02:00
parent 3ee23b3a92
commit fd92a6d7d9
2 changed files with 28 additions and 30 deletions

View File

@ -11,6 +11,8 @@ class FriendIcon(IconItem):
self._friend = friend self._friend = friend
self._popup = None self._popup = None
self._popup_distance = 0 self._popup_distance = 0
self._hover_popup = False
self._popdown_on_leave = False
self.connect('popup', self._popup_cb) self.connect('popup', self._popup_cb)
self.connect('popdown', self._popdown_cb) self.connect('popdown', self._popdown_cb)
@ -21,11 +23,21 @@ class FriendIcon(IconItem):
def get_friend(self): def get_friend(self):
return self._friend return self._friend
def _popup_cb(self, icon, x1, y1, x2, y2): def _popdown(self):
grid = Grid() if self._popup:
self._popup.destroy()
self._popup = None
if not self._popup: def _popup_cb(self, icon, x1, y1, x2, y2):
self._popup = FriendPopup(self._shell, grid, icon.get_friend()) self._popdown()
grid = Grid()
self._popup = FriendPopup(self._shell, grid, icon.get_friend())
self._popup.connect('enter-notify-event',
self._popup_enter_notify_event_cb)
self._popup.connect('leave-notify-event',
self._popup_leave_notify_event_cb)
distance = self._popup_distance distance = self._popup_distance
@ -49,11 +61,14 @@ class FriendIcon(IconItem):
self._popup.show() self._popup.show()
def _popup_destroy_cb(self, popup):
self._popup = None
def _popdown_cb(self, friend): def _popdown_cb(self, friend):
if self._popup: if not self._hover_popup:
self._popup.connect('destroy', self._popup_destroy_cb) self._popdown()
self._popup.popdown()
def _popup_enter_notify_event_cb(self, widget, event):
self._hover_popup = True
def _popup_leave_notify_event_cb(self, widget, event):
self._hover_popup = False
if self._popdown_on_leave:
self._popdown()

View File

@ -63,34 +63,17 @@ class FriendPopup(gtk.Window):
canvas.set_model(model) canvas.set_model(model)
self.connect('enter-notify-event', self._enter_notify_event_cb)
self.connect('leave-notify-event', self._leave_notify_event_cb)
def _invite_clicked_cb(self, icon): def _invite_clicked_cb(self, icon):
activity = self._shell.get_current_activity() activity = self._shell.get_current_activity()
buddy = self._friend.get_buddy() buddy = self._friend.get_buddy()
if buddy != None: if buddy != None:
activity.invite(buddy) activity.invite(buddy)
else:
print 'Friend not online'
def _make_friend_clicked_cb(self, icon): def _make_friend_clicked_cb(self, icon):
friends = self._shell.get_owner().get_friends() friends = self._shell.get_owner().get_friends()
friends.add_buddy(buddy) buddy = self._friend.get_buddy()
if buddy != None:
def _enter_notify_event_cb(self, widget, event): friends.add_buddy(buddy)
self._hover = True
def _leave_notify_event_cb(self, widget, event):
self._hover = False
if self._popdown_on_leave:
self.popdown()
def popdown(self):
if not self._hover:
self.destroy()
else:
self._popdown_on_leave = True
def get_width(self): def get_width(self):
return self._width return self._width