Create a conf module. Move activity registry out of the shell
(should only be graphical) into it.
This commit is contained in:
parent
49073039e9
commit
3e51b086df
1
.gitignore
vendored
1
.gitignore
vendored
@ -42,3 +42,4 @@ depcomp
|
||||
libtool
|
||||
ltmain.sh
|
||||
po/ChangeLog
|
||||
m4/intltool.m4
|
||||
|
@ -47,6 +47,7 @@ sugar/activity/Makefile
|
||||
sugar/canvas/Makefile
|
||||
sugar/chat/Makefile
|
||||
sugar/chat/sketchpad/Makefile
|
||||
sugar/conf/Makefile
|
||||
sugar/p2p/Makefile
|
||||
sugar/p2p/model/Makefile
|
||||
sugar/presence/Makefile
|
||||
|
@ -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):
|
||||
|
@ -13,7 +13,6 @@ sugardir = $(pkgdatadir)/shell
|
||||
sugar_PYTHON = \
|
||||
__init__.py \
|
||||
ActivityHost.py \
|
||||
ActivityRegistry.py \
|
||||
ChatController.py \
|
||||
ConsoleWindow.py \
|
||||
Owner.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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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):
|
||||
|
@ -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()
|
||||
|
||||
|
@ -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()
|
||||
|
@ -1,4 +1,4 @@
|
||||
SUBDIRS = activity canvas chat p2p presence
|
||||
SUBDIRS = activity canvas chat conf p2p presence
|
||||
|
||||
sugardir = $(pythondir)/sugar
|
||||
sugar_PYTHON = \
|
||||
|
4
sugar/conf/Makefile.am
Normal file
4
sugar/conf/Makefile.am
Normal file
@ -0,0 +1,4 @@
|
||||
sugardir = $(pythondir)/sugar/conf
|
||||
sugar_PYTHON = \
|
||||
__init__.py \
|
||||
ActivityRegistry.py
|
6
sugar/conf/__init__.py
Normal file
6
sugar/conf/__init__.py
Normal file
@ -0,0 +1,6 @@
|
||||
from sugar.conf.ActivityRegistry import ActivityRegistry
|
||||
|
||||
__registry = ActivityRegistry()
|
||||
|
||||
def get_activity_registry():
|
||||
return __registry
|
@ -8,6 +8,7 @@ except ImportError:
|
||||
from sugar.__installed__ import *
|
||||
|
||||
import sugar.setup
|
||||
import sugar.conf
|
||||
|
||||
def add_to_python_path(path):
|
||||
sys.path.insert(0, path)
|
||||
@ -40,6 +41,9 @@ def setup():
|
||||
sugar.setup.write_service('org.laptop.Presence', bin,
|
||||
get_services_dir())
|
||||
|
||||
registry = sugar.conf.get_activity_registry()
|
||||
registry.scan_directory(get_activities_dir())
|
||||
|
||||
def get_user_dir():
|
||||
if os.environ.has_key('SUGAR_NICK_NAME'):
|
||||
nick = get_nick_name()
|
||||
|
Loading…
Reference in New Issue
Block a user