Simplify overdesigned Mesh view impl
This commit is contained in:
parent
aea10ae900
commit
cd0b794879
@ -8,6 +8,3 @@ class HomeModel:
|
||||
|
||||
def get_friends(self):
|
||||
return self._friends
|
||||
|
||||
def get_mesh(self):
|
||||
return self._mesh
|
||||
|
@ -38,8 +38,7 @@ class HomeWindow(gtk.Window):
|
||||
y2 = y1 + FriendsGroup.HEIGHT
|
||||
icon_layout.set_bounds(x1, y1, x2, y2)
|
||||
|
||||
data_model = model.get_mesh()
|
||||
self._mesh_group = MeshGroup(self._shell, icon_layout, data_model)
|
||||
self._mesh_group = MeshGroup(self._shell, icon_layout)
|
||||
root.add_child(self._mesh_group)
|
||||
|
||||
icon_layout = IconLayout(FriendsGroup.WIDTH, FriendsGroup.HEIGHT)
|
||||
|
@ -4,35 +4,46 @@ import goocanvas
|
||||
|
||||
from sugar.canvas.IconItem import IconItem
|
||||
from sugar.canvas.IconItem import IconColor
|
||||
from sugar.presence import PresenceService
|
||||
from sugar import conf
|
||||
|
||||
import Theme
|
||||
|
||||
class ActivityItem(IconItem):
|
||||
def __init__(self, activity):
|
||||
def __init__(self, service):
|
||||
self._service = service
|
||||
|
||||
IconItem.__init__(self, icon_name=self.get_icon_name(),
|
||||
color=self.get_color(), size=144)
|
||||
|
||||
def get_id(self):
|
||||
return self._service.get_activity_id()
|
||||
|
||||
def get_icon_name(self):
|
||||
registry = conf.get_activity_registry()
|
||||
info = registry.get_activity(activity.get_type())
|
||||
icon_name = info.get_icon()
|
||||
info = registry.get_activity(self._service.get_type())
|
||||
|
||||
IconItem.__init__(self, icon_name=icon_name,
|
||||
color=activity.get_color(), size=144)
|
||||
|
||||
self._activity = activity
|
||||
return info.get_icon()
|
||||
|
||||
def get_color(self):
|
||||
pservice = PresenceService.get_instance()
|
||||
activity = pservice.get_activity(self.get_id())
|
||||
return IconColor(activity.get_color())
|
||||
|
||||
def get_service(self):
|
||||
return self._activity.get_service()
|
||||
return self._service
|
||||
|
||||
class MeshGroup(goocanvas.Group):
|
||||
WIDTH = 1200.0 * 3.5
|
||||
HEIGHT = 900.0 * 3.5
|
||||
|
||||
def __init__(self, shell, icon_layout, data_model):
|
||||
def __init__(self, shell, icon_layout):
|
||||
goocanvas.Group.__init__(self)
|
||||
self._shell = shell
|
||||
self._icon_layout = icon_layout
|
||||
self._activities = {}
|
||||
|
||||
self._theme = Theme.get_instance()
|
||||
self._theme.connect("theme-changed", self.__theme_changed_cb)
|
||||
|
||||
color = self._theme.get_home_mesh_color()
|
||||
self._mesh_rect = goocanvas.Rect(width=MeshGroup.WIDTH,
|
||||
@ -40,22 +51,32 @@ class MeshGroup(goocanvas.Group):
|
||||
fill_color=color)
|
||||
self.add_child(self._mesh_rect)
|
||||
|
||||
for activity in data_model:
|
||||
self.add_activity(activity)
|
||||
self._pservice = PresenceService.get_instance()
|
||||
self._pservice.connect("service-appeared", self.__service_appeared_cb)
|
||||
|
||||
data_model.connect('activity-added', self.__activity_added_cb)
|
||||
for service in self._pservice.get_services():
|
||||
self.__check_service(service)
|
||||
|
||||
def __theme_changed_cb(self, theme):
|
||||
pass
|
||||
def __service_appeared_cb(self, pservice, service):
|
||||
self.__check_service(service)
|
||||
|
||||
def add_activity(self, activity):
|
||||
item = ActivityItem(activity)
|
||||
def __check_service(self, service):
|
||||
registry = conf.get_activity_registry()
|
||||
if registry.get_activity(service.get_type()) != None:
|
||||
if not self.has_activity(service.get_activity_id()):
|
||||
self.add_activity(service)
|
||||
|
||||
def has_activity(self, activity_id):
|
||||
return self._activities.has_key(activity_id)
|
||||
|
||||
def add_activity(self, service):
|
||||
item = ActivityItem(service)
|
||||
item.connect('clicked', self.__activity_clicked_cb)
|
||||
|
||||
self._icon_layout.add_icon(item)
|
||||
self.add_child(item)
|
||||
|
||||
def __activity_added_cb(self, data_model, activity):
|
||||
self.add_activity(activity)
|
||||
self._activities[item.get_id()] = item
|
||||
|
||||
def __activity_clicked_cb(self, item):
|
||||
self._shell.join_activity(item.get_service())
|
||||
|
@ -1,66 +0,0 @@
|
||||
import gobject
|
||||
|
||||
from sugar.presence import PresenceService
|
||||
from sugar.canvas.IconColor import IconColor
|
||||
from sugar import conf
|
||||
|
||||
class ActivityInfo:
|
||||
def __init__(self, service):
|
||||
self._service = service
|
||||
|
||||
def get_id(self):
|
||||
return self._service.get_activity_id()
|
||||
|
||||
def get_type(self):
|
||||
return self._service.get_type()
|
||||
|
||||
def get_title(self):
|
||||
return self._service.get_published_value('title')
|
||||
|
||||
def get_color(self):
|
||||
pservice = PresenceService.get_instance()
|
||||
activity = pservice.get_activity(self.get_id())
|
||||
return IconColor(activity.get_color())
|
||||
|
||||
def get_service(self):
|
||||
return self._service
|
||||
|
||||
class MeshModel(gobject.GObject):
|
||||
__gsignals__ = {
|
||||
'activity-added': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
|
||||
([gobject.TYPE_PYOBJECT])),
|
||||
'activity-removed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
|
||||
([gobject.TYPE_PYOBJECT]))
|
||||
}
|
||||
|
||||
def __init__(self):
|
||||
gobject.GObject.__init__(self)
|
||||
|
||||
self._activities = {}
|
||||
|
||||
self._pservice = PresenceService.get_instance()
|
||||
self._pservice.connect("service-appeared", self.__service_appeared_cb)
|
||||
|
||||
for service in self._pservice.get_services():
|
||||
self.__check_service(service)
|
||||
|
||||
def has_activity(self, activity_id):
|
||||
return self._activities.has_key(activity_id)
|
||||
|
||||
def add_activity(self, service):
|
||||
activity_info = ActivityInfo(service)
|
||||
self._activities[activity_info.get_id()] = (activity_info)
|
||||
self.emit('activity-added', activity_info)
|
||||
|
||||
def __iter__(self):
|
||||
activities = self._activities.values()
|
||||
return activities.__iter__()
|
||||
|
||||
def __service_appeared_cb(self, pservice, service):
|
||||
self.__check_service(service)
|
||||
|
||||
def __check_service(self, service):
|
||||
registry = conf.get_activity_registry()
|
||||
if registry.get_activity(service.get_type()) != None:
|
||||
if not self.has_activity(service.get_activity_id()):
|
||||
self.add_activity(service)
|
Loading…
Reference in New Issue
Block a user