More refactoring. Start implementing friends.
This commit is contained in:
parent
028d22cdd7
commit
6865148c90
19
shell/Friends.py
Normal file
19
shell/Friends.py
Normal file
@ -0,0 +1,19 @@
|
||||
from sugar.canvas.IconColor import IconColor
|
||||
|
||||
class Friend:
|
||||
def __init__(self, name, color):
|
||||
self._name = name
|
||||
self._color = color
|
||||
|
||||
def get_name(self):
|
||||
return name
|
||||
|
||||
def get_color(self):
|
||||
return IconColor(self._color)
|
||||
|
||||
class Friends(list):
|
||||
def __init__(self):
|
||||
list.__init__(self)
|
||||
|
||||
def add_buddy(self, buddy):
|
||||
self.add(Friend(buddy.get_name(), buddy.get_color()))
|
@ -6,6 +6,7 @@ from sugar import env
|
||||
from sugar.p2p import Stream
|
||||
from sugar.presence import PresenceService
|
||||
from sugar import conf
|
||||
from Friends import Friends
|
||||
|
||||
PRESENCE_SERVICE_TYPE = "_presence_olpc._tcp"
|
||||
|
||||
@ -29,6 +30,10 @@ class ShellOwner(object):
|
||||
break
|
||||
|
||||
self._pservice = PresenceService.get_instance()
|
||||
self._friends = Friends()
|
||||
|
||||
def get_friends(self):
|
||||
return self._friends
|
||||
|
||||
def announce(self):
|
||||
# Create and announce our presence
|
||||
|
@ -100,12 +100,12 @@ class Shell(gobject.GObject):
|
||||
ShellDbusService(self, bus_name)
|
||||
|
||||
PresenceService.start()
|
||||
self._pservice = PresenceService.get_instance()
|
||||
|
||||
self._owner = ShellOwner()
|
||||
self._owner.announce()
|
||||
|
||||
self._pservice = PresenceService.get_instance()
|
||||
self._home_window.set_presence_service(self._pservice)
|
||||
self._home_window.set_owner(self._owner)
|
||||
|
||||
self._chat_controller = ChatController(self)
|
||||
self._chat_controller.listen()
|
||||
|
@ -18,11 +18,11 @@ class FriendsGroup(goocanvas.Group):
|
||||
WIDTH = 1200.0 * 1.9
|
||||
HEIGHT = 900.0 * 1.9
|
||||
|
||||
def __init__(self, icon_layout):
|
||||
def __init__(self, friends, icon_layout):
|
||||
goocanvas.Group.__init__(self)
|
||||
self._friend_to_child = {}
|
||||
|
||||
self._icon_layout = icon_layout
|
||||
self._friends = friends
|
||||
|
||||
self._theme = Theme.get_instance()
|
||||
self._theme.connect("theme-changed", self.__theme_changed_cb)
|
||||
|
@ -28,7 +28,7 @@ class HomeWindow(gtk.Window):
|
||||
self.realize()
|
||||
self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DESKTOP)
|
||||
|
||||
def set_presence_service(self, pservice):
|
||||
def set_owner(self, owner):
|
||||
root = self._view.get_model().get_root_item()
|
||||
|
||||
icon_layout = IconLayout(MeshGroup.WIDTH, MeshGroup.HEIGHT)
|
||||
@ -38,7 +38,7 @@ class HomeWindow(gtk.Window):
|
||||
y2 = y1 + FriendsGroup.HEIGHT
|
||||
icon_layout.set_bounds(x1, y1, x2, y2)
|
||||
|
||||
self._mesh_group = MeshGroup(self._shell, icon_layout, pservice)
|
||||
self._mesh_group = MeshGroup(self._shell, owner, icon_layout)
|
||||
root.add_child(self._mesh_group)
|
||||
|
||||
icon_layout = IconLayout(FriendsGroup.WIDTH, FriendsGroup.HEIGHT)
|
||||
@ -48,7 +48,7 @@ class HomeWindow(gtk.Window):
|
||||
y2 = y1 + HomeGroup.HEIGHT
|
||||
icon_layout.set_bounds(x1, y1, x2, y2)
|
||||
|
||||
self._friends_group = FriendsGroup(icon_layout)
|
||||
self._friends_group = FriendsGroup(owner, icon_layout)
|
||||
self._friends_group.translate((self._width - FriendsGroup.WIDTH) / 2,
|
||||
(self._height - FriendsGroup.HEIGHT) / 2)
|
||||
root.add_child(self._friends_group)
|
||||
|
@ -34,7 +34,7 @@ class MeshGroup(goocanvas.Group):
|
||||
WIDTH = 1200.0 * 3.5
|
||||
HEIGHT = 900.0 * 3.5
|
||||
|
||||
def __init__(self, shell, icon_layout, pservice):
|
||||
def __init__(self, shell, owner, icon_layout):
|
||||
goocanvas.Group.__init__(self)
|
||||
self._shell = shell
|
||||
self._icon_layout = icon_layout
|
||||
@ -48,6 +48,7 @@ class MeshGroup(goocanvas.Group):
|
||||
fill_color=color)
|
||||
self.add_child(self._mesh_rect)
|
||||
|
||||
pservice = PresenceService.get_instance()
|
||||
pservice.connect("service-appeared", self.__service_appeared_cb)
|
||||
|
||||
for service in pservice.get_services():
|
||||
|
Loading…
Reference in New Issue
Block a user