2006-08-28 14:58:21 +02:00
|
|
|
import goocanvas
|
|
|
|
|
|
|
|
from sugar.canvas.IconItem import IconItem
|
2006-08-28 18:40:41 +02:00
|
|
|
from sugar.canvas.IconColor import IconColor
|
2006-09-13 13:50:00 +02:00
|
|
|
from sugar.canvas.CanvasBox import CanvasBox
|
2006-08-28 18:40:41 +02:00
|
|
|
from sugar.presence import PresenceService
|
2006-09-15 13:23:21 +02:00
|
|
|
from view.FriendIcon import FriendIcon
|
2006-09-15 12:52:37 +02:00
|
|
|
from model.Friends import Friend
|
2006-08-28 18:40:41 +02:00
|
|
|
|
2006-09-13 13:50:00 +02:00
|
|
|
class RightPanel(CanvasBox):
|
2006-09-15 12:40:22 +02:00
|
|
|
def __init__(self, grid, shell_model):
|
2006-09-13 13:50:00 +02:00
|
|
|
CanvasBox.__init__(self, grid, CanvasBox.VERTICAL, 1)
|
2006-09-15 12:40:22 +02:00
|
|
|
self._shell_model = shell_model
|
|
|
|
self._friends = shell_model.get_friends()
|
2006-08-28 23:03:01 +02:00
|
|
|
self._activity_ps = None
|
|
|
|
self._joined_hid = -1
|
|
|
|
self._left_hid = -1
|
2006-09-08 12:23:33 +02:00
|
|
|
self._buddies = {}
|
2006-08-28 23:03:01 +02:00
|
|
|
|
|
|
|
self._pservice = PresenceService.get_instance()
|
|
|
|
self._pservice.connect('activity-appeared',
|
|
|
|
self.__activity_appeared_cb)
|
2006-08-28 18:40:41 +02:00
|
|
|
|
2006-09-15 12:40:22 +02:00
|
|
|
shell_model.connect('activity-changed', self.__activity_changed_cb)
|
2006-08-28 18:40:41 +02:00
|
|
|
|
2006-08-28 21:38:36 +02:00
|
|
|
def add(self, buddy):
|
2006-09-14 20:52:21 +02:00
|
|
|
friend = Friend(buddy.get_name(), buddy.get_color())
|
2006-09-15 12:40:22 +02:00
|
|
|
icon = FriendIcon(self._shell_model, friend)
|
2006-09-14 21:15:48 +02:00
|
|
|
icon.set_popup_distance(1)
|
2006-09-13 13:50:00 +02:00
|
|
|
self.set_constraints(icon, 3, 3)
|
2006-09-08 01:54:52 +02:00
|
|
|
self.add_child(icon)
|
2006-08-28 21:38:36 +02:00
|
|
|
|
2006-09-08 12:23:33 +02:00
|
|
|
self._buddies[buddy.get_name()] = icon
|
|
|
|
|
2006-09-08 01:13:42 +02:00
|
|
|
def remove(self, buddy):
|
2006-09-08 12:23:33 +02:00
|
|
|
i = self.find_child(self._buddies[buddy.get_name()])
|
|
|
|
self.remove_child(i)
|
2006-08-28 21:38:36 +02:00
|
|
|
|
2006-09-08 01:13:42 +02:00
|
|
|
def clear(self):
|
2006-09-08 12:15:50 +02:00
|
|
|
while (self.get_n_children() > 0):
|
|
|
|
self.remove_child(0)
|
2006-09-08 12:23:33 +02:00
|
|
|
self._buddies = {}
|
2006-08-28 21:38:36 +02:00
|
|
|
|
2006-08-28 23:03:01 +02:00
|
|
|
def __activity_appeared_cb(self, pservice, activity_ps):
|
2006-09-15 12:40:22 +02:00
|
|
|
activity = self._shell_model.get_current_activity()
|
2006-09-08 18:23:16 +02:00
|
|
|
if activity and activity_ps.get_id() == activity.get_id():
|
2006-08-28 23:03:01 +02:00
|
|
|
self._set_activity_ps(activity_ps)
|
|
|
|
|
|
|
|
def _set_activity_ps(self, activity_ps):
|
|
|
|
if self._activity_ps == activity_ps:
|
|
|
|
return
|
|
|
|
|
|
|
|
if self._joined_hid > 0:
|
2006-09-01 18:59:14 +02:00
|
|
|
self._activity_ps.disconnect(self._joined_hid)
|
2006-08-28 23:03:01 +02:00
|
|
|
self._joined_hid = -1
|
|
|
|
if self._left_hid > 0:
|
2006-09-01 18:59:14 +02:00
|
|
|
self._activity_ps.disconnect(self._left_hid)
|
2006-08-28 23:03:01 +02:00
|
|
|
self._left_hid = -1
|
|
|
|
|
2006-09-01 18:59:14 +02:00
|
|
|
self._activity_ps = activity_ps
|
|
|
|
|
|
|
|
self.clear()
|
|
|
|
|
2006-08-28 23:03:01 +02:00
|
|
|
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)
|