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

1
.gitignore vendored
View File

@ -42,3 +42,4 @@ depcomp
libtool libtool
ltmain.sh ltmain.sh
po/ChangeLog po/ChangeLog
m4/intltool.m4

View File

@ -47,6 +47,7 @@ sugar/activity/Makefile
sugar/canvas/Makefile sugar/canvas/Makefile
sugar/chat/Makefile sugar/chat/Makefile
sugar/chat/sketchpad/Makefile sugar/chat/sketchpad/Makefile
sugar/conf/Makefile
sugar/p2p/Makefile sugar/p2p/Makefile
sugar/p2p/model/Makefile sugar/p2p/model/Makefile
sugar/presence/Makefile sugar/presence/Makefile

View File

@ -1,6 +1,7 @@
import gtk import gtk
import dbus import dbus
from sugar import conf
from sugar.activity import Activity from sugar.activity import Activity
from PeopleWindow import PeopleWindow from PeopleWindow import PeopleWindow
@ -20,7 +21,8 @@ class ActivityHost:
self._gdk_window = gtk.gdk.window_foreign_new(self._xid) self._gdk_window = gtk.gdk.window_foreign_new(self._xid)
self._people_window = PeopleWindow(shell, self) 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() self._icon_name = info.get_icon()
def get_id(self): def get_id(self):

View File

@ -13,7 +13,6 @@ sugardir = $(pkgdatadir)/shell
sugar_PYTHON = \ sugar_PYTHON = \
__init__.py \ __init__.py \
ActivityHost.py \ ActivityHost.py \
ActivityRegistry.py \
ChatController.py \ ChatController.py \
ConsoleWindow.py \ ConsoleWindow.py \
Owner.py \ Owner.py \

View File

@ -7,7 +7,6 @@ import gtk
import gobject import gobject
import wnck import wnck
from ActivityRegistry import ActivityRegistry
from home.HomeWindow import HomeWindow from home.HomeWindow import HomeWindow
from home.HomeModel import HomeModel from home.HomeModel import HomeModel
from sugar import env from sugar import env
@ -17,6 +16,7 @@ from ActivityHost import ActivityHost
from ChatController import ChatController from ChatController import ChatController
from sugar.activity import ActivityFactory from sugar.activity import ActivityFactory
from sugar.activity import Activity from sugar.activity import Activity
from sugar import conf
import sugar.logger import sugar.logger
class ShellDbusService(dbus.service.Object): class ShellDbusService(dbus.service.Object):
@ -59,11 +59,10 @@ class Shell(gobject.GObject):
gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT])) gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT]))
} }
def __init__(self, registry): def __init__(self):
gobject.GObject.__init__(self) gobject.GObject.__init__(self)
self._screen = wnck.screen_get_default() self._screen = wnck.screen_get_default()
self._registry = registry
self._hosts = {} self._hosts = {}
self._zoom_level = Shell.ZOOM_HOME self._zoom_level = Shell.ZOOM_HOME
@ -78,7 +77,7 @@ class Shell(gobject.GObject):
self._chat_controller = ChatController(self) self._chat_controller = ChatController(self)
self._chat_controller.listen() self._chat_controller.listen()
home_model = HomeModel(self._registry) home_model = HomeModel()
self._home_window = HomeWindow(self, home_model) self._home_window = HomeWindow(self, home_model)
self._home_window.show() self._home_window.show()
@ -141,11 +140,13 @@ class Shell(gobject.GObject):
activity = self.get_current_activity() activity = self.get_current_activity()
if 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()) self._console.set_page(module.get_id())
def join_activity(self, service): 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() activity_id = service.get_activity_id()
@ -165,7 +166,8 @@ class Shell(gobject.GObject):
def start_activity(self, activity_name): def start_activity(self, activity_name):
activity = ActivityFactory.create(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: if info:
default_type = info.get_default_type() default_type = info.get_default_type()
if default_type != None: if default_type != None:
@ -176,9 +178,6 @@ class Shell(gobject.GObject):
logging.error('No such activity in the directory') logging.error('No such activity in the directory')
return None return None
def get_registry(self):
return self._registry
def get_chat_controller(self): def get_chat_controller(self):
return self._chat_controller return self._chat_controller

View File

@ -2,9 +2,9 @@ from home.FriendsModel import FriendsModel
from home.MeshModel import MeshModel from home.MeshModel import MeshModel
class HomeModel: class HomeModel:
def __init__(self, registry): def __init__(self):
self._friends = FriendsModel() self._friends = FriendsModel()
self._mesh = MeshModel(registry) self._mesh = MeshModel()
def get_friends(self): def get_friends(self):
return self._friends return self._friends

View File

@ -7,6 +7,7 @@ from sugar.canvas.IconItem import IconColor
from sugar.canvas.DonutItem import DonutItem from sugar.canvas.DonutItem import DonutItem
from sugar.canvas.DonutItem import PieceItem from sugar.canvas.DonutItem import PieceItem
from sugar.canvas.DonutItem import PieceIcon from sugar.canvas.DonutItem import PieceIcon
from sugar import conf
class TasksItem(DonutItem): class TasksItem(DonutItem):
def __init__(self, shell): def __init__(self, shell):
@ -56,7 +57,7 @@ class ActivityBar(goocanvas.Group):
self._shell = shell self._shell = shell
registry = shell.get_registry() registry = conf.get_activity_registry()
for activity in registry.list_activities(): for activity in registry.list_activities():
if activity.get_show_launcher(): if activity.get_show_launcher():
self.add_activity(activity) self.add_activity(activity)

View File

@ -1,7 +1,7 @@
import gobject import gobject
from sugar.presence.PresenceService import PresenceService from sugar.presence.PresenceService import PresenceService
from ActivityRegistry import ActivityRegistry from sugar import conf
class ActivityInfo: class ActivityInfo:
def __init__(self, service): def __init__(self, service):
@ -27,11 +27,10 @@ class MeshModel(gobject.GObject):
([gobject.TYPE_PYOBJECT])) ([gobject.TYPE_PYOBJECT]))
} }
def __init__(self, registry): def __init__(self):
gobject.GObject.__init__(self) gobject.GObject.__init__(self)
self._activities = {} self._activities = {}
self._registry = registry
self._pservice = PresenceService() self._pservice = PresenceService()
self._pservice.connect("service-appeared", self.__service_appeared_cb) self._pservice.connect("service-appeared", self.__service_appeared_cb)
@ -55,6 +54,7 @@ class MeshModel(gobject.GObject):
self.__check_service(service) self.__check_service(service)
def __check_service(self, 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()): if not self.has_activity(service.get_activity_id()):
self.add_activity(service) self.add_activity(service)

View File

@ -4,9 +4,11 @@ import goocanvas
from sugar.canvas.IconItem import IconItem from sugar.canvas.IconItem import IconItem
from sugar.canvas.IconItem import IconColor from sugar.canvas.IconItem import IconColor
from sugar import conf
class ActivityItem(IconItem): class ActivityItem(IconItem):
def __init__(self, activity, registry): def __init__(self, activity):
registry = conf.get_activity_registry()
info = registry.get_activity(activity.get_type()) info = registry.get_activity(activity.get_type())
icon_name = info.get_icon() icon_name = info.get_icon()
@ -18,9 +20,8 @@ class ActivityItem(IconItem):
return self._activity.get_service() return self._activity.get_service()
class Model(goocanvas.CanvasModelSimple): class Model(goocanvas.CanvasModelSimple):
def __init__(self, data_model, registry): def __init__(self, data_model):
goocanvas.CanvasModelSimple.__init__(self) goocanvas.CanvasModelSimple.__init__(self)
self._registry = registry
root = self.get_root_item() root = self.get_root_item()
@ -51,7 +52,7 @@ class MeshView(goocanvas.CanvasView):
self.connect("item_view_created", self.__item_view_created_cb) 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) self.set_model(canvas_model)
def __activity_button_press_cb(self, view, target, event, service): def __activity_button_press_cb(self, view, target, event, service):

View File

@ -25,11 +25,9 @@ class MatchboxProcess(Process):
class Session: class Session:
"""Takes care of running the shell and all the sugar processes""" """Takes care of running the shell and all the sugar processes"""
def __init__(self, registry):
self._registry = registry
def start(self): def start(self):
"""Start the session""" """Start the session"""
PresenceService.start() PresenceService.start()
process = MatchboxProcess() process = MatchboxProcess()
@ -38,7 +36,7 @@ class Session:
console = ConsoleWindow() console = ConsoleWindow()
sugar.logger.start('Shell', console) sugar.logger.start('Shell', console)
shell = Shell(self._registry) shell = Shell()
shell.set_console(console) shell.set_console(console)
shell.start() shell.start()

View File

@ -19,11 +19,6 @@ from sugar import env
env.setup() env.setup()
from ActivityRegistry import ActivityRegistry
registry = ActivityRegistry()
registry.scan_directory(env.get_activities_dir())
from session.Emulator import Emulator from session.Emulator import Emulator
if os.environ.has_key('SUGAR_EMULATOR') and \ 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 from session.Session import Session
session = Session(registry) session = Session()
session.start() session.start()

View File

@ -1,4 +1,4 @@
SUBDIRS = activity canvas chat p2p presence SUBDIRS = activity canvas chat conf p2p presence
sugardir = $(pythondir)/sugar sugardir = $(pythondir)/sugar
sugar_PYTHON = \ sugar_PYTHON = \

4
sugar/conf/Makefile.am Normal file
View File

@ -0,0 +1,4 @@
sugardir = $(pythondir)/sugar/conf
sugar_PYTHON = \
__init__.py \
ActivityRegistry.py

6
sugar/conf/__init__.py Normal file
View File

@ -0,0 +1,6 @@
from sugar.conf.ActivityRegistry import ActivityRegistry
__registry = ActivityRegistry()
def get_activity_registry():
return __registry

View File

@ -8,6 +8,7 @@ except ImportError:
from sugar.__installed__ import * from sugar.__installed__ import *
import sugar.setup import sugar.setup
import sugar.conf
def add_to_python_path(path): def add_to_python_path(path):
sys.path.insert(0, path) sys.path.insert(0, path)
@ -40,6 +41,9 @@ def setup():
sugar.setup.write_service('org.laptop.Presence', bin, sugar.setup.write_service('org.laptop.Presence', bin,
get_services_dir()) get_services_dir())
registry = sugar.conf.get_activity_registry()
registry.scan_directory(get_activities_dir())
def get_user_dir(): def get_user_dir():
if os.environ.has_key('SUGAR_NICK_NAME'): if os.environ.has_key('SUGAR_NICK_NAME'):
nick = get_nick_name() nick = get_nick_name()