More refactoring of the home implementation
This commit is contained in:
parent
adb269709c
commit
028d22cdd7
@ -8,8 +8,6 @@ import gobject
|
|||||||
import wnck
|
import wnck
|
||||||
|
|
||||||
from home.HomeWindow import HomeWindow
|
from home.HomeWindow import HomeWindow
|
||||||
from home.HomeModel import HomeModel
|
|
||||||
from sugar import env
|
|
||||||
from Owner import ShellOwner
|
from Owner import ShellOwner
|
||||||
from sugar.presence import PresenceService
|
from sugar.presence import PresenceService
|
||||||
from ActivityHost import ActivityHost
|
from ActivityHost import ActivityHost
|
||||||
@ -19,8 +17,9 @@ from sugar.activity import Activity
|
|||||||
from FirstTimeDialog import FirstTimeDialog
|
from FirstTimeDialog import FirstTimeDialog
|
||||||
from panel.PanelManager import PanelManager
|
from panel.PanelManager import PanelManager
|
||||||
from globalkeys import KeyGrabber
|
from globalkeys import KeyGrabber
|
||||||
import sugar
|
|
||||||
from sugar import conf
|
from sugar import conf
|
||||||
|
from sugar import env
|
||||||
|
import sugar
|
||||||
import sugar.logger
|
import sugar.logger
|
||||||
|
|
||||||
class ShellDbusService(dbus.service.Object):
|
class ShellDbusService(dbus.service.Object):
|
||||||
@ -105,17 +104,17 @@ class Shell(gobject.GObject):
|
|||||||
self._owner = ShellOwner()
|
self._owner = ShellOwner()
|
||||||
self._owner.announce()
|
self._owner.announce()
|
||||||
|
|
||||||
|
self._pservice = PresenceService.get_instance()
|
||||||
|
self._home_window.set_presence_service(self._pservice)
|
||||||
|
|
||||||
self._chat_controller = ChatController(self)
|
self._chat_controller = ChatController(self)
|
||||||
self._chat_controller.listen()
|
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 = PanelManager(self)
|
||||||
self._panel_manager.show_and_hide(10)
|
self._panel_manager.show_and_hide(10)
|
||||||
|
|
||||||
|
self.set_zoom_level(sugar.ZOOM_HOME)
|
||||||
|
|
||||||
def set_console(self, console):
|
def set_console(self, console):
|
||||||
self._console = console
|
self._console = console
|
||||||
|
|
||||||
@ -177,8 +176,7 @@ class Shell(gobject.GObject):
|
|||||||
if activity:
|
if activity:
|
||||||
activity.present()
|
activity.present()
|
||||||
else:
|
else:
|
||||||
pservice = PresenceService.get_instance()
|
activity_ps = self._pservice.get_activity(activity_id)
|
||||||
activity_ps = pservice.get_activity(activity_id)
|
|
||||||
|
|
||||||
if activity_ps:
|
if activity_ps:
|
||||||
activity = ActivityFactory.create(info.get_id())
|
activity = ActivityFactory.create(info.get_id())
|
||||||
|
@ -18,7 +18,7 @@ class FriendsGroup(goocanvas.Group):
|
|||||||
WIDTH = 1200.0 * 1.9
|
WIDTH = 1200.0 * 1.9
|
||||||
HEIGHT = 900.0 * 1.9
|
HEIGHT = 900.0 * 1.9
|
||||||
|
|
||||||
def __init__(self, icon_layout, data_model):
|
def __init__(self, icon_layout):
|
||||||
goocanvas.Group.__init__(self)
|
goocanvas.Group.__init__(self)
|
||||||
self._friend_to_child = {}
|
self._friend_to_child = {}
|
||||||
|
|
||||||
@ -34,11 +34,11 @@ class FriendsGroup(goocanvas.Group):
|
|||||||
radius_x=60, radius_y=60)
|
radius_x=60, radius_y=60)
|
||||||
self.add_child(self._friends_rect)
|
self.add_child(self._friends_rect)
|
||||||
|
|
||||||
for friend in data_model:
|
# for friend in data_model:
|
||||||
self.add_friend(friend)
|
# self.add_friend(friend)
|
||||||
|
|
||||||
data_model.connect('friend-added', self.__friend_added_cb)
|
# data_model.connect('friend-added', self.__friend_added_cb)
|
||||||
data_model.connect('friend-removed', self.__friend_removed_cb)
|
# data_model.connect('friend-removed', self.__friend_removed_cb)
|
||||||
|
|
||||||
def __theme_changed_cb(self, theme):
|
def __theme_changed_cb(self, theme):
|
||||||
color = self._theme.get_home_friends_color()
|
color = self._theme.get_home_friends_color()
|
||||||
|
@ -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)
|
|
@ -1,8 +0,0 @@
|
|||||||
from home.FriendsModel import FriendsModel
|
|
||||||
|
|
||||||
class HomeModel:
|
|
||||||
def __init__(self):
|
|
||||||
self._friends = FriendsModel()
|
|
||||||
|
|
||||||
def get_friends(self):
|
|
||||||
return self._friends
|
|
@ -28,7 +28,7 @@ class HomeWindow(gtk.Window):
|
|||||||
self.realize()
|
self.realize()
|
||||||
self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DESKTOP)
|
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()
|
root = self._view.get_model().get_root_item()
|
||||||
|
|
||||||
icon_layout = IconLayout(MeshGroup.WIDTH, MeshGroup.HEIGHT)
|
icon_layout = IconLayout(MeshGroup.WIDTH, MeshGroup.HEIGHT)
|
||||||
@ -38,7 +38,7 @@ class HomeWindow(gtk.Window):
|
|||||||
y2 = y1 + FriendsGroup.HEIGHT
|
y2 = y1 + FriendsGroup.HEIGHT
|
||||||
icon_layout.set_bounds(x1, y1, x2, y2)
|
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)
|
root.add_child(self._mesh_group)
|
||||||
|
|
||||||
icon_layout = IconLayout(FriendsGroup.WIDTH, FriendsGroup.HEIGHT)
|
icon_layout = IconLayout(FriendsGroup.WIDTH, FriendsGroup.HEIGHT)
|
||||||
@ -48,8 +48,7 @@ class HomeWindow(gtk.Window):
|
|||||||
y2 = y1 + HomeGroup.HEIGHT
|
y2 = y1 + HomeGroup.HEIGHT
|
||||||
icon_layout.set_bounds(x1, y1, x2, y2)
|
icon_layout.set_bounds(x1, y1, x2, y2)
|
||||||
|
|
||||||
data_model = model.get_friends()
|
self._friends_group = FriendsGroup(icon_layout)
|
||||||
self._friends_group = FriendsGroup(icon_layout, data_model)
|
|
||||||
self._friends_group.translate((self._width - FriendsGroup.WIDTH) / 2,
|
self._friends_group.translate((self._width - FriendsGroup.WIDTH) / 2,
|
||||||
(self._height - FriendsGroup.HEIGHT) / 2)
|
(self._height - FriendsGroup.HEIGHT) / 2)
|
||||||
root.add_child(self._friends_group)
|
root.add_child(self._friends_group)
|
||||||
|
@ -2,12 +2,9 @@ sugardir = $(pkgdatadir)/shell/home
|
|||||||
sugar_PYTHON = \
|
sugar_PYTHON = \
|
||||||
__init__.py \
|
__init__.py \
|
||||||
DonutItem.py \
|
DonutItem.py \
|
||||||
FriendsModel.py \
|
|
||||||
FriendsGroup.py \
|
FriendsGroup.py \
|
||||||
IconLayout.py \
|
IconLayout.py \
|
||||||
MeshModel.py \
|
|
||||||
MeshGroup.py \
|
MeshGroup.py \
|
||||||
HomeGroup.py \
|
HomeGroup.py \
|
||||||
HomeWindow.py \
|
HomeWindow.py \
|
||||||
HomeModel.py \
|
|
||||||
Theme.py
|
Theme.py
|
||||||
|
@ -30,14 +30,11 @@ class ActivityItem(IconItem):
|
|||||||
activity = pservice.get_activity(self.get_id())
|
activity = pservice.get_activity(self.get_id())
|
||||||
return IconColor(activity.get_color())
|
return IconColor(activity.get_color())
|
||||||
|
|
||||||
def get_service(self):
|
|
||||||
return self._service
|
|
||||||
|
|
||||||
class MeshGroup(goocanvas.Group):
|
class MeshGroup(goocanvas.Group):
|
||||||
WIDTH = 1200.0 * 3.5
|
WIDTH = 1200.0 * 3.5
|
||||||
HEIGHT = 900.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)
|
goocanvas.Group.__init__(self)
|
||||||
self._shell = shell
|
self._shell = shell
|
||||||
self._icon_layout = icon_layout
|
self._icon_layout = icon_layout
|
||||||
@ -51,10 +48,9 @@ class MeshGroup(goocanvas.Group):
|
|||||||
fill_color=color)
|
fill_color=color)
|
||||||
self.add_child(self._mesh_rect)
|
self.add_child(self._mesh_rect)
|
||||||
|
|
||||||
self._pservice = PresenceService.get_instance()
|
pservice.connect("service-appeared", self.__service_appeared_cb)
|
||||||
self._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)
|
self.__check_service(service)
|
||||||
|
|
||||||
def __service_appeared_cb(self, pservice, service):
|
def __service_appeared_cb(self, pservice, service):
|
||||||
|
Loading…
Reference in New Issue
Block a user