Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/shell/view/BuddyIcon.py
blob: 4fec55b01686dff46d3461f7e4fe595e426b52cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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=112)

		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(self._friend)

		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)