More refactoring of the home implementation

This commit is contained in:
Marco Pesenti Gritti 2006-08-30 11:15:21 +02:00
parent adb269709c
commit 028d22cdd7
7 changed files with 19 additions and 97 deletions

View File

@ -8,8 +8,6 @@ import gobject
import wnck
from home.HomeWindow import HomeWindow
from home.HomeModel import HomeModel
from sugar import env
from Owner import ShellOwner
from sugar.presence import PresenceService
from ActivityHost import ActivityHost
@ -19,8 +17,9 @@ from sugar.activity import Activity
from FirstTimeDialog import FirstTimeDialog
from panel.PanelManager import PanelManager
from globalkeys import KeyGrabber
import sugar
from sugar import conf
from sugar import env
import sugar
import sugar.logger
class ShellDbusService(dbus.service.Object):
@ -105,17 +104,17 @@ class Shell(gobject.GObject):
self._owner = ShellOwner()
self._owner.announce()
self._pservice = PresenceService.get_instance()
self._home_window.set_presence_service(self._pservice)
self._chat_controller = ChatController(self)
self._chat_controller.listen()
self.set_zoom_level(sugar.ZOOM_HOME)
home_model = HomeModel()
self._home_window.set_model(home_model)
self._panel_manager = PanelManager(self)
self._panel_manager.show_and_hide(10)
self.set_zoom_level(sugar.ZOOM_HOME)
def set_console(self, console):
self._console = console
@ -177,8 +176,7 @@ class Shell(gobject.GObject):
if activity:
activity.present()
else:
pservice = PresenceService.get_instance()
activity_ps = pservice.get_activity(activity_id)
activity_ps = self._pservice.get_activity(activity_id)
if activity_ps:
activity = ActivityFactory.create(info.get_id())

View File

@ -18,7 +18,7 @@ class FriendsGroup(goocanvas.Group):
WIDTH = 1200.0 * 1.9
HEIGHT = 900.0 * 1.9
def __init__(self, icon_layout, data_model):
def __init__(self, icon_layout):
goocanvas.Group.__init__(self)
self._friend_to_child = {}
@ -34,11 +34,11 @@ class FriendsGroup(goocanvas.Group):
radius_x=60, radius_y=60)
self.add_child(self._friends_rect)
for friend in data_model:
self.add_friend(friend)
# for friend in data_model:
# self.add_friend(friend)
data_model.connect('friend-added', self.__friend_added_cb)
data_model.connect('friend-removed', self.__friend_removed_cb)
# data_model.connect('friend-added', self.__friend_added_cb)
# data_model.connect('friend-removed', self.__friend_removed_cb)
def __theme_changed_cb(self, theme):
color = self._theme.get_home_friends_color()

View File

@ -1,60 +0,0 @@
import gobject
from sugar.presence import PresenceService
from sugar.canvas.IconColor import IconColor
import logging
class Friend:
def __init__(self, buddy):
self._buddy = buddy
def get_name(self):
return self._buddy.get_name()
def get_color(self):
color = self._buddy.get_color()
try:
icolor = IconColor(color)
except RuntimeError:
icolor = IconColor()
logging.info("Buddy %s doesn't have an allowed color; \
using a random color instead." % self.get_name())
return icolor
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.get_instance()
self._pservice.connect("buddy-appeared", self.__buddy_appeared_cb)
self._pservice.connect("buddy-disappeared", self.__buddy_disappeared_cb)
for buddy in self._pservice.get_buddies():
self.add_friend(buddy)
def add_friend(self, buddy):
friend = Friend(buddy)
self._friends[buddy.get_name()] = friend
self.emit('friend-added', friend)
def remove_friend(self, buddy):
self.emit('friend-removed', self._friends[buddy.get_name()])
del self._friends[buddy.get_name()]
def __iter__(self):
return self._friends.values().__iter__()
def __buddy_appeared_cb(self, pservice, buddy):
self.add_friend(buddy)
def __buddy_disappeared_cb(self, pservice, buddy):
self.remove_friend(buddy)

View File

@ -1,8 +0,0 @@
from home.FriendsModel import FriendsModel
class HomeModel:
def __init__(self):
self._friends = FriendsModel()
def get_friends(self):
return self._friends

View File

@ -28,7 +28,7 @@ class HomeWindow(gtk.Window):
self.realize()
self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DESKTOP)
def set_model(self, model):
def set_presence_service(self, pservice):
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)
self._mesh_group = MeshGroup(self._shell, icon_layout, pservice)
root.add_child(self._mesh_group)
icon_layout = IconLayout(FriendsGroup.WIDTH, FriendsGroup.HEIGHT)
@ -48,8 +48,7 @@ class HomeWindow(gtk.Window):
y2 = y1 + HomeGroup.HEIGHT
icon_layout.set_bounds(x1, y1, x2, y2)
data_model = model.get_friends()
self._friends_group = FriendsGroup(icon_layout, data_model)
self._friends_group = FriendsGroup(icon_layout)
self._friends_group.translate((self._width - FriendsGroup.WIDTH) / 2,
(self._height - FriendsGroup.HEIGHT) / 2)
root.add_child(self._friends_group)

View File

@ -2,12 +2,9 @@ sugardir = $(pkgdatadir)/shell/home
sugar_PYTHON = \
__init__.py \
DonutItem.py \
FriendsModel.py \
FriendsGroup.py \
IconLayout.py \
MeshModel.py \
MeshGroup.py \
HomeGroup.py \
HomeWindow.py \
HomeModel.py \
Theme.py

View File

@ -30,14 +30,11 @@ class ActivityItem(IconItem):
activity = pservice.get_activity(self.get_id())
return IconColor(activity.get_color())
def get_service(self):
return self._service
class MeshGroup(goocanvas.Group):
WIDTH = 1200.0 * 3.5
HEIGHT = 900.0 * 3.5
def __init__(self, shell, icon_layout):
def __init__(self, shell, icon_layout, pservice):
goocanvas.Group.__init__(self)
self._shell = shell
self._icon_layout = icon_layout
@ -51,10 +48,9 @@ class MeshGroup(goocanvas.Group):
fill_color=color)
self.add_child(self._mesh_rect)
self._pservice = PresenceService.get_instance()
self._pservice.connect("service-appeared", self.__service_appeared_cb)
pservice.connect("service-appeared", self.__service_appeared_cb)
for service in self._pservice.get_services():
for service in pservice.get_services():
self.__check_service(service)
def __service_appeared_cb(self, pservice, service):