Read service type from the .activity file

This commit is contained in:
Marco Pesenti Gritti
2006-07-14 16:40:45 +02:00
parent 5ff09a10f7
commit db08c3795f
7 changed files with 59 additions and 32 deletions
+6 -2
View File
@@ -1,5 +1,7 @@
import gobject
from sugar.presence.PresenceService import PresenceService
class ActivityInfo:
def __init__(self, service):
self._service = service
@@ -15,10 +17,12 @@ class ActivitiesModel(gobject.GObject):
__gsignals__ = {
'activity-added': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT])),
'activity-removed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT]))
}
def __init__(self):
gobject.GObject(self)
gobject.GObject.__init__(self)
self._activities = []
@@ -33,7 +37,7 @@ class ActivitiesModel(gobject.GObject):
self.emit('activity-added', activity_info)
def __iter__(self):
return activities.__iter__()
return self._activities.__iter__()
def _on_new_service_adv_cb(self, pservice, activity_id, short_stype):
if activity_id:
+18
View File
@@ -29,6 +29,14 @@ class ActivityModule:
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
class ActivityRegistry:
"""Service that tracks the available activities"""
@@ -65,12 +73,20 @@ class ActivityRegistry:
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
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')
python_module = cp.get('Activity', 'python_module')
activity_exec = '%s %s %s' % (env.get_activity_runner(),
activity_id, python_module)
if default_type:
activity_exec += ' ' + default_type
env.add_to_python_path(directory)
else:
logging.error('%s must specifiy exec or python_module' % (path))
@@ -79,6 +95,8 @@ class ActivityRegistry:
module = ActivityModule(name, activity_id, activity_exec, directory)
self._activities.append(module)
module.set_default_type(default_type)
return True
def list_activities(self):
+4 -3
View File
@@ -4,6 +4,7 @@ import gtk
import wnck
from sugar.activity import Activity
from ActivitiesModel import ActivitiesModel
class NewActivityButton(gtk.MenuToolButton):
def __init__(self, home):
@@ -45,13 +46,13 @@ class ActivitiesGrid(gtk.VBox):
for activity in model:
self._add(activity)
screen.connect('activity-added', self.__activity_added_cb)
screen.connect('activity-removed', self.__activity_removed_cb)
model.connect('activity-added', self.__activity_added_cb)
model.connect('activity-removed', self.__activity_removed_cb)
def __activity_added_cb(self, model, activity):
self._add(activity)
def __activity_closed_cb(self, model, activity):
def __activity_removed_cb(self, model, activity):
self._remove(window)
def _remove(self, activity):
+4 -1
View File
@@ -13,4 +13,7 @@ theme.setup()
lw = LogWriter(sys.argv[1])
lw.start()
Activity.register_factory(sys.argv[1], sys.argv[2])
if len(sys.argv) == 4:
Activity.register_factory(sys.argv[1], sys.argv[2], sys.argv[3])
else:
Activity.register_factory(sys.argv[1], sys.argv[2])