Several fixes and cleanups
This commit is contained in:
parent
95d9b7fe8e
commit
0dcaf314f7
@ -5,18 +5,19 @@ from sugar.activity import Activity
|
|||||||
from PeopleWindow import PeopleWindow
|
from PeopleWindow import PeopleWindow
|
||||||
|
|
||||||
class ActivityHost:
|
class ActivityHost:
|
||||||
def __init__(self, shell, xid):
|
def __init__(self, shell, window):
|
||||||
self._shell = shell
|
self._shell = shell
|
||||||
self._xid = xid
|
|
||||||
|
xid = window.get_xid()
|
||||||
|
|
||||||
bus = dbus.SessionBus()
|
bus = dbus.SessionBus()
|
||||||
path = Activity.ACTIVITY_SERVICE_PATH + "/%s" % xid
|
proxy_obj = bus.get_object(Activity.get_service_name(xid),
|
||||||
proxy_obj = bus.get_object(Activity.ACTIVITY_SERVICE_NAME, path)
|
Activity.get_object_path(xid))
|
||||||
|
|
||||||
self._activity = dbus.Interface(proxy_obj, Activity.ACTIVITY_INTERFACE)
|
self._activity = dbus.Interface(proxy_obj, Activity.ACTIVITY_INTERFACE)
|
||||||
self._id = self._activity.get_id()
|
self._id = self._activity.get_id()
|
||||||
self._default_type = self._activity.get_default_type()
|
self._default_type = self._activity.get_default_type()
|
||||||
self._window = gtk.gdk.window_foreign_new(xid)
|
self._window = gtk.gdk.window_foreign_new(window.get_xid())
|
||||||
self._people_window = PeopleWindow(shell, self)
|
self._people_window = PeopleWindow(shell, self)
|
||||||
|
|
||||||
def get_id(self):
|
def get_id(self):
|
||||||
|
@ -111,7 +111,7 @@ class PresenceView(gtk.VBox):
|
|||||||
if buddy:
|
if buddy:
|
||||||
chat_service = buddy.get_service_of_type(BuddyChat.SERVICE_TYPE)
|
chat_service = buddy.get_service_of_type(BuddyChat.SERVICE_TYPE)
|
||||||
activity = self._shell.start_activity('com.redhat.Sugar.ChatActivity')
|
activity = self._shell.start_activity('com.redhat.Sugar.ChatActivity')
|
||||||
#activity.execute('start', [chat_service.object_path()])
|
activity.execute('start', [chat_service.object_path()])
|
||||||
|
|
||||||
def __buddy_icon_changed_cb(self, buddy):
|
def __buddy_icon_changed_cb(self, buddy):
|
||||||
it = self._get_iter_for_buddy(buddy)
|
it = self._get_iter_for_buddy(buddy)
|
||||||
|
@ -17,6 +17,7 @@ from sugar.presence.PresenceService import PresenceService
|
|||||||
from ActivityHost import ActivityHost
|
from ActivityHost import ActivityHost
|
||||||
from ChatController import ChatController
|
from ChatController import ChatController
|
||||||
from sugar.activity import ActivityFactory
|
from sugar.activity import ActivityFactory
|
||||||
|
from sugar.activity import Activity
|
||||||
|
|
||||||
class ShellDbusService(dbus.service.Object):
|
class ShellDbusService(dbus.service.Object):
|
||||||
def __init__(self, shell, bus_name):
|
def __init__(self, shell, bus_name):
|
||||||
@ -73,8 +74,7 @@ class Shell:
|
|||||||
|
|
||||||
def __window_opened_cb(self, screen, window):
|
def __window_opened_cb(self, screen, window):
|
||||||
if window.get_window_type() == wnck.WINDOW_NORMAL:
|
if window.get_window_type() == wnck.WINDOW_NORMAL:
|
||||||
xid = window.get_xid()
|
self._hosts[window.get_xid()] = ActivityHost(self, window)
|
||||||
self._hosts[xid] = ActivityHost(self, xid)
|
|
||||||
|
|
||||||
def __window_closed_cb(self, screen, window):
|
def __window_closed_cb(self, screen, window):
|
||||||
if window.get_window_type() == wnck.WINDOW_NORMAL:
|
if window.get_window_type() == wnck.WINDOW_NORMAL:
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
import dbus
|
import dbus
|
||||||
import dbus.service
|
import dbus.service
|
||||||
import gtk
|
import gtk
|
||||||
@ -10,25 +12,23 @@ ACTIVITY_SERVICE_NAME = "org.laptop.Activity"
|
|||||||
ACTIVITY_SERVICE_PATH = "/org/laptop/Activity"
|
ACTIVITY_SERVICE_PATH = "/org/laptop/Activity"
|
||||||
ACTIVITY_INTERFACE = "org.laptop.Activity"
|
ACTIVITY_INTERFACE = "org.laptop.Activity"
|
||||||
|
|
||||||
|
def get_service_name(xid):
|
||||||
|
return ACTIVITY_SERVICE_NAME + '%d' % xid
|
||||||
|
|
||||||
|
def get_object_path(xid):
|
||||||
|
return ACTIVITY_SERVICE_PATH + "/%s" % xid
|
||||||
|
|
||||||
|
|
||||||
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 the dbus python bindings."""
|
||||||
|
|
||||||
def __init__(self, pservice, xid, activity):
|
def start(self, pservice, activity):
|
||||||
self._activity = activity
|
self._activity = activity
|
||||||
self._pservice = pservice
|
self._pservice = pservice
|
||||||
|
|
||||||
bus = dbus.SessionBus()
|
|
||||||
service_name = ACTIVITY_SERVICE_NAME
|
|
||||||
self._object_path = ACTIVITY_SERVICE_PATH + "/%s" % xid
|
|
||||||
service = dbus.service.BusName(service_name, bus=bus)
|
|
||||||
dbus.service.Object.__init__(self, service, self._object_path)
|
|
||||||
|
|
||||||
def get_object_path(self):
|
|
||||||
return self._object_path
|
|
||||||
|
|
||||||
@dbus.service.method(ACTIVITY_INTERFACE)
|
@dbus.service.method(ACTIVITY_INTERFACE)
|
||||||
def share(self):
|
def share(self):
|
||||||
"""Called by the shell to request the activity to share itself on the network."""
|
"""Called by the shell to request the activity to share itself on the network."""
|
||||||
@ -68,7 +68,7 @@ class ActivityDbusService(dbus.service.Object):
|
|||||||
class Activity(gtk.Window):
|
class Activity(gtk.Window):
|
||||||
"""Base Activity class that all other Activities derive from."""
|
"""Base Activity class that all other Activities derive from."""
|
||||||
|
|
||||||
def __init__(self, service = None):
|
def __init__(self):
|
||||||
gtk.Window.__init__(self)
|
gtk.Window.__init__(self)
|
||||||
|
|
||||||
self._shared = False
|
self._shared = False
|
||||||
@ -82,17 +82,17 @@ class Activity(gtk.Window):
|
|||||||
group.realize()
|
group.realize()
|
||||||
self.window.set_group(group.window)
|
self.window.set_group(group.window)
|
||||||
|
|
||||||
self._bus = ActivityDbusService(self._pservice, self.window.xid, self)
|
bus = dbus.SessionBus()
|
||||||
|
xid = self.window.xid
|
||||||
|
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 __del__(self):
|
def __del__(self):
|
||||||
if self._bus:
|
if self._bus:
|
||||||
del self._bus
|
del self._bus
|
||||||
self._bus = None
|
self._bus = None
|
||||||
|
|
||||||
def get_object_path(self):
|
|
||||||
"""Returns the path of the activity dbus service"""
|
|
||||||
return self._bus.get_object_path()
|
|
||||||
|
|
||||||
def set_default_type(self, default_type):
|
def set_default_type(self, default_type):
|
||||||
"""Set the activity default type.
|
"""Set the activity default type.
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ class ActivityFactory(dbus.service.Object):
|
|||||||
@dbus.service.method("com.redhat.Sugar.ActivityFactory")
|
@dbus.service.method("com.redhat.Sugar.ActivityFactory")
|
||||||
def create(self):
|
def create(self):
|
||||||
activity = self._class()
|
activity = self._class()
|
||||||
return activity.get_object_path()
|
return activity.window.xid
|
||||||
|
|
||||||
def create(activity_name):
|
def create(activity_name):
|
||||||
"""Create a new activity from his name."""
|
"""Create a new activity from his name."""
|
||||||
@ -50,10 +50,11 @@ def create(activity_name):
|
|||||||
proxy_obj = bus.get_object(factory_name, factory_path)
|
proxy_obj = bus.get_object(factory_name, factory_path)
|
||||||
factory = dbus.Interface(proxy_obj, "com.redhat.Sugar.ActivityFactory")
|
factory = dbus.Interface(proxy_obj, "com.redhat.Sugar.ActivityFactory")
|
||||||
|
|
||||||
activity_path = factory.create()
|
xid = factory.create()
|
||||||
|
|
||||||
bus = dbus.SessionBus()
|
bus = dbus.SessionBus()
|
||||||
proxy_obj = bus.get_object(Activity.ACTIVITY_SERVICE_NAME, activity_path)
|
proxy_obj = bus.get_object(Activity.get_service_name(xid),
|
||||||
|
Activity.get_object_path(xid))
|
||||||
activity = dbus.Interface(proxy_obj, Activity.ACTIVITY_INTERFACE)
|
activity = dbus.Interface(proxy_obj, Activity.ACTIVITY_INTERFACE)
|
||||||
|
|
||||||
return activity
|
return activity
|
||||||
|
Loading…
Reference in New Issue
Block a user