sugar-toolkit-gtk3/shell/home/FriendsGroup.py

64 lines
1.7 KiB
Python
Raw Normal View History

2006-08-19 11:12:25 +02:00
import random
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
class FriendIcon(IconItem):
def __init__(self, friend):
IconItem.__init__(self, icon_name='stock-buddy',
color=friend.get_color(), size=96)
self._friend = friend
def get_friend(self):
return self._friend
class FriendsGroup(goocanvas.Group):
2006-08-29 14:39:34 +02:00
WIDTH = 1200.0 * 1.9
HEIGHT = 900.0 * 1.9
def __init__(self, icon_layout, data_model):
goocanvas.Group.__init__(self)
self._friend_to_child = {}
self._icon_layout = icon_layout
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)
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)
self.add_child(self._friends_rect)
2006-08-19 11:12:25 +02:00
for friend in data_model:
self.add_friend(friend)
data_model.connect('friend-added', self.__friend_added_cb)
data_model.connect('friend-removed', self.__friend_removed_cb)
2006-08-19 11:12:25 +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-08-19 11:12:25 +02:00
def add_friend(self, friend):
icon = FriendIcon(friend)
self.add_child(icon)
self._friend_to_child[friend] = icon
self._icon_layout.add_icon(icon)
2006-08-19 11:12:25 +02:00
def remove_friend(self, friend):
icon = self._friend_to_child[friend]
self._icon_layout.remove_icon(icon)
self.remove_child(self.find_child(icon))
del self._friend_to_child[friend]
2006-08-19 11:12:25 +02:00
def __friend_added_cb(self, data_model, friend):
self.add_friend(friend)
def __friend_removed_cb(self, data_model, friend):
self.remove_friend(friend)