Split ActivityHost in model/view. Refactor accordingly.
This commit is contained in:
@@ -17,10 +17,7 @@
|
||||
import gtk
|
||||
import dbus
|
||||
|
||||
from sugar import profile
|
||||
from sugar.activity import Activity
|
||||
from sugar.presence import PresenceService
|
||||
from sugar.graphics.iconcolor import IconColor
|
||||
from sugar.p2p import Stream
|
||||
from sugar.p2p import network
|
||||
from sugar.chat import ActivityChat
|
||||
@@ -41,23 +38,12 @@ class ActivityChatWindow(gtk.Window):
|
||||
self.add(chat_widget)
|
||||
|
||||
class ActivityHost:
|
||||
def __init__(self, shell_model, window):
|
||||
self._window = window
|
||||
self._xid = window.get_xid()
|
||||
self._pservice = PresenceService.get_instance()
|
||||
|
||||
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 = shell_model.get_bundle_registry()
|
||||
info = registry.get_bundle(self._type)
|
||||
self._icon_name = info.get_icon()
|
||||
def __init__(self, model):
|
||||
self._model = model
|
||||
self._id = model.get_id()
|
||||
self._window = model.get_window()
|
||||
self._activity = Activity.get_service(self.get_xid())
|
||||
self._gdk_window = gtk.gdk.window_foreign_new(self.get_xid())
|
||||
|
||||
try:
|
||||
self._overlay_window = OverlayWindow.OverlayWindow(self._gdk_window)
|
||||
@@ -74,21 +60,11 @@ class ActivityHost:
|
||||
def get_id(self):
|
||||
return self._id
|
||||
|
||||
def get_title(self):
|
||||
return self._window.get_name()
|
||||
|
||||
def get_xid(self):
|
||||
return self._xid
|
||||
return self._window.get_xid()
|
||||
|
||||
def get_icon_name(self):
|
||||
return self._icon_name
|
||||
|
||||
def get_icon_color(self):
|
||||
activity = self._pservice.get_activity(self._id)
|
||||
if activity != None:
|
||||
return IconColor(activity.get_color())
|
||||
else:
|
||||
return profile.get_color()
|
||||
def get_model(self):
|
||||
return self._model
|
||||
|
||||
def execute(self, command, args):
|
||||
self._activity.execute(command, args)
|
||||
@@ -108,12 +84,6 @@ class ActivityHost:
|
||||
writer.custom_request("invite", None, None, issuer,
|
||||
self._type, self._id)
|
||||
|
||||
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())
|
||||
|
||||
|
||||
+12
-30
@@ -35,12 +35,8 @@ import sugar
|
||||
|
||||
class Shell(gobject.GObject):
|
||||
__gsignals__ = {
|
||||
'activity-opened': (gobject.SIGNAL_RUN_FIRST,
|
||||
gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT])),
|
||||
'activity-changed': (gobject.SIGNAL_RUN_FIRST,
|
||||
gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT])),
|
||||
'activity-closed': (gobject.SIGNAL_RUN_FIRST,
|
||||
gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT]))
|
||||
}
|
||||
|
||||
def __init__(self, model):
|
||||
@@ -66,8 +62,10 @@ class Shell(gobject.GObject):
|
||||
self._home_window.show()
|
||||
self.set_zoom_level(sugar.ZOOM_HOME)
|
||||
|
||||
self._screen.connect('window-opened', self.__window_opened_cb)
|
||||
self._screen.connect('window-closed', self.__window_closed_cb)
|
||||
home_model = self._model.get_home()
|
||||
home_model.connect('activity-added', self._activity_added_cb)
|
||||
home_model.connect('activity-removed', self._activity_removed_cb)
|
||||
|
||||
self._screen.connect('active-window-changed',
|
||||
self.__active_window_changed_cb)
|
||||
|
||||
@@ -139,19 +137,9 @@ class Shell(gobject.GObject):
|
||||
elif key == '0x93':
|
||||
self._frame.notify_key_release()
|
||||
|
||||
def __window_opened_cb(self, screen, window):
|
||||
logging.debug('Shell.__window_opened_cb')
|
||||
if window.get_window_type() == wnck.WINDOW_NORMAL:
|
||||
try:
|
||||
activity_host = ActivityHost(self.get_model(), window)
|
||||
except dbus.DBusException:
|
||||
logging.debug('Shell.__window_opened_cb: opened unknown window ' +
|
||||
window.get_name() + ' with xid ' +
|
||||
str(window.get_xid()))
|
||||
return
|
||||
|
||||
self._hosts[activity_host.get_xid()] = activity_host
|
||||
self.emit('activity-opened', activity_host)
|
||||
def _activity_added_cb(self, home_model, home_activity):
|
||||
activity_host = ActivityHost(home_activity)
|
||||
self._hosts[activity_host.get_xid()] = activity_host
|
||||
|
||||
def __active_window_changed_cb(self, screen):
|
||||
logging.debug('Shell.__active_window_changed_cb')
|
||||
@@ -168,19 +156,13 @@ class Shell(gobject.GObject):
|
||||
|
||||
self._set_current_activity(activity_host)
|
||||
|
||||
def __window_closed_cb(self, screen, window):
|
||||
logging.debug('Shell.__window_closed_cb')
|
||||
if window.get_window_type() != wnck.WINDOW_NORMAL:
|
||||
def _activity_removed_cb(self, home_model, home_activity):
|
||||
xid = home_activity.get_window().get_xid()
|
||||
if not self._hosts.has_key(xid):
|
||||
return
|
||||
|
||||
if not self._hosts.has_key(window.get_xid()):
|
||||
return
|
||||
|
||||
host = self._hosts[window.get_xid()]
|
||||
host.destroy()
|
||||
|
||||
self.emit('activity-closed', host)
|
||||
del self._hosts[window.get_xid()]
|
||||
self._hosts[xid].destroy()
|
||||
del self._hosts[xid]
|
||||
|
||||
if len(self._hosts) == 0:
|
||||
self._set_current_activity(None)
|
||||
|
||||
+11
-14
@@ -26,10 +26,10 @@ class ActivityMenu(Menu):
|
||||
ACTION_SHARE = 1
|
||||
ACTION_CLOSE = 2
|
||||
|
||||
def __init__(self, activity_host):
|
||||
Menu.__init__(self, activity_host.get_title())
|
||||
def __init__(self, activity_model):
|
||||
Menu.__init__(self, activity_model.get_title())
|
||||
|
||||
if not activity_host.get_shared():
|
||||
if not activity_model.get_shared():
|
||||
self._add_mesh_action()
|
||||
|
||||
self._add_close_action()
|
||||
@@ -43,32 +43,29 @@ class ActivityMenu(Menu):
|
||||
self.add_action(icon, ActivityMenu.ACTION_CLOSE)
|
||||
|
||||
class ActivityIcon(MenuIcon):
|
||||
def __init__(self, shell, menu_shell, activity_host):
|
||||
def __init__(self, shell, menu_shell, activity):
|
||||
self._shell = shell
|
||||
self._activity_host = activity_host
|
||||
self._activity = activity
|
||||
self._activity_model = activity.get_model()
|
||||
|
||||
icon_name = activity_host.get_icon_name()
|
||||
icon_color = activity_host.get_icon_color()
|
||||
icon_name = self._activity_model.get_icon_name()
|
||||
icon_color = self._activity_model.get_icon_color()
|
||||
|
||||
MenuIcon.__init__(self, menu_shell, icon_name=icon_name,
|
||||
color=icon_color)
|
||||
|
||||
def create_menu(self):
|
||||
menu = ActivityMenu(self._activity_host)
|
||||
menu = ActivityMenu(self._activity_model)
|
||||
menu.connect('action', self._action_cb)
|
||||
return menu
|
||||
|
||||
def _action_cb(self, menu, action):
|
||||
self.popdown()
|
||||
|
||||
activity = self._shell.get_current_activity()
|
||||
if activity == None:
|
||||
return
|
||||
|
||||
if action == ActivityMenu.ACTION_SHARE:
|
||||
activity.share()
|
||||
self._activity.share()
|
||||
if action == ActivityMenu.ACTION_CLOSE:
|
||||
activity.close()
|
||||
self._activity.close()
|
||||
|
||||
class ZoomBox(hippo.CanvasBox):
|
||||
def __init__(self, shell, menu_shell):
|
||||
|
||||
@@ -19,7 +19,6 @@ import math
|
||||
|
||||
from sugar.graphics.canvasicon import CanvasIcon
|
||||
from sugar.graphics import style
|
||||
from model.homemodel import HomeModel
|
||||
|
||||
class ActivitiesDonut(hippo.CanvasBox, hippo.CanvasItem):
|
||||
__gtype_name__ = 'SugarActivitiesDonut'
|
||||
@@ -29,7 +28,7 @@ class ActivitiesDonut(hippo.CanvasBox, hippo.CanvasItem):
|
||||
self._activities = {}
|
||||
self._shell = shell
|
||||
|
||||
self._model = HomeModel(shell)
|
||||
self._model = shell.get_model().get_home()
|
||||
self._model.connect('activity-added', self._activity_added_cb)
|
||||
self._model.connect('activity-removed', self._activity_removed_cb)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user