Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/shell
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@localhost.localdomain>2006-08-22 12:01:53 (GMT)
committer Marco Pesenti Gritti <marco@localhost.localdomain>2006-08-22 12:01:53 (GMT)
commit3e51b086df1221a469bc98842fe779c47f4f2514 (patch)
treeb237039d9682bf7d6387c84c5ccc1f4a354089e1 /shell
parent49073039e94685f697389712dbed35f5d39e4270 (diff)
Create a conf module. Move activity registry out of the shell
(should only be graphical) into it.
Diffstat (limited to 'shell')
-rw-r--r--shell/ActivityHost.py4
-rw-r--r--shell/ActivityRegistry.py118
-rw-r--r--shell/Makefile.am1
-rwxr-xr-xshell/Shell.py19
-rw-r--r--shell/home/HomeModel.py4
-rw-r--r--shell/home/HomeView.py3
-rw-r--r--shell/home/MeshModel.py8
-rw-r--r--shell/home/MeshView.py9
-rw-r--r--shell/session/Session.py6
-rwxr-xr-xshell/sugar7
10 files changed, 28 insertions, 151 deletions
diff --git a/shell/ActivityHost.py b/shell/ActivityHost.py
index 84577c1..d8b6569 100644
--- a/shell/ActivityHost.py
+++ b/shell/ActivityHost.py
@@ -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):
diff --git a/shell/ActivityRegistry.py b/shell/ActivityRegistry.py
deleted file mode 100644
index 5ff0059..0000000
--- a/shell/ActivityRegistry.py
+++ /dev/null
@@ -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
diff --git a/shell/Makefile.am b/shell/Makefile.am
index dbaefdd..7c788b9 100644
--- a/shell/Makefile.am
+++ b/shell/Makefile.am
@@ -13,7 +13,6 @@ sugardir = $(pkgdatadir)/shell
sugar_PYTHON = \
__init__.py \
ActivityHost.py \
- ActivityRegistry.py \
ChatController.py \
ConsoleWindow.py \
Owner.py \
diff --git a/shell/Shell.py b/shell/Shell.py
index 2f47c22..171ae13 100755
--- a/shell/Shell.py
+++ b/shell/Shell.py
@@ -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
diff --git a/shell/home/HomeModel.py b/shell/home/HomeModel.py
index 5f4965d..1e1e316 100644
--- a/shell/home/HomeModel.py
+++ b/shell/home/HomeModel.py
@@ -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
diff --git a/shell/home/HomeView.py b/shell/home/HomeView.py
index acc451c..48a3044 100644
--- a/shell/home/HomeView.py
+++ b/shell/home/HomeView.py
@@ -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)
diff --git a/shell/home/MeshModel.py b/shell/home/MeshModel.py
index b2163ac..2225cc6 100644
--- a/shell/home/MeshModel.py
+++ b/shell/home/MeshModel.py
@@ -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)
diff --git a/shell/home/MeshView.py b/shell/home/MeshView.py
index 8bbea05..a2694be 100644
--- a/shell/home/MeshView.py
+++ b/shell/home/MeshView.py
@@ -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):
diff --git a/shell/session/Session.py b/shell/session/Session.py
index 8af2c65..28da29a 100644
--- a/shell/session/Session.py
+++ b/shell/session/Session.py
@@ -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()
diff --git a/shell/sugar b/shell/sugar
index 8108b26..da0b7b3 100755
--- a/shell/sugar
+++ b/shell/sugar
@@ -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()