2006-08-19 11:12:25 +02:00
|
|
|
import random
|
|
|
|
|
2006-08-19 02:00:04 +02:00
|
|
|
import goocanvas
|
|
|
|
|
2006-08-19 11:12:25 +02:00
|
|
|
from sugar.canvas.IconItem import IconItem
|
2006-08-23 14:13:15 +02:00
|
|
|
import Theme
|
2006-08-23 14:06:45 +02:00
|
|
|
|
2006-08-26 14:59:19 +02:00
|
|
|
class FriendIcon(IconItem):
|
|
|
|
def __init__(self, friend):
|
2006-08-28 12:44:46 +02:00
|
|
|
IconItem.__init__(self, icon_name='stock-buddy',
|
2006-08-29 16:07:23 +02:00
|
|
|
color=friend.get_color(), size=96)
|
2006-08-26 14:59:19 +02:00
|
|
|
self._friend = friend
|
|
|
|
|
|
|
|
def get_friend(self):
|
|
|
|
return self._friend
|
|
|
|
|
2006-08-29 11:48:20 +02:00
|
|
|
class FriendsGroup(goocanvas.Group):
|
2006-08-29 14:39:34 +02:00
|
|
|
WIDTH = 1200.0 * 1.9
|
|
|
|
HEIGHT = 900.0 * 1.9
|
|
|
|
|
2006-09-04 14:30:44 +02:00
|
|
|
def __init__(self, shell, friends, icon_layout):
|
2006-08-29 11:48:20 +02:00
|
|
|
goocanvas.Group.__init__(self)
|
2006-08-26 14:59:19 +02:00
|
|
|
|
2006-09-04 14:30:44 +02:00
|
|
|
self._shell = shell
|
2006-08-29 16:07:23 +02:00
|
|
|
self._icon_layout = icon_layout
|
2006-08-30 11:46:14 +02:00
|
|
|
self._friends = friends
|
2006-08-29 16:07:23 +02:00
|
|
|
|
2006-08-23 14:13:15 +02:00
|
|
|
self._theme = Theme.get_instance()
|
2006-08-23 14:06:45 +02:00
|
|
|
self._theme.connect("theme-changed", self.__theme_changed_cb)
|
2006-08-19 02:00:04 +02:00
|
|
|
|
2006-08-23 16:41:12 +02:00
|
|
|
color = self._theme.get_home_friends_color()
|
2006-08-29 14:39:34 +02:00
|
|
|
self._friends_rect = goocanvas.Rect(width=FriendsGroup.WIDTH,
|
|
|
|
height=FriendsGroup.HEIGHT,
|
2006-08-23 14:06:45 +02:00
|
|
|
line_width=0, fill_color=color,
|
2006-08-29 14:47:33 +02:00
|
|
|
radius_x=60, radius_y=60)
|
2006-08-29 11:48:20 +02:00
|
|
|
self.add_child(self._friends_rect)
|
2006-08-19 11:12:25 +02:00
|
|
|
|
2006-08-30 12:22:01 +02:00
|
|
|
for friend in self._friends:
|
|
|
|
self.add_friend(friend)
|
2006-08-19 11:12:25 +02:00
|
|
|
|
2006-08-30 12:22:01 +02:00
|
|
|
friends.connect('friend-added', self.__friend_added_cb)
|
2006-08-19 11:12:25 +02:00
|
|
|
|
2006-08-23 16:41:12 +02:00
|
|
|
def __theme_changed_cb(self, theme):
|
|
|
|
color = self._theme.get_home_friends_color()
|
2006-08-23 14:06:45 +02:00
|
|
|
self._friends_rect.set_property("fill-color", color)
|
|
|
|
|
2006-09-04 14:30:44 +02:00
|
|
|
def __friend_clicked_cb(self, icon):
|
|
|
|
activity = self._shell.get_current_activity()
|
|
|
|
buddy = icon.get_friend().get_buddy()
|
|
|
|
if buddy != None:
|
|
|
|
activity.invite(buddy)
|
|
|
|
|
2006-08-19 11:12:25 +02:00
|
|
|
def add_friend(self, friend):
|
2006-08-26 14:59:19 +02:00
|
|
|
icon = FriendIcon(friend)
|
2006-09-04 14:30:44 +02:00
|
|
|
icon.connect('clicked', self.__friend_clicked_cb)
|
2006-08-29 11:48:20 +02:00
|
|
|
self.add_child(icon)
|
2006-08-29 16:07:23 +02:00
|
|
|
self._icon_layout.add_icon(icon)
|
2006-08-19 11:12:25 +02:00
|
|
|
|
|
|
|
def __friend_added_cb(self, data_model, friend):
|
2006-08-26 14:59:19 +02:00
|
|
|
self.add_friend(friend)
|