Create a conf module. Move activity registry out of the shell

(should only be graphical) into it.
This commit is contained in:
Marco Pesenti Gritti
2006-08-22 14:01:53 +02:00
parent 49073039e9
commit 3e51b086df
16 changed files with 45 additions and 34 deletions
+3 -1
View File
@@ -1,6 +1,7 @@
import gtk
import dbus
from sugar import conf
from sugar.activity import Activity
from PeopleWindow import PeopleWindow
@@ -20,7 +21,8 @@ class ActivityHost:
self._gdk_window = gtk.gdk.window_foreign_new(self._xid)
self._people_window = PeopleWindow(shell, self)
info = self._shell.get_registry().get_activity(self._default_type)
registry = conf.get_activity_registry()
info = registry.get_activity(self._default_type)
self._icon_name = info.get_icon()
def get_id(self):
-118
View File
@@ -1,118 +0,0 @@
import logging
import os
from ConfigParser import ConfigParser
from ConfigParser import NoOptionError
class ActivityModule:
"""Info about an activity module. Wraps a .activity file."""
def __init__(self, name, activity_id, directory):
self._name = name
self._icon = None
self._id = activity_id
self._directory = directory
self._show_launcher = False
def get_name(self):
"""Get the activity user visible name."""
return self._name
def get_id(self):
"""Get the activity identifier"""
return self._id
def get_icon(self):
"""Get the activity icon name"""
return self._icon
def set_icon(self, icon):
"""Set the activity icon name"""
self._icon = icon
def get_directory(self):
"""Get the path to activity directory."""
return self._directory
def get_default_type(self):
"""Get the the type of the default activity service."""
return self._default_type
def set_default_type(self, default_type):
"""Set the the type of the default activity service."""
self._default_type = default_type
def get_show_launcher(self):
"""Get whether there should be a visible launcher for the activity"""
return self._show_launcher
def set_show_launcher(self, show_launcher):
"""Set whether there should be a visible launcher for the activity"""
self._show_launcher = show_launcher
class ActivityRegistry:
"""Service that tracks the available activities"""
def __init__(self):
self._activities = []
def get_activity_from_id(self, activity_id):
"""Returns an activity given his identifier"""
for activity in self._activities:
if activity.get_id() == activity_id:
return activity
return None
def get_activity(self, default_type):
"""Returns an activity given his default type"""
for activity in self._activities:
if activity.get_default_type() == default_type:
return activity
return None
def scan_directory(self, path):
"""Scan a directory for activities and add them to the registry."""
if os.path.isdir(path):
for f in os.listdir(path):
if f.endswith(".activity"):
self.add(os.path.join(path, f))
def add(self, path):
"""Add an activity to the registry. The path points to a .activity file."""
cp = ConfigParser()
cp.read([path])
directory = os.path.dirname(path)
try:
activity_id = cp.get('Activity', 'id')
except NoOptionError:
logging.error('%s miss the required id option' % (path))
return False
try:
name = cp.get('Activity', 'name')
except NoOptionError:
logging.error('%s miss the required name option' % (path))
return False
if cp.has_option('Activity', 'default_type'):
default_type = cp.get('Activity', 'default_type')
else:
default_type = None
module = ActivityModule(name, activity_id, directory)
self._activities.append(module)
if cp.has_option('Activity', 'show_launcher'):
module.set_show_launcher(True)
if cp.has_option('Activity', 'icon'):
module.set_icon(cp.get('Activity', 'icon'))
module.set_default_type(default_type)
return True
def list_activities(self):
"""Enumerate the registered activities as an ActivityModule list."""
return self._activities
-1
View File
@@ -13,7 +13,6 @@ sugardir = $(pkgdatadir)/shell
sugar_PYTHON = \
__init__.py \
ActivityHost.py \
ActivityRegistry.py \
ChatController.py \
ConsoleWindow.py \
Owner.py \
+9 -10
View File
@@ -7,7 +7,6 @@ import gtk
import gobject
import wnck
from ActivityRegistry import ActivityRegistry
from home.HomeWindow import HomeWindow
from home.HomeModel import HomeModel
from sugar import env
@@ -17,6 +16,7 @@ from ActivityHost import ActivityHost
from ChatController import ChatController
from sugar.activity import ActivityFactory
from sugar.activity import Activity
from sugar import conf
import sugar.logger
class ShellDbusService(dbus.service.Object):
@@ -59,11 +59,10 @@ class Shell(gobject.GObject):
gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT]))
}
def __init__(self, registry):
def __init__(self):
gobject.GObject.__init__(self)
self._screen = wnck.screen_get_default()
self._registry = registry
self._hosts = {}
self._zoom_level = Shell.ZOOM_HOME
@@ -78,7 +77,7 @@ class Shell(gobject.GObject):
self._chat_controller = ChatController(self)
self._chat_controller.listen()
home_model = HomeModel(self._registry)
home_model = HomeModel()
self._home_window = HomeWindow(self, home_model)
self._home_window.show()
@@ -141,11 +140,13 @@ class Shell(gobject.GObject):
activity = self.get_current_activity()
if activity:
module = self._registry.get_activity(activity.get_default_type())
registry = conf.get_activity_registry()
module = registry.get_activity(activity.get_default_type())
self._console.set_page(module.get_id())
def join_activity(self, service):
info = self._registry.get_activity(service.get_type())
registry = conf.get_activity_registry()
info = registry.get_activity(service.get_type())
activity_id = service.get_activity_id()
@@ -165,7 +166,8 @@ class Shell(gobject.GObject):
def start_activity(self, activity_name):
activity = ActivityFactory.create(activity_name)
info = self._registry.get_activity_from_id(activity_name)
registry = conf.get_activity_registry()
info = registry.get_activity_from_id(activity_name)
if info:
default_type = info.get_default_type()
if default_type != None:
@@ -176,9 +178,6 @@ class Shell(gobject.GObject):
logging.error('No such activity in the directory')
return None
def get_registry(self):
return self._registry
def get_chat_controller(self):
return self._chat_controller
+2 -2
View File
@@ -2,9 +2,9 @@ from home.FriendsModel import FriendsModel
from home.MeshModel import MeshModel
class HomeModel:
def __init__(self, registry):
def __init__(self):
self._friends = FriendsModel()
self._mesh = MeshModel(registry)
self._mesh = MeshModel()
def get_friends(self):
return self._friends
+2 -1
View File
@@ -7,6 +7,7 @@ from sugar.canvas.IconItem import IconColor
from sugar.canvas.DonutItem import DonutItem
from sugar.canvas.DonutItem import PieceItem
from sugar.canvas.DonutItem import PieceIcon
from sugar import conf
class TasksItem(DonutItem):
def __init__(self, shell):
@@ -56,7 +57,7 @@ class ActivityBar(goocanvas.Group):
self._shell = shell
registry = shell.get_registry()
registry = conf.get_activity_registry()
for activity in registry.list_activities():
if activity.get_show_launcher():
self.add_activity(activity)
+4 -4
View File
@@ -1,7 +1,7 @@
import gobject
from sugar.presence.PresenceService import PresenceService
from ActivityRegistry import ActivityRegistry
from sugar import conf
class ActivityInfo:
def __init__(self, service):
@@ -27,11 +27,10 @@ class MeshModel(gobject.GObject):
([gobject.TYPE_PYOBJECT]))
}
def __init__(self, registry):
def __init__(self):
gobject.GObject.__init__(self)
self._activities = {}
self._registry = registry
self._pservice = PresenceService()
self._pservice.connect("service-appeared", self.__service_appeared_cb)
@@ -55,6 +54,7 @@ class MeshModel(gobject.GObject):
self.__check_service(service)
def __check_service(self, service):
if self._registry.get_activity(service.get_type()) != None:
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)
+5 -4
View File
@@ -4,9 +4,11 @@ import goocanvas
from sugar.canvas.IconItem import IconItem
from sugar.canvas.IconItem import IconColor
from sugar import conf
class ActivityItem(IconItem):
def __init__(self, activity, registry):
def __init__(self, activity):
registry = conf.get_activity_registry()
info = registry.get_activity(activity.get_type())
icon_name = info.get_icon()
@@ -18,9 +20,8 @@ class ActivityItem(IconItem):
return self._activity.get_service()
class Model(goocanvas.CanvasModelSimple):
def __init__(self, data_model, registry):
def __init__(self, data_model):
goocanvas.CanvasModelSimple.__init__(self)
self._registry = registry
root = self.get_root_item()
@@ -51,7 +52,7 @@ class MeshView(goocanvas.CanvasView):
self.connect("item_view_created", self.__item_view_created_cb)
canvas_model = Model(data_model, shell.get_registry())
canvas_model = Model(data_model)
self.set_model(canvas_model)
def __activity_button_press_cb(self, view, target, event, service):
+2 -4
View File
@@ -25,11 +25,9 @@ class MatchboxProcess(Process):
class Session:
"""Takes care of running the shell and all the sugar processes"""
def __init__(self, registry):
self._registry = registry
def start(self):
"""Start the session"""
PresenceService.start()
process = MatchboxProcess()
@@ -38,7 +36,7 @@ class Session:
console = ConsoleWindow()
sugar.logger.start('Shell', console)
shell = Shell(self._registry)
shell = Shell()
shell.set_console(console)
shell.start()
+1 -6
View File
@@ -19,11 +19,6 @@ from sugar import env
env.setup()
from ActivityRegistry import ActivityRegistry
registry = ActivityRegistry()
registry.scan_directory(env.get_activities_dir())
from session.Emulator import Emulator
if os.environ.has_key('SUGAR_EMULATOR') and \
@@ -33,5 +28,5 @@ if os.environ.has_key('SUGAR_EMULATOR') and \
from session.Session import Session
session = Session(registry)
session = Session()
session.start()