Start implementing friends/mesh
This commit is contained in:
parent
de65daf548
commit
0d4acb6e78
@ -36,6 +36,7 @@ shell/PresenceService/Makefile
|
|||||||
sugar/Makefile
|
sugar/Makefile
|
||||||
sugar/__installed__.py
|
sugar/__installed__.py
|
||||||
sugar/activity/Makefile
|
sugar/activity/Makefile
|
||||||
|
sugar/canvas/Makefile
|
||||||
sugar/chat/Makefile
|
sugar/chat/Makefile
|
||||||
sugar/chat/sketchpad/Makefile
|
sugar/chat/sketchpad/Makefile
|
||||||
sugar/p2p/Makefile
|
sugar/p2p/Makefile
|
||||||
|
@ -9,6 +9,7 @@ import wnck
|
|||||||
|
|
||||||
from ActivityRegistry import ActivityRegistry
|
from ActivityRegistry import ActivityRegistry
|
||||||
from home.HomeWindow import HomeWindow
|
from home.HomeWindow import HomeWindow
|
||||||
|
from home.HomeModel import HomeModel
|
||||||
from sugar import env
|
from sugar import env
|
||||||
from Owner import ShellOwner
|
from Owner import ShellOwner
|
||||||
from sugar.presence.PresenceService import PresenceService
|
from sugar.presence.PresenceService import PresenceService
|
||||||
@ -77,7 +78,8 @@ class Shell(gobject.GObject):
|
|||||||
self._chat_controller = ChatController(self)
|
self._chat_controller = ChatController(self)
|
||||||
self._chat_controller.listen()
|
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._home_window.show()
|
||||||
|
|
||||||
self._screen.connect('window-opened', self.__window_opened_cb)
|
self._screen.connect('window-opened', self.__window_opened_cb)
|
||||||
|
40
shell/home/FriendsModel.py
Normal file
40
shell/home/FriendsModel.py
Normal 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)
|
@ -1,19 +1,44 @@
|
|||||||
|
import random
|
||||||
|
|
||||||
import goocanvas
|
import goocanvas
|
||||||
|
|
||||||
|
from sugar.canvas.IconItem import IconItem
|
||||||
|
|
||||||
class Model(goocanvas.CanvasModelSimple):
|
class Model(goocanvas.CanvasModelSimple):
|
||||||
def __init__(self, shell):
|
def __init__(self, data_model):
|
||||||
goocanvas.CanvasModelSimple.__init__(self)
|
goocanvas.CanvasModelSimple.__init__(self)
|
||||||
|
|
||||||
root = self.get_root_item()
|
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):
|
class FriendsView(goocanvas.CanvasView):
|
||||||
def __init__(self, shell):
|
def __init__(self, shell, data_model):
|
||||||
goocanvas.CanvasView.__init__(self)
|
goocanvas.CanvasView.__init__(self)
|
||||||
self._shell = shell
|
self._shell = shell
|
||||||
|
|
||||||
self.connect("item_view_created", self.__item_view_created_cb)
|
self.connect("item_view_created", self.__item_view_created_cb)
|
||||||
|
|
||||||
canvas_model = Model(shell)
|
canvas_model = Model(data_model)
|
||||||
self.set_model(canvas_model)
|
self.set_model(canvas_model)
|
||||||
|
|
||||||
def __item_view_created_cb(self, view, item_view, item):
|
def __item_view_created_cb(self, view, item_view, item):
|
||||||
|
13
shell/home/HomeModel.py
Normal file
13
shell/home/HomeModel.py
Normal 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
|
@ -9,7 +9,7 @@ class HomeWindow(gtk.Window):
|
|||||||
FRIENDS_VIEW = 1
|
FRIENDS_VIEW = 1
|
||||||
MESH_VIEW = 2
|
MESH_VIEW = 2
|
||||||
|
|
||||||
def __init__(self, shell):
|
def __init__(self, shell, model):
|
||||||
gtk.Window.__init__(self)
|
gtk.Window.__init__(self)
|
||||||
|
|
||||||
self.connect('realize', self.__realize_cb)
|
self.connect('realize', self.__realize_cb)
|
||||||
@ -23,12 +23,12 @@ class HomeWindow(gtk.Window):
|
|||||||
self._setup_canvas(home_view)
|
self._setup_canvas(home_view)
|
||||||
home_view.show()
|
home_view.show()
|
||||||
|
|
||||||
friends_view = FriendsView(shell)
|
friends_view = FriendsView(shell, model.get_friends())
|
||||||
self._nb.append_page(friends_view)
|
self._nb.append_page(friends_view)
|
||||||
self._setup_canvas(friends_view)
|
self._setup_canvas(friends_view)
|
||||||
friends_view.show()
|
friends_view.show()
|
||||||
|
|
||||||
mesh_view = MeshView(shell)
|
mesh_view = MeshView(shell, model.get_mesh())
|
||||||
self._setup_canvas(mesh_view)
|
self._setup_canvas(mesh_view)
|
||||||
self._nb.append_page(mesh_view)
|
self._nb.append_page(mesh_view)
|
||||||
mesh_view.show()
|
mesh_view.show()
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
sugardir = $(pkgdatadir)/shell
|
sugardir = $(pkgdatadir)/shell/home
|
||||||
sugar_PYTHON = \
|
sugar_PYTHON = \
|
||||||
__init__.py \
|
__init__.py \
|
||||||
|
FriendsModel.py \
|
||||||
FriendsView.py \
|
FriendsView.py \
|
||||||
|
MeshModel.py \
|
||||||
MeshView.py \
|
MeshView.py \
|
||||||
HomeView.py \
|
HomeView.py \
|
||||||
HomeWindow.py
|
HomeWindow.py \
|
||||||
|
HomeModel.py
|
||||||
|
@ -19,7 +19,7 @@ class ActivityInfo:
|
|||||||
def get_service(self):
|
def get_service(self):
|
||||||
return self._service
|
return self._service
|
||||||
|
|
||||||
class ActivitiesModel(gobject.GObject):
|
class MeshModel(gobject.GObject):
|
||||||
__gsignals__ = {
|
__gsignals__ = {
|
||||||
'activity-added': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
|
'activity-added': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
|
||||||
([gobject.TYPE_PYOBJECT])),
|
([gobject.TYPE_PYOBJECT])),
|
@ -1,19 +1,23 @@
|
|||||||
import goocanvas
|
import goocanvas
|
||||||
|
|
||||||
class Model(goocanvas.CanvasModelSimple):
|
class Model(goocanvas.CanvasModelSimple):
|
||||||
def __init__(self, shell):
|
def __init__(self, data_model):
|
||||||
goocanvas.CanvasModelSimple.__init__(self)
|
goocanvas.CanvasModelSimple.__init__(self)
|
||||||
|
|
||||||
root = self.get_root_item()
|
root = self.get_root_item()
|
||||||
|
|
||||||
|
item = goocanvas.Rect(width=1200, height=900,
|
||||||
|
fill_color="#4f4f4f")
|
||||||
|
root.add_child(item)
|
||||||
|
|
||||||
class MeshView(goocanvas.CanvasView):
|
class MeshView(goocanvas.CanvasView):
|
||||||
def __init__(self, shell):
|
def __init__(self, shell, data_model):
|
||||||
goocanvas.CanvasView.__init__(self)
|
goocanvas.CanvasView.__init__(self)
|
||||||
self._shell = shell
|
self._shell = shell
|
||||||
|
|
||||||
self.connect("item_view_created", self.__item_view_created_cb)
|
self.connect("item_view_created", self.__item_view_created_cb)
|
||||||
|
|
||||||
canvas_model = Model(shell)
|
canvas_model = Model(data_model)
|
||||||
self.set_model(canvas_model)
|
self.set_model(canvas_model)
|
||||||
|
|
||||||
def __item_view_created_cb(self, view, item_view, item):
|
def __item_view_created_cb(self, view, item_view, item):
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
SUBDIRS = activity chat p2p presence
|
SUBDIRS = activity canvas chat p2p presence
|
||||||
|
|
||||||
sugardir = $(pythondir)/sugar
|
sugardir = $(pythondir)/sugar
|
||||||
sugar_PYTHON = \
|
sugar_PYTHON = \
|
||||||
|
@ -21,7 +21,7 @@ class IconCache(gobject.GObject):
|
|||||||
icon_file.close()
|
icon_file.close()
|
||||||
|
|
||||||
if color != None:
|
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)
|
data = re.sub('\.fill-color \{.*\}', style, data)
|
||||||
|
|
||||||
loader = gtk.gdk.pixbuf_loader_new_with_mime_type('image/svg-xml')
|
loader = gtk.gdk.pixbuf_loader_new_with_mime_type('image/svg-xml')
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
sugardir = $(pythondir)/sugar/canvas
|
sugardir = $(pythondir)/sugar/canvas
|
||||||
sugar_PYTHON = \
|
sugar_PYTHON = \
|
||||||
__init__.py \
|
__init__.py \
|
||||||
|
DonutItem.py \
|
||||||
IconItem.py
|
IconItem.py
|
||||||
|
Loading…
Reference in New Issue
Block a user