Setup the activity from the shell process, through dbus,
this simplifies things a lot...
This commit is contained in:
@@ -10,11 +10,10 @@ class ActivityHost:
|
||||
self._xid = xid
|
||||
|
||||
bus = dbus.SessionBus()
|
||||
service = Activity.ACTIVITY_SERVICE_NAME + "%s" % xid
|
||||
path = Activity.ACTIVITY_SERVICE_PATH + "/%s" % xid
|
||||
proxy_obj = bus.get_object(service, path)
|
||||
proxy_obj = bus.get_object(Activity.ACTIVITY_SERVICE_NAME, path)
|
||||
|
||||
self._activity = dbus.Interface(proxy_obj, 'com.redhat.Sugar.Activity')
|
||||
self._activity = dbus.Interface(proxy_obj, Activity.ACTIVITY_INTERFACE)
|
||||
self._id = self._activity.get_id()
|
||||
self._default_type = self._activity.get_default_type()
|
||||
self._window = gtk.gdk.window_foreign_new(xid)
|
||||
|
||||
@@ -45,6 +45,13 @@ class ActivityRegistry:
|
||||
|
||||
def __init__(self):
|
||||
self._activities = []
|
||||
|
||||
def get_activity_from_id(self, activity_id):
|
||||
"""Returns an activity given his identifier"""
|
||||
for activity in self._activities:
|
||||
if activity.get_id() == activity_id:
|
||||
return activity
|
||||
return None
|
||||
|
||||
def get_activity(self, default_type):
|
||||
"""Returns an activity given his default type"""
|
||||
|
||||
+2
-11
@@ -72,16 +72,7 @@ class ActivitiesGrid(gtk.VBox):
|
||||
self._buttons[activity.get_id()] = button
|
||||
|
||||
def __button_clicked_cb(self, button, info):
|
||||
activity = self._shell.get_registry().get_activity(info.get_type())
|
||||
|
||||
activity_id = info.get_service().get_activity_id()
|
||||
pservice = PresenceService()
|
||||
activity_ps = pservice.get_activity(activity_id)
|
||||
|
||||
if activity_ps:
|
||||
ActivityFactory.create(activity.get_id(), activity_ps)
|
||||
else:
|
||||
print 'Cannot start activity.'
|
||||
self._shell.join_activity(info.get_service())
|
||||
|
||||
class TasksGrid(gtk.VBox):
|
||||
def __init__(self, home):
|
||||
@@ -168,7 +159,7 @@ class HomeWindow(gtk.Window):
|
||||
return self._shell.get_registry().list_activities()
|
||||
|
||||
def create(self, activity_name):
|
||||
ActivityFactory.create(activity_name)
|
||||
self._shell.start_activity(activity_name)
|
||||
|
||||
def activate(self, activity_window):
|
||||
activity_window.activate(gtk.get_current_event_time())
|
||||
|
||||
+27
-1
@@ -1,4 +1,5 @@
|
||||
import os
|
||||
import logging
|
||||
|
||||
import dbus
|
||||
import dbus.glib
|
||||
@@ -12,9 +13,10 @@ from HomeWindow import HomeWindow
|
||||
from sugar import env
|
||||
from ConsoleWindow import ConsoleWindow
|
||||
from Owner import ShellOwner
|
||||
from PresenceService import PresenceService
|
||||
from sugar.presence.PresenceService import PresenceService
|
||||
from ActivityHost import ActivityHost
|
||||
from ChatListener import ChatListener
|
||||
from sugar.activity import ActivityFactory
|
||||
|
||||
class ShellDbusService(dbus.service.Object):
|
||||
def __init__(self, shell, bus_name):
|
||||
@@ -106,6 +108,30 @@ class Shell:
|
||||
module = self._registry.get_activity(activity.get_default_type())
|
||||
console = self.get_console(module.get_id())
|
||||
activity.show_dialog(console)
|
||||
|
||||
def join_activity(self, service):
|
||||
info = self._registry.get_activity(service.get_type())
|
||||
|
||||
activity_id = service.get_activity_id()
|
||||
pservice = PresenceService()
|
||||
activity_ps = pservice.get_activity(activity_id)
|
||||
|
||||
if activity_ps:
|
||||
activity = ActivityFactory.create(info.get_id())
|
||||
activity.set_default_type(service.get_type())
|
||||
activity.join(activity_ps.object_path())
|
||||
else:
|
||||
logging.error('Cannot start activity.')
|
||||
|
||||
def start_activity(self, activity_name):
|
||||
activity = ActivityFactory.create(activity_name)
|
||||
info = self._registry.get_activity_from_id(activity_name)
|
||||
if info:
|
||||
activity.set_default_type(info.get_default_type())
|
||||
return activity
|
||||
else:
|
||||
logging.error('No such activity in the directory')
|
||||
return None
|
||||
|
||||
def log(self, module_id, message):
|
||||
console = self.get_console(module_id)
|
||||
|
||||
Reference in New Issue
Block a user