From 6b09475b998cd15d0bf89831137968d48fc16f4e Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Mon, 18 Dec 2006 14:24:28 +0100 Subject: [PATCH] Add a start method to the activity. It's parallel/alternative to join. --- shell/view/Shell.py | 2 +- sugar/activity/Activity.py | 41 ++++++++++++++++++++++---------------- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/shell/view/Shell.py b/shell/view/Shell.py index 0bb59bfb..b2a1ab45 100644 --- a/shell/view/Shell.py +++ b/shell/view/Shell.py @@ -209,7 +209,7 @@ class Shell(gobject.GObject): def start_activity(self, activity_type): logging.debug('Shell.start_activity') activity = ActivityFactory.create(activity_type) - activity.execute('test', []) + activity.start() return activity def set_zoom_level(self, level): diff --git a/sugar/activity/Activity.py b/sugar/activity/Activity.py index 1c77c7b7..a9ce024d 100644 --- a/sugar/activity/Activity.py +++ b/sugar/activity/Activity.py @@ -23,7 +23,7 @@ import dbus.service import gtk import gobject -from sugar.presence.PresenceService import PresenceService +from sugar.presence import PresenceService from sugar import activity from sugar import env import sugar.util @@ -44,21 +44,31 @@ class ActivityDbusService(dbus.service.Object): The dbus service is separate from the actual Activity object so that we can tightly control what stuff passes through the dbus python bindings.""" - def start(self, pservice, activity): + def __init__(self, activity): + xid = activity.window.xid + bus = dbus.SessionBus() + bus_name = dbus.service.BusName(get_service_name(xid), bus=bus) + dbus.service.Object.__init__(self, bus_name, get_object_path(xid)) + self._activity = activity - self._pservice = pservice + self._pservice = PresenceService.get_instance() + + @dbus.service.method(ACTIVITY_INTERFACE) + def start(self): + """Start the activity.""" + self._activity.start() + + @dbus.service.method(ACTIVITY_INTERFACE) + def join(self, activity_ps_path): + """Join the activity specified by its presence service path.""" + activity_ps = self._pservice.get(activity_ps_path) + return self._activity.join(activity_ps) @dbus.service.method(ACTIVITY_INTERFACE) def share(self): """Called by the shell to request the activity to share itself on the network.""" self._activity.share() - @dbus.service.method(ACTIVITY_INTERFACE) - def join(self, activity_ps_path): - """Join the activity specified by its presence service path""" - activity_ps = self._pservice.get(activity_ps_path) - return self._activity.join(activity_ps) - @dbus.service.method(ACTIVITY_INTERFACE) def get_id(self): """Get the activity identifier""" @@ -90,7 +100,7 @@ class Activity(gtk.Window): self._shared = False self._activity_id = None self._service = None - self._pservice = PresenceService() + self._pservice = PresenceService.get_instance() self.present() @@ -98,12 +108,11 @@ class Activity(gtk.Window): group.realize() self.window.set_group(group.window) - bus = dbus.SessionBus() - xid = self.window.xid + self._bus = ActivityDbusService(self) - bus_name = dbus.service.BusName(get_service_name(xid), bus=bus) - self._bus = ActivityDbusService(bus_name, get_object_path(xid)) - self._bus.start(self._pservice, self) + def start(self): + """Start the activity.""" + self._activity_id = sugar.util.unique_id() def get_type(self): """Gets the activity type.""" @@ -119,8 +128,6 @@ class Activity(gtk.Window): def get_id(self): """Get the unique activity identifier.""" - if self._activity_id == None: - self._activity_id = sugar.util.unique_id() return self._activity_id def join(self, activity_ps):