sugar-toolkit-gtk3/shell/home/MeshGroup.py

77 lines
2.1 KiB
Python
Raw Normal View History

import random
import goocanvas
import conf
from sugar.canvas.IconItem import IconItem
from sugar.canvas.IconItem import IconColor
2006-08-30 10:54:28 +02:00
from sugar.presence import PresenceService
from home.IconLayout import IconLayout
class ActivityItem(IconItem):
2006-08-30 10:54:28 +02:00
def __init__(self, service):
self._service = service
IconItem.__init__(self, icon_name=self.get_icon_name(),
2006-09-09 02:05:00 +02:00
color=self.get_color(), size=96)
2006-08-30 10:54:28 +02:00
def get_id(self):
return self._service.get_activity_id()
def get_icon_name(self):
registry = conf.get_activity_registry()
info = registry.get_activity_from_type(self._service.get_type())
2006-08-30 10:54:28 +02:00
return info.get_icon()
def get_color(self):
pservice = PresenceService.get_instance()
activity = pservice.get_activity(self.get_id())
return IconColor(activity.get_color())
2006-08-30 13:14:37 +02:00
def get_service(self):
return self._service
class MeshGroup(goocanvas.Group):
def __init__(self, shell):
goocanvas.Group.__init__(self)
2006-08-29 16:17:00 +02:00
self._shell = shell
self._icon_layout = IconLayout(1200, 900)
2006-08-30 10:54:28 +02:00
self._activities = {}
pservice = PresenceService.get_instance()
pservice.connect("service-appeared", self.__service_appeared_cb)
for service in pservice.get_services():
2006-08-30 10:54:28 +02:00
self.__check_service(service)
2006-08-30 10:54:28 +02:00
def __service_appeared_cb(self, pservice, service):
self.__check_service(service)
2006-08-30 10:54:28 +02:00
def __check_service(self, service):
registry = conf.get_activity_registry()
if registry.get_activity_from_type(service.get_type()) != None:
2006-08-30 10:54:28 +02:00
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)
2006-08-29 16:17:00 +02:00
item.connect('clicked', self.__activity_clicked_cb)
2006-08-30 10:54:28 +02:00
self._icon_layout.add_icon(item)
self.add_child(item)
2006-08-30 10:54:28 +02:00
self._activities[item.get_id()] = item
2006-08-29 16:17:00 +02:00
def __activity_clicked_cb(self, item):
default_type = item.get_service().get_type()
registry = conf.get_activity_registry()
2006-09-08 01:54:52 +02:00
bundle_id = registry.get_activity_from_type(default_type).get_id()
activity_id = item.get_service().get_activity_id()
self._shell.join_activity(bundle_id, activity_id)