sugar-toolkit-gtk3/shell/view/ActivityHost.py

73 lines
1.9 KiB
Python
Raw Normal View History

import gtk
import dbus
import conf
from sugar.activity import Activity
2006-08-26 14:17:55 +02:00
from sugar.presence import PresenceService
from sugar.canvas.IconColor import IconColor
2006-09-04 14:30:44 +02:00
from sugar.p2p import Stream
from sugar.p2p import network
class ActivityHost:
2006-08-09 18:29:33 +02:00
def __init__(self, shell, window):
2006-07-26 12:57:54 +02:00
self._shell = shell
self._window = window
self._xid = window.get_xid()
self._pservice = PresenceService.get_instance()
2006-08-09 18:29:33 +02:00
bus = dbus.SessionBus()
proxy_obj = bus.get_object(Activity.get_service_name(self._xid),
Activity.get_object_path(self._xid))
self._activity = dbus.Interface(proxy_obj, Activity.ACTIVITY_INTERFACE)
self._id = self._activity.get_id()
self._type = self._activity.get_type()
self._gdk_window = gtk.gdk.window_foreign_new(self._xid)
registry = conf.get_activity_registry()
info = registry.get_activity(self._type)
self._icon_name = info.get_icon()
def get_id(self):
return self._id
def get_xid(self):
return self._xid
def get_icon_name(self):
return self._icon_name
2006-08-26 14:17:55 +02:00
def get_icon_color(self):
activity = self._pservice.get_activity(self._id)
2006-08-26 14:17:55 +02:00
if activity != None:
return IconColor(activity.get_color())
else:
return conf.get_profile().get_color()
2006-07-26 00:17:05 +02:00
def share(self):
self._activity.share()
2006-09-04 14:30:44 +02:00
def invite(self, buddy):
if not self.get_shared():
self.share()
issuer = self._pservice.get_owner().get_name()
2006-09-04 14:30:44 +02:00
service = buddy.get_service_of_type("_presence_olpc._tcp")
stream = Stream.Stream.new_from_service(service, start_reader=False)
writer = stream.new_writer(service)
writer.custom_request("invite", None, None, issuer,
self._type, self._id)
2006-09-04 14:30:44 +02:00
def get_shared(self):
return self._activity.get_shared()
def get_type(self):
return self._type
def present(self):
self._window.activate(gtk.get_current_event_time())
def show_dialog(self, dialog):
dialog.show()
dialog.window.set_transient_for(self._gdk_window)