2006-08-28 14:58:21 +02:00
|
|
|
import goocanvas
|
|
|
|
|
2006-08-23 11:52:18 +02:00
|
|
|
from panel.Panel import Panel
|
2006-08-28 14:58:21 +02:00
|
|
|
from sugar.canvas.IconItem import IconItem
|
2006-08-28 18:40:41 +02:00
|
|
|
from sugar.canvas.IconColor import IconColor
|
|
|
|
from sugar.presence import PresenceService
|
|
|
|
|
|
|
|
class FriendsGroup(goocanvas.Group):
|
2006-08-28 21:38:36 +02:00
|
|
|
N_BUDDIES = 10
|
|
|
|
|
2006-08-30 12:22:01 +02:00
|
|
|
def __init__(self, shell, friends, width):
|
2006-08-28 18:40:41 +02:00
|
|
|
goocanvas.Group.__init__(self)
|
2006-08-28 23:03:01 +02:00
|
|
|
self._shell = shell
|
2006-08-30 12:22:01 +02:00
|
|
|
self._friends = friends
|
2006-08-28 21:38:36 +02:00
|
|
|
self._width = width
|
2006-08-28 23:03:01 +02:00
|
|
|
self._activity_ps = None
|
|
|
|
self._joined_hid = -1
|
|
|
|
self._left_hid = -1
|
|
|
|
|
|
|
|
self._pservice = PresenceService.get_instance()
|
|
|
|
self._pservice.connect('activity-appeared',
|
|
|
|
self.__activity_appeared_cb)
|
2006-08-28 18:40:41 +02:00
|
|
|
|
2006-08-28 21:38:36 +02:00
|
|
|
self._buddies = []
|
2006-08-28 18:40:41 +02:00
|
|
|
i = 0
|
2006-08-28 21:38:36 +02:00
|
|
|
while i < FriendsGroup.N_BUDDIES:
|
|
|
|
self.add_child(self._create_placeholder(i))
|
|
|
|
self._buddies.append(None)
|
2006-08-28 18:40:41 +02:00
|
|
|
i += 1
|
|
|
|
|
|
|
|
shell.connect('activity-changed', self.__activity_changed_cb)
|
|
|
|
|
2006-08-28 21:38:36 +02:00
|
|
|
def add(self, buddy):
|
|
|
|
i = 0
|
|
|
|
while i < FriendsGroup.N_BUDDIES:
|
|
|
|
if self._buddies[i] == None:
|
2006-08-28 23:03:01 +02:00
|
|
|
self._add_buddy(buddy, i)
|
2006-08-28 21:38:36 +02:00
|
|
|
break
|
|
|
|
i += 1
|
|
|
|
|
|
|
|
def remove(self, buddy):
|
|
|
|
i = 0
|
|
|
|
while i < FriendsGroup.N_BUDDIES:
|
|
|
|
if self._buddies[i] == buddy.get_name():
|
2006-08-28 23:03:01 +02:00
|
|
|
self._remove_buddy(buddy, i)
|
2006-08-28 21:38:36 +02:00
|
|
|
break
|
|
|
|
i += 1
|
|
|
|
|
|
|
|
def clear(self):
|
|
|
|
i = 0
|
|
|
|
while i < FriendsGroup.N_BUDDIES:
|
2006-08-28 23:03:01 +02:00
|
|
|
if self._buddies[i] != None:
|
|
|
|
self._remove_buddy(i)
|
2006-08-28 21:38:36 +02:00
|
|
|
i += 1
|
|
|
|
|
|
|
|
def _get_y(self, i):
|
|
|
|
return i * (self._width + 6)
|
|
|
|
|
|
|
|
def _add_buddy(self, buddy, i):
|
|
|
|
self.remove_child(i)
|
2006-08-28 23:03:01 +02:00
|
|
|
icon = IconItem(icon_name='stock-buddy',
|
|
|
|
color=IconColor(buddy.get_color()),
|
|
|
|
size=self._width, y=self._get_y(i))
|
2006-08-30 12:22:01 +02:00
|
|
|
icon.connect('clicked', self.__buddy_clicked_cb, buddy)
|
2006-08-28 21:38:36 +02:00
|
|
|
self.add_child(icon, i)
|
|
|
|
self._buddies[i] = buddy.get_name()
|
|
|
|
|
|
|
|
def _create_placeholder(self, i):
|
|
|
|
icon = IconItem(icon_name='stock-buddy', color=IconColor('white'),
|
|
|
|
y=self._get_y(i), size=self._width)
|
|
|
|
return icon
|
|
|
|
|
|
|
|
def _remove_buddy(self, i):
|
|
|
|
self.remove_child(i)
|
|
|
|
self.add_child(self._create_placeholder(i), i)
|
|
|
|
self._buddies[i] = None
|
|
|
|
|
2006-08-28 23:03:01 +02:00
|
|
|
def __activity_appeared_cb(self, pservice, activity_ps):
|
|
|
|
activity = self._shell.get_current_activity()
|
|
|
|
if activity_ps.get_id() == activity.get_id():
|
|
|
|
self._set_activity_ps(activity_ps)
|
|
|
|
|
|
|
|
def _set_activity_ps(self, activity_ps):
|
|
|
|
if self._activity_ps == activity_ps:
|
|
|
|
return
|
|
|
|
|
|
|
|
self._activity_ps = activity_ps
|
|
|
|
|
2006-08-28 21:38:36 +02:00
|
|
|
self.clear()
|
2006-08-28 23:03:01 +02:00
|
|
|
|
|
|
|
if self._joined_hid > 0:
|
|
|
|
self.disconnect(self._joined_hid)
|
|
|
|
self._joined_hid = -1
|
|
|
|
if self._left_hid > 0:
|
|
|
|
self.disconnect(self._left_hid)
|
|
|
|
self._left_hid = -1
|
|
|
|
|
|
|
|
if activity_ps != None:
|
2006-08-28 21:38:36 +02:00
|
|
|
for buddy in activity_ps.get_joined_buddies():
|
|
|
|
self.add(buddy)
|
2006-08-28 23:03:01 +02:00
|
|
|
|
|
|
|
self._joined_hid = activity_ps.connect(
|
|
|
|
'buddy-joined', self.__buddy_joined_cb)
|
|
|
|
self._left_hid = activity_ps.connect(
|
|
|
|
'buddy-left', self.__buddy_left_cb)
|
|
|
|
|
|
|
|
def __activity_changed_cb(self, group, activity):
|
|
|
|
activity_ps = self._pservice.get_activity(activity.get_id())
|
|
|
|
self._set_activity_ps(activity_ps)
|
2006-08-28 21:38:36 +02:00
|
|
|
|
|
|
|
def __buddy_joined_cb(self, activity, buddy):
|
|
|
|
self.add(buddy)
|
|
|
|
|
|
|
|
def __buddy_left_cb(self, activity, buddy):
|
|
|
|
self.remove(buddy)
|
2006-08-28 14:58:21 +02:00
|
|
|
|
2006-08-30 12:22:01 +02:00
|
|
|
def __buddy_clicked_cb(self, icon, buddy):
|
|
|
|
self._friends.add_buddy(buddy)
|
|
|
|
|
2006-08-28 14:58:21 +02:00
|
|
|
class ActionsBar(goocanvas.Group):
|
|
|
|
def __init__(self, shell, width):
|
|
|
|
goocanvas.Group.__init__(self)
|
|
|
|
self._width = width
|
|
|
|
self._shell = shell
|
|
|
|
|
|
|
|
self._y = 0
|
|
|
|
|
|
|
|
icon = IconItem(icon_name='stock-share', size=self._width)
|
|
|
|
icon.connect('clicked', self.__share_clicked_cb)
|
|
|
|
self.add_icon(icon)
|
|
|
|
|
|
|
|
icon = IconItem(icon_name='stock-invite', size=self._width)
|
|
|
|
icon.connect('clicked', self.__invite_clicked_cb)
|
|
|
|
self.add_icon(icon)
|
|
|
|
|
|
|
|
icon = IconItem(icon_name='stock-chat', size=self._width)
|
|
|
|
icon.connect('clicked', self.__chat_clicked_cb)
|
|
|
|
self.add_icon(icon)
|
|
|
|
|
|
|
|
def add_icon(self, icon):
|
|
|
|
icon.set_property('y', self._y)
|
2006-08-28 16:53:29 +02:00
|
|
|
self._y += (self._width + 6)
|
2006-08-28 14:58:21 +02:00
|
|
|
self.add_child(icon)
|
|
|
|
|
|
|
|
def __share_clicked_cb(self, item):
|
2006-08-28 15:10:31 +02:00
|
|
|
activity = self._shell.get_current_activity()
|
|
|
|
if activity != None:
|
|
|
|
activity.share()
|
2006-08-28 14:58:21 +02:00
|
|
|
|
|
|
|
def __invite_clicked_cb(self, item):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def __chat_clicked_cb(self, item):
|
|
|
|
pass
|
2006-08-23 11:52:18 +02:00
|
|
|
|
|
|
|
class FriendsPanel(Panel):
|
2006-08-30 12:22:01 +02:00
|
|
|
def __init__(self, shell, friends):
|
2006-08-23 11:52:18 +02:00
|
|
|
Panel.__init__(self)
|
2006-08-28 14:58:21 +02:00
|
|
|
self._shell = shell
|
2006-08-30 12:22:01 +02:00
|
|
|
self._friends = friends
|
2006-08-28 14:58:21 +02:00
|
|
|
|
|
|
|
def construct(self):
|
|
|
|
Panel.construct(self)
|
|
|
|
|
2006-08-28 18:40:41 +02:00
|
|
|
root = self.get_root()
|
|
|
|
|
2006-08-28 14:58:21 +02:00
|
|
|
actions_bar = ActionsBar(self._shell, self.get_width())
|
2006-08-28 18:40:41 +02:00
|
|
|
root.add_child(actions_bar)
|
|
|
|
|
2006-08-30 12:22:01 +02:00
|
|
|
friends_group = FriendsGroup(self._shell, self._friends,
|
|
|
|
self.get_width())
|
2006-08-28 18:40:41 +02:00
|
|
|
friends_group.translate(0, 150)
|
|
|
|
root.add_child(friends_group)
|