More work on session refactoring

This commit is contained in:
Marco Pesenti Gritti 2006-07-12 17:21:22 +02:00
parent be806eb191
commit d12b780074
6 changed files with 46 additions and 22 deletions

View File

@ -1,3 +1,4 @@
[Activity]
name = com.redhat.Sugar.ChatActivity
class = ChatActivity.ChatActivity
name = Chat
id = com.redhat.Sugar.ChatActivity
python_module = ChatActivity.ChatActivity

View File

@ -1,4 +1,9 @@
import logging
import os
from ConfigParser import ConfigParser
from ConfigParser import NoOptionError
from sugar import env
class ActivityModule:
"""Info about an activity module. Wraps a .activity file."""
@ -17,9 +22,9 @@ class ActivityModule:
"""Get the activity identifier"""
return self._id
def get_class(self):
def get_exec(self):
"""Get the activity executable"""
return self._class
return self._exec
def get_directory(self):
"""Get the path to activity directory."""
@ -33,9 +38,9 @@ class ActivityRegistry:
def scan_directory(self, path):
"""Scan a directory for activities and add them to the registry."""
if os.path.isdir(base_dir):
for filename in os.listdir(base_dir):
activity_dir = os.path.join(base_dir, filename)
if os.path.isdir(path):
for filename in os.listdir(path):
activity_dir = os.path.join(path, filename)
if os.path.isdir(activity_dir):
for filename in os.listdir(activity_dir):
if filename.endswith(".activity"):
@ -50,18 +55,26 @@ class ActivityRegistry:
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 a required option' % (path))
logging.error('%s miss the required name option' % (path))
return False
if cp.has_option('Activity', 'exec'):
activity_exec = cp.get('Activity', 'exec')
elif cp.has_option('Activity', 'python_module'):
python_module = cp.get('Activity', 'python_module')
activity_exec = 'python -m sugar/activity/Activity %s %s' \
% (name, python_module)
% (activity_id, python_module)
env.add_to_python_path(directory)
else:
logging.error('%s must specifiy exec or python_module' % (path))
return False
module = ActivityModule(name, activity_id, activity_exec, directory)
self._activities.append(module)

View File

@ -17,17 +17,17 @@ class NewActivityButton(gtk.MenuToolButton):
def __show_menu_cb(self, button):
menu = gtk.Menu()
for activity_info in self._home.list_activities():
item = gtk.MenuItem(activity_info.get_title(), False)
name = activity_info.get_name()
item.connect('activate', self.__menu_item_activate_cb, name)
for module in self._home.list_activities():
item = gtk.MenuItem(module.get_name(), False)
activity_id = module.get_id()
item.connect('activate', self.__menu_item_activate_cb, activity_id)
menu.append(item)
item.show()
self.set_menu(menu)
def __menu_item_activate_cb(self, item, name):
self._home.create(name)
def __menu_item_activate_cb(self, item, activity_id):
self._home.create(activity_id)
class Toolbar(gtk.Toolbar):
def __init__(self, shell):

View File

@ -1,6 +1,10 @@
import logging
import gobject
class Process:
"""Object representing one of the session processes"""
def __init__(self, command):
self._pid = None
self._command = command
@ -9,6 +13,9 @@ class Process:
return self._command
def start(self):
print self._command
logging.debug('Start %s' % (self._command))
args = self._command.split()
flags = gobject.SPAWN_SEARCH_PATH or gobject.SPAWN_STDERR_TO_DEV_NULL
result = gobject.spawn_async(args, flags=flags, standard_output=True)

View File

@ -1,3 +1,5 @@
import os
import dbus
import gtk
import wnck
@ -7,6 +9,7 @@ from ConsoleLogger import ConsoleLogger
from ActivityRegistry import ActivityRegistry
from HomeWindow import HomeWindow
from sugar import keybindings
from sugar import env
from sugar.activity import Activity
from PresenceWindow import PresenceWindow
from sugar.chat.ActivityChat import ActivityChat
@ -50,6 +53,8 @@ class Shell:
self._owner = ShellOwner()
self._registry = ActivityRegistry()
self._registry.scan_directory(env.get_activities_dir())
self._registry.scan_directory(os.path.join(env.get_user_dir(), 'activities'))
self._home_window = HomeWindow(self)
keybindings.setup_global_keys(self._home_window, self)

View File

@ -92,16 +92,14 @@ def main(activity_name, activity_class):
factory = ActivityFactory(activity_name, activity_class)
registry = _get_registry()
registry.add(activity_name, activity_name)
gtk.main()
class ActivityDbusService(dbus.service.Object):
"""Base dbus service object that each Activity uses to export dbus methods.
The dbus service is separate from the actual Activity object so that we can
tightly control what stuff passes through the dbus python bindings."""
tightly control what stuff passes through print aaaa
the dbus python bindings."""
_ALLOWED_CALLBACKS = [ON_PUBLISH_CB]