More work on session refactoring
This commit is contained in:
parent
be806eb191
commit
d12b780074
@ -1,3 +1,4 @@
|
|||||||
[Activity]
|
[Activity]
|
||||||
name = com.redhat.Sugar.ChatActivity
|
name = Chat
|
||||||
class = ChatActivity.ChatActivity
|
id = com.redhat.Sugar.ChatActivity
|
||||||
|
python_module = ChatActivity.ChatActivity
|
||||||
|
@ -1,4 +1,9 @@
|
|||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
|
from ConfigParser import ConfigParser
|
||||||
|
from ConfigParser import NoOptionError
|
||||||
|
|
||||||
|
from sugar import env
|
||||||
|
|
||||||
class ActivityModule:
|
class ActivityModule:
|
||||||
"""Info about an activity module. Wraps a .activity file."""
|
"""Info about an activity module. Wraps a .activity file."""
|
||||||
@ -17,9 +22,9 @@ class ActivityModule:
|
|||||||
"""Get the activity identifier"""
|
"""Get the activity identifier"""
|
||||||
return self._id
|
return self._id
|
||||||
|
|
||||||
def get_class(self):
|
def get_exec(self):
|
||||||
"""Get the activity executable"""
|
"""Get the activity executable"""
|
||||||
return self._class
|
return self._exec
|
||||||
|
|
||||||
def get_directory(self):
|
def get_directory(self):
|
||||||
"""Get the path to activity directory."""
|
"""Get the path to activity directory."""
|
||||||
@ -33,9 +38,9 @@ class ActivityRegistry:
|
|||||||
|
|
||||||
def scan_directory(self, path):
|
def scan_directory(self, path):
|
||||||
"""Scan a directory for activities and add them to the registry."""
|
"""Scan a directory for activities and add them to the registry."""
|
||||||
if os.path.isdir(base_dir):
|
if os.path.isdir(path):
|
||||||
for filename in os.listdir(base_dir):
|
for filename in os.listdir(path):
|
||||||
activity_dir = os.path.join(base_dir, filename)
|
activity_dir = os.path.join(path, filename)
|
||||||
if os.path.isdir(activity_dir):
|
if os.path.isdir(activity_dir):
|
||||||
for filename in os.listdir(activity_dir):
|
for filename in os.listdir(activity_dir):
|
||||||
if filename.endswith(".activity"):
|
if filename.endswith(".activity"):
|
||||||
@ -50,18 +55,26 @@ class ActivityRegistry:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
activity_id = cp.get('Activity', 'id')
|
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')
|
name = cp.get('Activity', 'name')
|
||||||
except NoOptionError:
|
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'):
|
if cp.has_option('Activity', 'exec'):
|
||||||
activity_exec = cp.get('Activity', 'exec')
|
activity_exec = cp.get('Activity', 'exec')
|
||||||
elif cp.has_option('Activity', 'python_module'):
|
elif cp.has_option('Activity', 'python_module'):
|
||||||
python_module = cp.get('Activity', 'python_module')
|
python_module = cp.get('Activity', 'python_module')
|
||||||
activity_exec = 'python -m sugar/activity/Activity %s %s' \
|
activity_exec = 'python -m sugar/activity/Activity %s %s' \
|
||||||
% (name, python_module)
|
% (activity_id, python_module)
|
||||||
|
env.add_to_python_path(directory)
|
||||||
else:
|
else:
|
||||||
logging.error('%s must specifiy exec or python_module' % (path))
|
logging.error('%s must specifiy exec or python_module' % (path))
|
||||||
|
return False
|
||||||
|
|
||||||
module = ActivityModule(name, activity_id, activity_exec, directory)
|
module = ActivityModule(name, activity_id, activity_exec, directory)
|
||||||
self._activities.append(module)
|
self._activities.append(module)
|
||||||
|
@ -17,17 +17,17 @@ class NewActivityButton(gtk.MenuToolButton):
|
|||||||
def __show_menu_cb(self, button):
|
def __show_menu_cb(self, button):
|
||||||
menu = gtk.Menu()
|
menu = gtk.Menu()
|
||||||
|
|
||||||
for activity_info in self._home.list_activities():
|
for module in self._home.list_activities():
|
||||||
item = gtk.MenuItem(activity_info.get_title(), False)
|
item = gtk.MenuItem(module.get_name(), False)
|
||||||
name = activity_info.get_name()
|
activity_id = module.get_id()
|
||||||
item.connect('activate', self.__menu_item_activate_cb, name)
|
item.connect('activate', self.__menu_item_activate_cb, activity_id)
|
||||||
menu.append(item)
|
menu.append(item)
|
||||||
item.show()
|
item.show()
|
||||||
|
|
||||||
self.set_menu(menu)
|
self.set_menu(menu)
|
||||||
|
|
||||||
def __menu_item_activate_cb(self, item, name):
|
def __menu_item_activate_cb(self, item, activity_id):
|
||||||
self._home.create(name)
|
self._home.create(activity_id)
|
||||||
|
|
||||||
class Toolbar(gtk.Toolbar):
|
class Toolbar(gtk.Toolbar):
|
||||||
def __init__(self, shell):
|
def __init__(self, shell):
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
|
import logging
|
||||||
|
|
||||||
import gobject
|
import gobject
|
||||||
|
|
||||||
class Process:
|
class Process:
|
||||||
|
"""Object representing one of the session processes"""
|
||||||
|
|
||||||
def __init__(self, command):
|
def __init__(self, command):
|
||||||
self._pid = None
|
self._pid = None
|
||||||
self._command = command
|
self._command = command
|
||||||
@ -9,6 +13,9 @@ class Process:
|
|||||||
return self._command
|
return self._command
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
|
print self._command
|
||||||
|
logging.debug('Start %s' % (self._command))
|
||||||
|
|
||||||
args = self._command.split()
|
args = self._command.split()
|
||||||
flags = gobject.SPAWN_SEARCH_PATH or gobject.SPAWN_STDERR_TO_DEV_NULL
|
flags = gobject.SPAWN_SEARCH_PATH or gobject.SPAWN_STDERR_TO_DEV_NULL
|
||||||
result = gobject.spawn_async(args, flags=flags, standard_output=True)
|
result = gobject.spawn_async(args, flags=flags, standard_output=True)
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
import dbus
|
import dbus
|
||||||
import gtk
|
import gtk
|
||||||
import wnck
|
import wnck
|
||||||
@ -7,6 +9,7 @@ from ConsoleLogger import ConsoleLogger
|
|||||||
from ActivityRegistry import ActivityRegistry
|
from ActivityRegistry import ActivityRegistry
|
||||||
from HomeWindow import HomeWindow
|
from HomeWindow import HomeWindow
|
||||||
from sugar import keybindings
|
from sugar import keybindings
|
||||||
|
from sugar import env
|
||||||
from sugar.activity import Activity
|
from sugar.activity import Activity
|
||||||
from PresenceWindow import PresenceWindow
|
from PresenceWindow import PresenceWindow
|
||||||
from sugar.chat.ActivityChat import ActivityChat
|
from sugar.chat.ActivityChat import ActivityChat
|
||||||
@ -50,6 +53,8 @@ class Shell:
|
|||||||
self._owner = ShellOwner()
|
self._owner = ShellOwner()
|
||||||
|
|
||||||
self._registry = ActivityRegistry()
|
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)
|
self._home_window = HomeWindow(self)
|
||||||
keybindings.setup_global_keys(self._home_window, self)
|
keybindings.setup_global_keys(self._home_window, self)
|
||||||
|
@ -92,16 +92,14 @@ def main(activity_name, activity_class):
|
|||||||
|
|
||||||
factory = ActivityFactory(activity_name, activity_class)
|
factory = ActivityFactory(activity_name, activity_class)
|
||||||
|
|
||||||
registry = _get_registry()
|
|
||||||
registry.add(activity_name, activity_name)
|
|
||||||
|
|
||||||
gtk.main()
|
gtk.main()
|
||||||
|
|
||||||
class ActivityDbusService(dbus.service.Object):
|
class ActivityDbusService(dbus.service.Object):
|
||||||
"""Base dbus service object that each Activity uses to export dbus methods.
|
"""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
|
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]
|
_ALLOWED_CALLBACKS = [ON_PUBLISH_CB]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user