From fb716ae0466547ea4e6c580b9d55fe015139201f Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Sun, 07 Jan 2007 05:04:30 +0000 Subject: Make activity launching asynchronous The ActivityFactory create() method now returns a handler GObject, which callers may attach signals to to receive success and error signals from the result of the activity launch request. --- (limited to 'sugar/activity') diff --git a/sugar/activity/ActivityFactory.py b/sugar/activity/ActivityFactory.py index 481c5b9..94e765e 100644 --- a/sugar/activity/ActivityFactory.py +++ b/sugar/activity/ActivityFactory.py @@ -76,24 +76,43 @@ class ActivityFactory(dbus.service.Object): if len(self._activities) == 0: gtk.main_quit() -def create(activity_name): - """Create a new activity from his name.""" - bus = dbus.SessionBus() +class ActivityCreationHandler(gobject.GObject): + + __gsignals__ = { + 'error': (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, + ([gobject.TYPE_PYOBJECT])), + 'success': (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, + ([gobject.TYPE_PYOBJECT])) + } - factory_name = activity_name - factory_path = get_path(factory_name) + def __init__(self, activity_name): + gobject.GObject.__init__(self) - proxy_obj = bus.get_object(factory_name, factory_path) - factory = dbus.Interface(proxy_obj, "com.redhat.Sugar.ActivityFactory") + bus = dbus.SessionBus() + factory_name = activity_name + factory_path = get_path(factory_name) - xid = factory.create() + proxy_obj = bus.get_object(factory_name, factory_path) + factory = dbus.Interface(proxy_obj, "com.redhat.Sugar.ActivityFactory") - bus = dbus.SessionBus() - proxy_obj = bus.get_object(Activity.get_service_name(xid), - Activity.get_object_path(xid)) - activity = dbus.Interface(proxy_obj, Activity.ACTIVITY_INTERFACE) + factory.create(reply_handler=self._reply_handler, error_handler=self._error_handler) - return activity + def _reply_handler(self, xid): + bus = dbus.SessionBus() + proxy_obj = bus.get_object(Activity.get_service_name(xid), + Activity.get_object_path(xid)) + activity = dbus.Interface(proxy_obj, Activity.ACTIVITY_INTERFACE) + self.emit('success', activity) + + def _error_handler(self, err): + logging.debug("Couldn't create activity: %s" % err) + self.emit('error', err) + +def create(activity_name): + """Create a new activity from its name.""" + return ActivityCreationHandler(activity_name) def start_factory(activity_class, bundle_path): """Start the activity factory.""" -- cgit v0.9.1