More work on session refactoring
This commit is contained in:
@@ -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)
|
||||
|
||||
+6
-6
@@ -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):
|
||||
|
||||
@@ -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)
|
||||
|
||||
+6
-1
@@ -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,7 +53,9 @@ 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)
|
||||
self._home_window.show()
|
||||
|
||||
Reference in New Issue
Block a user