Clicking on the friend icon in the frame add it to friends.
This commit is contained in:
parent
6865148c90
commit
030ba2b56d
@ -1,3 +1,5 @@
|
|||||||
|
import gobject
|
||||||
|
|
||||||
from sugar.canvas.IconColor import IconColor
|
from sugar.canvas.IconColor import IconColor
|
||||||
|
|
||||||
class Friend:
|
class Friend:
|
||||||
@ -6,14 +8,35 @@ class Friend:
|
|||||||
self._color = color
|
self._color = color
|
||||||
|
|
||||||
def get_name(self):
|
def get_name(self):
|
||||||
return name
|
return self._name
|
||||||
|
|
||||||
def get_color(self):
|
def get_color(self):
|
||||||
return IconColor(self._color)
|
return IconColor(self._color)
|
||||||
|
|
||||||
class Friends(list):
|
class Friends(gobject.GObject):
|
||||||
|
__gsignals__ = {
|
||||||
|
'friend-added': (gobject.SIGNAL_RUN_FIRST,
|
||||||
|
gobject.TYPE_NONE, ([object])),
|
||||||
|
'friend-removed': (gobject.SIGNAL_RUN_FIRST,
|
||||||
|
gobject.TYPE_NONE, ([object])),
|
||||||
|
}
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
list.__init__(self)
|
gobject.GObject.__init__(self)
|
||||||
|
|
||||||
|
self._list = []
|
||||||
|
|
||||||
|
def has_buddy(self, buddy):
|
||||||
|
for friend in self:
|
||||||
|
if friend.get_name() == buddy.get_name():
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def add_buddy(self, buddy):
|
def add_buddy(self, buddy):
|
||||||
self.add(Friend(buddy.get_name(), buddy.get_color()))
|
if not self.has_buddy(buddy):
|
||||||
|
friend = Friend(buddy.get_name(), buddy.get_color())
|
||||||
|
self._list.append(friend)
|
||||||
|
self.emit('friend-added', friend)
|
||||||
|
|
||||||
|
def __iter__(self):
|
||||||
|
return self._list.__iter__()
|
||||||
|
@ -14,6 +14,7 @@ sugar_PYTHON = \
|
|||||||
ChatController.py \
|
ChatController.py \
|
||||||
ConsoleWindow.py \
|
ConsoleWindow.py \
|
||||||
FirstTimeDialog.py \
|
FirstTimeDialog.py \
|
||||||
|
Friends.py \
|
||||||
Owner.py \
|
Owner.py \
|
||||||
Shell.py
|
Shell.py
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ class Shell(gobject.GObject):
|
|||||||
self._chat_controller = ChatController(self)
|
self._chat_controller = ChatController(self)
|
||||||
self._chat_controller.listen()
|
self._chat_controller.listen()
|
||||||
|
|
||||||
self._panel_manager = PanelManager(self)
|
self._panel_manager = PanelManager(self, self._owner)
|
||||||
self._panel_manager.show_and_hide(10)
|
self._panel_manager.show_and_hide(10)
|
||||||
|
|
||||||
self.set_zoom_level(sugar.ZOOM_HOME)
|
self.set_zoom_level(sugar.ZOOM_HOME)
|
||||||
|
@ -34,11 +34,10 @@ class FriendsGroup(goocanvas.Group):
|
|||||||
radius_x=60, radius_y=60)
|
radius_x=60, radius_y=60)
|
||||||
self.add_child(self._friends_rect)
|
self.add_child(self._friends_rect)
|
||||||
|
|
||||||
# for friend in data_model:
|
for friend in self._friends:
|
||||||
# self.add_friend(friend)
|
self.add_friend(friend)
|
||||||
|
|
||||||
# data_model.connect('friend-added', self.__friend_added_cb)
|
friends.connect('friend-added', self.__friend_added_cb)
|
||||||
# data_model.connect('friend-removed', self.__friend_removed_cb)
|
|
||||||
|
|
||||||
def __theme_changed_cb(self, theme):
|
def __theme_changed_cb(self, theme):
|
||||||
color = self._theme.get_home_friends_color()
|
color = self._theme.get_home_friends_color()
|
||||||
@ -47,17 +46,7 @@ class FriendsGroup(goocanvas.Group):
|
|||||||
def add_friend(self, friend):
|
def add_friend(self, friend):
|
||||||
icon = FriendIcon(friend)
|
icon = FriendIcon(friend)
|
||||||
self.add_child(icon)
|
self.add_child(icon)
|
||||||
self._friend_to_child[friend] = icon
|
|
||||||
self._icon_layout.add_icon(icon)
|
self._icon_layout.add_icon(icon)
|
||||||
|
|
||||||
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]
|
|
||||||
|
|
||||||
def __friend_added_cb(self, data_model, friend):
|
def __friend_added_cb(self, data_model, friend):
|
||||||
self.add_friend(friend)
|
self.add_friend(friend)
|
||||||
|
|
||||||
def __friend_removed_cb(self, data_model, friend):
|
|
||||||
self.remove_friend(friend)
|
|
||||||
|
@ -38,7 +38,7 @@ class HomeWindow(gtk.Window):
|
|||||||
y2 = y1 + FriendsGroup.HEIGHT
|
y2 = y1 + FriendsGroup.HEIGHT
|
||||||
icon_layout.set_bounds(x1, y1, x2, y2)
|
icon_layout.set_bounds(x1, y1, x2, y2)
|
||||||
|
|
||||||
self._mesh_group = MeshGroup(self._shell, owner, icon_layout)
|
self._mesh_group = MeshGroup(self._shell, icon_layout)
|
||||||
root.add_child(self._mesh_group)
|
root.add_child(self._mesh_group)
|
||||||
|
|
||||||
icon_layout = IconLayout(FriendsGroup.WIDTH, FriendsGroup.HEIGHT)
|
icon_layout = IconLayout(FriendsGroup.WIDTH, FriendsGroup.HEIGHT)
|
||||||
@ -48,7 +48,7 @@ class HomeWindow(gtk.Window):
|
|||||||
y2 = y1 + HomeGroup.HEIGHT
|
y2 = y1 + HomeGroup.HEIGHT
|
||||||
icon_layout.set_bounds(x1, y1, x2, y2)
|
icon_layout.set_bounds(x1, y1, x2, y2)
|
||||||
|
|
||||||
self._friends_group = FriendsGroup(owner, icon_layout)
|
self._friends_group = FriendsGroup(owner.get_friends(), icon_layout)
|
||||||
self._friends_group.translate((self._width - FriendsGroup.WIDTH) / 2,
|
self._friends_group.translate((self._width - FriendsGroup.WIDTH) / 2,
|
||||||
(self._height - FriendsGroup.HEIGHT) / 2)
|
(self._height - FriendsGroup.HEIGHT) / 2)
|
||||||
root.add_child(self._friends_group)
|
root.add_child(self._friends_group)
|
||||||
|
@ -34,7 +34,7 @@ class MeshGroup(goocanvas.Group):
|
|||||||
WIDTH = 1200.0 * 3.5
|
WIDTH = 1200.0 * 3.5
|
||||||
HEIGHT = 900.0 * 3.5
|
HEIGHT = 900.0 * 3.5
|
||||||
|
|
||||||
def __init__(self, shell, owner, icon_layout):
|
def __init__(self, shell, icon_layout):
|
||||||
goocanvas.Group.__init__(self)
|
goocanvas.Group.__init__(self)
|
||||||
self._shell = shell
|
self._shell = shell
|
||||||
self._icon_layout = icon_layout
|
self._icon_layout = icon_layout
|
||||||
|
@ -8,9 +8,10 @@ from sugar.presence import PresenceService
|
|||||||
class FriendsGroup(goocanvas.Group):
|
class FriendsGroup(goocanvas.Group):
|
||||||
N_BUDDIES = 10
|
N_BUDDIES = 10
|
||||||
|
|
||||||
def __init__(self, shell, width):
|
def __init__(self, shell, friends, width):
|
||||||
goocanvas.Group.__init__(self)
|
goocanvas.Group.__init__(self)
|
||||||
self._shell = shell
|
self._shell = shell
|
||||||
|
self._friends = friends
|
||||||
self._width = width
|
self._width = width
|
||||||
self._activity_ps = None
|
self._activity_ps = None
|
||||||
self._joined_hid = -1
|
self._joined_hid = -1
|
||||||
@ -60,6 +61,7 @@ class FriendsGroup(goocanvas.Group):
|
|||||||
icon = IconItem(icon_name='stock-buddy',
|
icon = IconItem(icon_name='stock-buddy',
|
||||||
color=IconColor(buddy.get_color()),
|
color=IconColor(buddy.get_color()),
|
||||||
size=self._width, y=self._get_y(i))
|
size=self._width, y=self._get_y(i))
|
||||||
|
icon.connect('clicked', self.__buddy_clicked_cb, buddy)
|
||||||
self.add_child(icon, i)
|
self.add_child(icon, i)
|
||||||
self._buddies[i] = buddy.get_name()
|
self._buddies[i] = buddy.get_name()
|
||||||
|
|
||||||
@ -112,6 +114,9 @@ class FriendsGroup(goocanvas.Group):
|
|||||||
def __buddy_left_cb(self, activity, buddy):
|
def __buddy_left_cb(self, activity, buddy):
|
||||||
self.remove(buddy)
|
self.remove(buddy)
|
||||||
|
|
||||||
|
def __buddy_clicked_cb(self, icon, buddy):
|
||||||
|
self._friends.add_buddy(buddy)
|
||||||
|
|
||||||
class ActionsBar(goocanvas.Group):
|
class ActionsBar(goocanvas.Group):
|
||||||
def __init__(self, shell, width):
|
def __init__(self, shell, width):
|
||||||
goocanvas.Group.__init__(self)
|
goocanvas.Group.__init__(self)
|
||||||
@ -149,9 +154,10 @@ class ActionsBar(goocanvas.Group):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
class FriendsPanel(Panel):
|
class FriendsPanel(Panel):
|
||||||
def __init__(self, shell):
|
def __init__(self, shell, friends):
|
||||||
Panel.__init__(self)
|
Panel.__init__(self)
|
||||||
self._shell = shell
|
self._shell = shell
|
||||||
|
self._friends = friends
|
||||||
|
|
||||||
def construct(self):
|
def construct(self):
|
||||||
Panel.construct(self)
|
Panel.construct(self)
|
||||||
@ -161,6 +167,7 @@ class FriendsPanel(Panel):
|
|||||||
actions_bar = ActionsBar(self._shell, self.get_width())
|
actions_bar = ActionsBar(self._shell, self.get_width())
|
||||||
root.add_child(actions_bar)
|
root.add_child(actions_bar)
|
||||||
|
|
||||||
friends_group = FriendsGroup(self._shell, self.get_width())
|
friends_group = FriendsGroup(self._shell, self._friends,
|
||||||
|
self.get_width())
|
||||||
friends_group.translate(0, 150)
|
friends_group.translate(0, 150)
|
||||||
root.add_child(friends_group)
|
root.add_child(friends_group)
|
||||||
|
@ -7,7 +7,7 @@ from panel.TopPanel import TopPanel
|
|||||||
from panel.Panel import Panel
|
from panel.Panel import Panel
|
||||||
|
|
||||||
class PanelManager:
|
class PanelManager:
|
||||||
def __init__(self, shell):
|
def __init__(self, shell, owner):
|
||||||
size = 30
|
size = 30
|
||||||
|
|
||||||
self._verbs_panel = VerbsPanel(shell)
|
self._verbs_panel = VerbsPanel(shell)
|
||||||
@ -15,7 +15,7 @@ class PanelManager:
|
|||||||
self._verbs_panel.move(0, gtk.gdk.screen_height() - size)
|
self._verbs_panel.move(0, gtk.gdk.screen_height() - size)
|
||||||
self._verbs_panel.resize(gtk.gdk.screen_width(), size)
|
self._verbs_panel.resize(gtk.gdk.screen_width(), size)
|
||||||
|
|
||||||
self._friends_panel = FriendsPanel(shell)
|
self._friends_panel = FriendsPanel(shell, owner.get_friends())
|
||||||
self._friends_panel.move(gtk.gdk.screen_width() - size, size)
|
self._friends_panel.move(gtk.gdk.screen_width() - size, size)
|
||||||
self._friends_panel.resize(size, gtk.gdk.screen_height() - size * 2)
|
self._friends_panel.resize(size, gtk.gdk.screen_height() - size * 2)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user