sugar-toolkit-gtk3/shell/view/BuddyIcon.py
2006-09-19 14:04:11 +02:00

38 lines
1006 B
Python

from sugar.canvas.MenuIcon import MenuIcon
from view.BuddyMenu import BuddyMenu
class BuddyIcon(MenuIcon):
def __init__(self, shell, menu_shell, friend):
MenuIcon.__init__(self, menu_shell, icon_name='stock-buddy',
color=friend.get_color(), size=96)
self._shell = shell
self._friend = friend
def set_popup_distance(self, distance):
self._popup_distance = distance
def create_menu(self):
menu = BuddyMenu(self._shell, self._friend)
menu.connect('action', self._popup_action_cb)
return menu
def _popup_action_cb(self, popup, action):
self.popdown()
model = self._shell.get_model()
if action == BuddyMenu.ACTION_REMOVE_FRIEND:
friends = model.get_friends()
friends.remove(buddy)
buddy = self._friend.get_buddy()
if buddy == None:
return
if action == BuddyMenu.ACTION_INVITE:
activity = model.get_current_activity()
activity.invite(buddy)
elif action == BuddyMenu.ACTION_MAKE_FRIEND:
friends = model.get_friends()
friends.make_friend(buddy)