From 0d4acb6e78ecd52b31b0b861bcf4a77b22936e59 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Sat, 19 Aug 2006 11:12:25 +0200 Subject: [PATCH] Start implementing friends/mesh --- configure.ac | 1 + shell/Shell.py | 4 +- shell/home/FriendsModel.py | 40 +++++++++++++++++++ shell/home/FriendsView.py | 31 ++++++++++++-- shell/home/HomeModel.py | 13 ++++++ shell/home/HomeWindow.py | 6 +-- shell/home/Makefile.am | 7 +++- .../home/{ActivitiesModel.py => MeshModel.py} | 2 +- shell/home/MeshView.py | 10 +++-- sugar/Makefile.am | 2 +- sugar/canvas/IconItem.py | 2 +- sugar/canvas/Makefile.am | 1 + 12 files changed, 104 insertions(+), 15 deletions(-) create mode 100644 shell/home/FriendsModel.py create mode 100644 shell/home/HomeModel.py rename shell/home/{ActivitiesModel.py => MeshModel.py} (97%) diff --git a/configure.ac b/configure.ac index 735c2cc9..e569750c 100644 --- a/configure.ac +++ b/configure.ac @@ -36,6 +36,7 @@ shell/PresenceService/Makefile sugar/Makefile sugar/__installed__.py sugar/activity/Makefile +sugar/canvas/Makefile sugar/chat/Makefile sugar/chat/sketchpad/Makefile sugar/p2p/Makefile diff --git a/shell/Shell.py b/shell/Shell.py index c8ebe06a..5876f703 100755 --- a/shell/Shell.py +++ b/shell/Shell.py @@ -9,6 +9,7 @@ import wnck from ActivityRegistry import ActivityRegistry from home.HomeWindow import HomeWindow +from home.HomeModel import HomeModel from sugar import env from Owner import ShellOwner from sugar.presence.PresenceService import PresenceService @@ -77,7 +78,8 @@ class Shell(gobject.GObject): self._chat_controller = ChatController(self) self._chat_controller.listen() - self._home_window = HomeWindow(self) + home_model = HomeModel(self._registry) + self._home_window = HomeWindow(self, home_model) self._home_window.show() self._screen.connect('window-opened', self.__window_opened_cb) diff --git a/shell/home/FriendsModel.py b/shell/home/FriendsModel.py new file mode 100644 index 00000000..6f18083a --- /dev/null +++ b/shell/home/FriendsModel.py @@ -0,0 +1,40 @@ +import gobject + +from sugar.presence.PresenceService import PresenceService + +class Friend: + def __init__(self, buddy): + self._buddy = buddy + + def get_name(self): + return self._buddy.get_name() + +class FriendsModel(gobject.GObject): + __gsignals__ = { + 'friend-added': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, + ([gobject.TYPE_PYOBJECT])), + 'friend-removed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, + ([gobject.TYPE_PYOBJECT])) + } + + def __init__(self): + gobject.GObject.__init__(self) + + self._friends = [] + + self._pservice = PresenceService() + self._pservice.connect("buddy-appeared", self.__buddy_appeared_cb) + + for buddy in self._pservice.get_buddies(): + self.add_friend(buddy) + + def add_friend(self, buddy): + friend = Friend(buddy) + self._friends.append(friend) + self.emit('friend-added', friend) + + def __iter__(self): + return self._friends.__iter__() + + def __buddy_appeared_cb(self, pservice, buddy): + self.add_friend(buddy) diff --git a/shell/home/FriendsView.py b/shell/home/FriendsView.py index baa834bd..b12616a4 100644 --- a/shell/home/FriendsView.py +++ b/shell/home/FriendsView.py @@ -1,19 +1,44 @@ +import random + import goocanvas +from sugar.canvas.IconItem import IconItem + class Model(goocanvas.CanvasModelSimple): - def __init__(self, shell): + def __init__(self, data_model): goocanvas.CanvasModelSimple.__init__(self) root = self.get_root_item() + item = goocanvas.Rect(width=1200, height=900, + fill_color="#d8d8d8") + root.add_child(item) + + for friend in data_model: + self.add_friend(friend) + + data_model.connect('friend-added', self.__friend_added_cb) + + def add_friend(self, friend): + root = self.get_root_item() + + icon = IconItem('stock-buddy', 'green', 48) + icon.set_property('x', random.random() * 1100) + icon.set_property('y', random.random() * 800) + + root.add_child(icon) + + def __friend_added_cb(self, data_model, friend): + self.add_friend(friend) + class FriendsView(goocanvas.CanvasView): - def __init__(self, shell): + def __init__(self, shell, data_model): goocanvas.CanvasView.__init__(self) self._shell = shell self.connect("item_view_created", self.__item_view_created_cb) - canvas_model = Model(shell) + canvas_model = Model(data_model) self.set_model(canvas_model) def __item_view_created_cb(self, view, item_view, item): diff --git a/shell/home/HomeModel.py b/shell/home/HomeModel.py new file mode 100644 index 00000000..5f4965d3 --- /dev/null +++ b/shell/home/HomeModel.py @@ -0,0 +1,13 @@ +from home.FriendsModel import FriendsModel +from home.MeshModel import MeshModel + +class HomeModel: + def __init__(self, registry): + self._friends = FriendsModel() + self._mesh = MeshModel(registry) + + def get_friends(self): + return self._friends + + def get_mesh(self): + return self._mesh diff --git a/shell/home/HomeWindow.py b/shell/home/HomeWindow.py index ca3007da..86c83ab1 100644 --- a/shell/home/HomeWindow.py +++ b/shell/home/HomeWindow.py @@ -9,7 +9,7 @@ class HomeWindow(gtk.Window): FRIENDS_VIEW = 1 MESH_VIEW = 2 - def __init__(self, shell): + def __init__(self, shell, model): gtk.Window.__init__(self) self.connect('realize', self.__realize_cb) @@ -23,12 +23,12 @@ class HomeWindow(gtk.Window): self._setup_canvas(home_view) home_view.show() - friends_view = FriendsView(shell) + friends_view = FriendsView(shell, model.get_friends()) self._nb.append_page(friends_view) self._setup_canvas(friends_view) friends_view.show() - mesh_view = MeshView(shell) + mesh_view = MeshView(shell, model.get_mesh()) self._setup_canvas(mesh_view) self._nb.append_page(mesh_view) mesh_view.show() diff --git a/shell/home/Makefile.am b/shell/home/Makefile.am index 72445ecd..2a86a261 100644 --- a/shell/home/Makefile.am +++ b/shell/home/Makefile.am @@ -1,7 +1,10 @@ -sugardir = $(pkgdatadir)/shell +sugardir = $(pkgdatadir)/shell/home sugar_PYTHON = \ __init__.py \ + FriendsModel.py \ FriendsView.py \ + MeshModel.py \ MeshView.py \ HomeView.py \ - HomeWindow.py + HomeWindow.py \ + HomeModel.py diff --git a/shell/home/ActivitiesModel.py b/shell/home/MeshModel.py similarity index 97% rename from shell/home/ActivitiesModel.py rename to shell/home/MeshModel.py index c46256d2..b2163ac6 100644 --- a/shell/home/ActivitiesModel.py +++ b/shell/home/MeshModel.py @@ -19,7 +19,7 @@ class ActivityInfo: def get_service(self): return self._service -class ActivitiesModel(gobject.GObject): +class MeshModel(gobject.GObject): __gsignals__ = { 'activity-added': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT])), diff --git a/shell/home/MeshView.py b/shell/home/MeshView.py index 7b2e5f67..611ad182 100644 --- a/shell/home/MeshView.py +++ b/shell/home/MeshView.py @@ -1,19 +1,23 @@ import goocanvas class Model(goocanvas.CanvasModelSimple): - def __init__(self, shell): + def __init__(self, data_model): goocanvas.CanvasModelSimple.__init__(self) root = self.get_root_item() + item = goocanvas.Rect(width=1200, height=900, + fill_color="#4f4f4f") + root.add_child(item) + class MeshView(goocanvas.CanvasView): - def __init__(self, shell): + def __init__(self, shell, data_model): goocanvas.CanvasView.__init__(self) self._shell = shell self.connect("item_view_created", self.__item_view_created_cb) - canvas_model = Model(shell) + canvas_model = Model(data_model) self.set_model(canvas_model) def __item_view_created_cb(self, view, item_view, item): diff --git a/sugar/Makefile.am b/sugar/Makefile.am index 086d2918..a01427d0 100644 --- a/sugar/Makefile.am +++ b/sugar/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = activity chat p2p presence +SUBDIRS = activity canvas chat p2p presence sugardir = $(pythondir)/sugar sugar_PYTHON = \ diff --git a/sugar/canvas/IconItem.py b/sugar/canvas/IconItem.py index 153699b8..bf57bce9 100644 --- a/sugar/canvas/IconItem.py +++ b/sugar/canvas/IconItem.py @@ -21,7 +21,7 @@ class IconCache(gobject.GObject): icon_file.close() if color != None: - style = '.fill-color {fill: %s;}' % color + style = '.fill-color {fill: %s; stroke: %s;}' % (color, color) data = re.sub('\.fill-color \{.*\}', style, data) loader = gtk.gdk.pixbuf_loader_new_with_mime_type('image/svg-xml') diff --git a/sugar/canvas/Makefile.am b/sugar/canvas/Makefile.am index 9120ba25..35146695 100644 --- a/sugar/canvas/Makefile.am +++ b/sugar/canvas/Makefile.am @@ -1,4 +1,5 @@ sugardir = $(pythondir)/sugar/canvas sugar_PYTHON = \ __init__.py \ + DonutItem.py \ IconItem.py