Cleanup shell model/view separation

This commit is contained in:
Marco Pesenti Gritti
2006-09-18 11:48:33 +02:00
parent 274dfbbf6a
commit 1f3187e0b5
6 changed files with 59 additions and 63 deletions
+44 -4
View File
@@ -13,10 +13,20 @@ from globalkeys import KeyGrabber
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):
gobject.GObject.__init__(self)
self._model = model
self._hosts = {}
self._screen = wnck.screen_get_default()
self._grid = Grid()
@@ -57,16 +67,33 @@ class Shell(gobject.GObject):
def __window_opened_cb(self, screen, window):
if window.get_window_type() == wnck.WINDOW_NORMAL:
self._model.add_activity(ActivityHost(self, window))
activity_host = ActivityHost(self, window)
self._hosts[activity_host.get_xid()] = activity_host
self.emit('activity-opened', activity_host)
def __active_window_changed_cb(self, screen):
window = screen.get_active_window()
if window and window.get_window_type() == wnck.WINDOW_NORMAL:
self._model.set_current_activity(window.get_xid())
if window == None:
self._model.set_current_activity(None)
self.emit('activity-changed', None)
if window.get_window_type() == wnck.WINDOW_NORMAL:
activity_host = self._hosts[window.get_xid()]
current = self._model.get_current_activity()
if activity_host.get_id() == current:
return
self._model.set_current_activity(activity_host.get_id())
self.emit('activity-changed', activity_host)
def __window_closed_cb(self, screen, window):
if window.get_window_type() == wnck.WINDOW_NORMAL:
self._model.remove_activity(window.get_xid())
if self._hosts.has_key(window.get_xid()):
host = self._hosts[window.get_xid()]
self.emit('activity-closed', host)
del self._hosts[window.get_xid()]
def get_model(self):
return self._model
@@ -100,3 +127,16 @@ class Shell(gobject.GObject):
else:
self._screen.toggle_showing_desktop(True)
self._home_window.set_zoom_level(level)
def get_current_activity(self):
activity_id = self._model.get_current_activity()
if activity_id:
return self._get_activity(activity_id)
else:
return None
def _get_activity(self, activity_id):
for host in self._hosts.values():
if host.get_id() == activity_id:
return host
return None
+2 -3
View File
@@ -21,8 +21,7 @@ class RightPanel(CanvasBox):
self._pservice.connect('activity-appeared',
self.__activity_appeared_cb)
shell.get_model().connect('activity-changed',
self.__activity_changed_cb)
shell.connect('activity-changed', self.__activity_changed_cb)
def add(self, buddy):
icon = BuddyIcon(self._shell, BuddyInfo(buddy))
@@ -42,7 +41,7 @@ class RightPanel(CanvasBox):
self._buddies = {}
def __activity_appeared_cb(self, pservice, activity_ps):
activity = self._shell.get_model().get_current_activity()
activity = self._shell.get_current_activity()
if activity and activity_ps.get_id() == activity.get_id():
self._set_activity_ps(activity_ps)
+3 -5
View File
@@ -37,8 +37,7 @@ class ActivityIcon(MenuIcon):
def _action_cb(self, menu, action):
if action == ActivityMenu.ACTION_SHARE:
shell_model = self._shell.get_model()
activity = shell_model.get_current_activity()
activity = shell.get_current_activity()
if activity != None:
activity.share()
@@ -77,9 +76,8 @@ class TopPanel(goocanvas.Group):
self._box = box
shell_model = shell.get_model()
shell_model.connect('activity-changed', self._activity_changed_cb)
self._set_current_activity(shell_model.get_current_activity())
shell.connect('activity-changed', self._activity_changed_cb)
self._set_current_activity(shell.get_current_activity())
def _set_current_activity(self, activity):
if self._activity_icon:
+2 -3
View File
@@ -9,9 +9,8 @@ class TasksItem(DonutItem):
self._items = {}
shell_model = shell.get_model()
shell_model.connect('activity_opened', self.__activity_opened_cb)
shell_model.connect('activity_closed', self.__activity_closed_cb)
shell.connect('activity_opened', self.__activity_opened_cb)
shell.connect('activity_closed', self.__activity_closed_cb)
def __activity_opened_cb(self, model, activity):
self._add(activity)