Start implementing friends/mesh

This commit is contained in:
Marco Pesenti Gritti 2006-08-19 11:12:25 +02:00
parent de65daf548
commit 0d4acb6e78
12 changed files with 104 additions and 15 deletions

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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):

13
shell/home/HomeModel.py Normal file
View File

@ -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

View File

@ -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()

View File

@ -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

View File

@ -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])),

View File

@ -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):

View File

@ -1,4 +1,4 @@
SUBDIRS = activity chat p2p presence
SUBDIRS = activity canvas chat p2p presence
sugardir = $(pythondir)/sugar
sugar_PYTHON = \

View File

@ -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')

View File

@ -1,4 +1,5 @@
sugardir = $(pythondir)/sugar/canvas
sugar_PYTHON = \
__init__.py \
DonutItem.py \
IconItem.py