From 3a4f8da5ce573ed8728cf2a0d3d35603aeb5fffa Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Thu, 14 Sep 2006 19:37:40 +0200 Subject: [PATCH 01/27] Factor out friend icon --- shell/FriendIcon.py | 53 ++++++++++++++++++++++++++++++++++++++ shell/Makefile.am | 1 + shell/home/FriendsGroup.py | 53 +------------------------------------- 3 files changed, 55 insertions(+), 52 deletions(-) create mode 100644 shell/FriendIcon.py diff --git a/shell/FriendIcon.py b/shell/FriendIcon.py new file mode 100644 index 00000000..384e7455 --- /dev/null +++ b/shell/FriendIcon.py @@ -0,0 +1,53 @@ +from sugar.canvas.IconItem import IconItem +from FriendPopup import FriendPopup +from sugar.canvas.Grid import Grid + +class FriendIcon(IconItem): + def __init__(self, shell, friend): + IconItem.__init__(self, icon_name='stock-buddy', + color=friend.get_color(), size=96) + + self._shell = shell + self._friend = friend + self._popup = None + + self.connect('popup', self._popup_cb) + self.connect('popdown', self._popdown_cb) + + def get_friend(self): + return self._friend + + def _popup_cb(self, icon, x1, y1, x2, y2): + grid = Grid() + + if not self._popup: + self._popup = FriendPopup(self._shell, grid, icon.get_friend()) + + [grid_x1, grid_y1] = grid.convert_from_screen(x1, y1) + [grid_x2, grid_y2] = grid.convert_from_screen(x2, y2) + + if grid_x2 + self._popup.get_width() + 1 > Grid.ROWS: + grid_x = grid_x1 - self._popup.get_width() + 1 + else: + grid_x = grid_x2 - 1 + + grid_y = grid_y1 + + if grid_y < 0: + grid_y = 0 + if grid_y + self._popup.get_width() > Grid.ROWS: + grid_y = Grid.ROWS - self._popup.get_width() + + grid.set_constraints(self._popup, grid_x, grid_y, + self._popup.get_width(), self._popup.get_height()) + + self._popup.show() + + def _popup_destroy_cb(self, popup): + self._popup = None + + def _popdown_cb(self, friend): + if self._popup: + self._popup.connect('destroy', self._popup_destroy_cb) + self._popup.popdown() + diff --git a/shell/Makefile.am b/shell/Makefile.am index 4a1d49bc..f48be4e9 100644 --- a/shell/Makefile.am +++ b/shell/Makefile.am @@ -14,6 +14,7 @@ sugar_PYTHON = \ ChatController.py \ ConsoleWindow.py \ FirstTimeDialog.py \ + FriendIcon.py \ FriendPopup.py \ Friends.py \ Invites.py \ diff --git a/shell/home/FriendsGroup.py b/shell/home/FriendsGroup.py index 605070ba..ed87015b 100644 --- a/shell/home/FriendsGroup.py +++ b/shell/home/FriendsGroup.py @@ -2,60 +2,9 @@ import random import goocanvas -from sugar.canvas.IconItem import IconItem from home.IconLayout import IconLayout from home.MyIcon import MyIcon -from FriendPopup import FriendPopup -from sugar.canvas.Grid import Grid - -class FriendIcon(IconItem): - def __init__(self, shell, friend): - IconItem.__init__(self, icon_name='stock-buddy', - color=friend.get_color(), size=96) - - self._shell = shell - self._friend = friend - self._popup = None - - self.connect('popup', self._popup_cb) - self.connect('popdown', self._popdown_cb) - - def get_friend(self): - return self._friend - - def _popup_cb(self, icon, x1, y1, x2, y2): - grid = Grid() - - if not self._popup: - self._popup = FriendPopup(self._shell, grid, icon.get_friend()) - - [grid_x1, grid_y1] = grid.convert_from_screen(x1, y1) - [grid_x2, grid_y2] = grid.convert_from_screen(x2, y2) - - if grid_x2 + self._popup.get_width() + 1 > Grid.ROWS: - grid_x = grid_x1 - self._popup.get_width() + 1 - else: - grid_x = grid_x2 - 1 - - grid_y = grid_y1 - - if grid_y < 0: - grid_y = 0 - if grid_y + self._popup.get_width() > Grid.ROWS: - grid_y = Grid.ROWS - self._popup.get_width() - - grid.set_constraints(self._popup, grid_x, grid_y, - self._popup.get_width(), self._popup.get_height()) - - self._popup.show() - - def _popup_destroy_cb(self, popup): - self._popup = None - - def _popdown_cb(self, friend): - if self._popup: - self._popup.connect('destroy', self._popup_destroy_cb) - self._popup.popdown() +from FriendIcon import FriendIcon class FriendsGroup(goocanvas.Group): def __init__(self, shell, friends): From 8265e29cdfffb06c94ca5a17029b4aaab5df6a7f Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Thu, 14 Sep 2006 20:52:21 +0200 Subject: [PATCH 02/27] Use FriendIcon in the frame --- shell/FriendPopup.py | 3 ++- shell/Shell.py | 3 +++ shell/frame/RightPanel.py | 11 ++++------- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/shell/FriendPopup.py b/shell/FriendPopup.py index 1d309a6d..8a9f6691 100644 --- a/shell/FriendPopup.py +++ b/shell/FriendPopup.py @@ -75,7 +75,8 @@ class FriendPopup(gtk.Window): print 'Friend not online' def _make_friend_clicked_cb(self, icon): - pass + friends = self._shell.get_owner().get_friends() + friends.add_buddy(buddy) def _enter_notify_event_cb(self, widget, event): self._hover = True diff --git a/shell/Shell.py b/shell/Shell.py index efe6a5a0..044d25d2 100755 --- a/shell/Shell.py +++ b/shell/Shell.py @@ -84,6 +84,9 @@ class Shell(gobject.GObject): self._frame = Frame(self, self._owner) self._frame.show_and_hide(10) + def get_owner(self): + return self._owner + def __global_key_pressed_cb(self, grabber, key): if key == 'F1': self.set_zoom_level(sugar.ZOOM_ACTIVITY) diff --git a/shell/frame/RightPanel.py b/shell/frame/RightPanel.py index 80729fd3..cb2f4f14 100644 --- a/shell/frame/RightPanel.py +++ b/shell/frame/RightPanel.py @@ -4,6 +4,8 @@ from sugar.canvas.IconItem import IconItem from sugar.canvas.IconColor import IconColor from sugar.canvas.CanvasBox import CanvasBox from sugar.presence import PresenceService +from FriendIcon import FriendIcon +from Friends import Friend class RightPanel(CanvasBox): def __init__(self, grid, shell, friends): @@ -22,11 +24,9 @@ class RightPanel(CanvasBox): shell.connect('activity-changed', self.__activity_changed_cb) def add(self, buddy): - icon = IconItem(icon_name='stock-buddy', - color=IconColor(buddy.get_color())) + friend = Friend(buddy.get_name(), buddy.get_color()) + icon = FriendIcon(self._shell, friend) self.set_constraints(icon, 3, 3) - icon.connect('clicked', self.__buddy_clicked_cb, buddy) - self.add_child(icon) self._buddies[buddy.get_name()] = icon @@ -78,6 +78,3 @@ class RightPanel(CanvasBox): def __buddy_left_cb(self, activity, buddy): self.remove(buddy) - - def __buddy_clicked_cb(self, icon, buddy): - self._friends.add_buddy(buddy) From e12881e36b760bd7ce703961f97a39c89da6c8de Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Thu, 14 Sep 2006 21:01:59 +0200 Subject: [PATCH 03/27] Pass screen relative coordinates in the popup event --- sugar/canvas/IconItem.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sugar/canvas/IconItem.py b/sugar/canvas/IconItem.py index 38850f1d..f7626151 100644 --- a/sugar/canvas/IconItem.py +++ b/sugar/canvas/IconItem.py @@ -257,6 +257,13 @@ class IconItem(goocanvas.ItemSimple, goocanvas.Item): [x2, y2] = canvas.convert_to_pixels(view.get_bounds().x2, view.get_bounds().y2) + [window_x, window_y] = canvas.window.get_origin() + + x1 += window_x + y1 += window_y + x2 += window_x + y2 += window_y + self.emit('popup', int(x1), int(y1), int(x2), int(y2)) def _popdown(self): From 3ee23b3a92c0be2e6eae3be19a9922934bab4b4c Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Thu, 14 Sep 2006 21:15:48 +0200 Subject: [PATCH 04/27] Keep popups out of the frame --- shell/FriendIcon.py | 12 +++++++++--- shell/frame/RightPanel.py | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/shell/FriendIcon.py b/shell/FriendIcon.py index 384e7455..3824bba6 100644 --- a/shell/FriendIcon.py +++ b/shell/FriendIcon.py @@ -10,10 +10,14 @@ class FriendIcon(IconItem): self._shell = shell self._friend = friend self._popup = None + self._popup_distance = 0 self.connect('popup', self._popup_cb) self.connect('popdown', self._popdown_cb) + def set_popup_distance(self, distance): + self._popup_distance = distance + def get_friend(self): return self._friend @@ -23,13 +27,15 @@ class FriendIcon(IconItem): if not self._popup: self._popup = FriendPopup(self._shell, grid, icon.get_friend()) + distance = self._popup_distance + [grid_x1, grid_y1] = grid.convert_from_screen(x1, y1) [grid_x2, grid_y2] = grid.convert_from_screen(x2, y2) - if grid_x2 + self._popup.get_width() + 1 > Grid.ROWS: - grid_x = grid_x1 - self._popup.get_width() + 1 + if grid_x2 + self._popup.get_width() + distance > Grid.ROWS: + grid_x = grid_x1 - self._popup.get_width() - distance else: - grid_x = grid_x2 - 1 + grid_x = grid_x2 + distance grid_y = grid_y1 diff --git a/shell/frame/RightPanel.py b/shell/frame/RightPanel.py index cb2f4f14..be55abf2 100644 --- a/shell/frame/RightPanel.py +++ b/shell/frame/RightPanel.py @@ -26,6 +26,7 @@ class RightPanel(CanvasBox): def add(self, buddy): friend = Friend(buddy.get_name(), buddy.get_color()) icon = FriendIcon(self._shell, friend) + icon.set_popup_distance(1) self.set_constraints(icon, 3, 3) self.add_child(icon) From fd92a6d7d92e8cad3b4ca9a69c5f73e2fbe03f54 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 15 Sep 2006 00:34:42 +0200 Subject: [PATCH 05/27] Improve popup/popdown logic --- shell/FriendIcon.py | 35 +++++++++++++++++++++++++---------- shell/FriendPopup.py | 23 +++-------------------- 2 files changed, 28 insertions(+), 30 deletions(-) diff --git a/shell/FriendIcon.py b/shell/FriendIcon.py index 3824bba6..94de02dc 100644 --- a/shell/FriendIcon.py +++ b/shell/FriendIcon.py @@ -11,6 +11,8 @@ class FriendIcon(IconItem): self._friend = friend self._popup = None self._popup_distance = 0 + self._hover_popup = False + self._popdown_on_leave = False self.connect('popup', self._popup_cb) self.connect('popdown', self._popdown_cb) @@ -21,11 +23,21 @@ class FriendIcon(IconItem): def get_friend(self): return self._friend - def _popup_cb(self, icon, x1, y1, x2, y2): - grid = Grid() + def _popdown(self): + if self._popup: + self._popup.destroy() + self._popup = None - if not self._popup: - self._popup = FriendPopup(self._shell, grid, icon.get_friend()) + def _popup_cb(self, icon, x1, y1, x2, y2): + self._popdown() + + grid = Grid() + self._popup = FriendPopup(self._shell, grid, icon.get_friend()) + + self._popup.connect('enter-notify-event', + self._popup_enter_notify_event_cb) + self._popup.connect('leave-notify-event', + self._popup_leave_notify_event_cb) distance = self._popup_distance @@ -49,11 +61,14 @@ class FriendIcon(IconItem): self._popup.show() - def _popup_destroy_cb(self, popup): - self._popup = None - def _popdown_cb(self, friend): - if self._popup: - self._popup.connect('destroy', self._popup_destroy_cb) - self._popup.popdown() + if not self._hover_popup: + self._popdown() + def _popup_enter_notify_event_cb(self, widget, event): + self._hover_popup = True + + def _popup_leave_notify_event_cb(self, widget, event): + self._hover_popup = False + if self._popdown_on_leave: + self._popdown() diff --git a/shell/FriendPopup.py b/shell/FriendPopup.py index 8a9f6691..4a2cd1b1 100644 --- a/shell/FriendPopup.py +++ b/shell/FriendPopup.py @@ -63,34 +63,17 @@ class FriendPopup(gtk.Window): canvas.set_model(model) - self.connect('enter-notify-event', self._enter_notify_event_cb) - self.connect('leave-notify-event', self._leave_notify_event_cb) - def _invite_clicked_cb(self, icon): activity = self._shell.get_current_activity() buddy = self._friend.get_buddy() if buddy != None: activity.invite(buddy) - else: - print 'Friend not online' def _make_friend_clicked_cb(self, icon): friends = self._shell.get_owner().get_friends() - friends.add_buddy(buddy) - - def _enter_notify_event_cb(self, widget, event): - self._hover = True - - def _leave_notify_event_cb(self, widget, event): - self._hover = False - if self._popdown_on_leave: - self.popdown() - - def popdown(self): - if not self._hover: - self.destroy() - else: - self._popdown_on_leave = True + buddy = self._friend.get_buddy() + if buddy != None: + friends.add_buddy(buddy) def get_width(self): return self._width From 3fc81ae94530fb19f1519da983605e33ca2b4cb1 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 15 Sep 2006 01:01:26 +0200 Subject: [PATCH 06/27] Add a popup shell which ensure only one popup is active at the same time. --- shell/FriendIcon.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/shell/FriendIcon.py b/shell/FriendIcon.py index 94de02dc..36e702c5 100644 --- a/shell/FriendIcon.py +++ b/shell/FriendIcon.py @@ -2,7 +2,18 @@ from sugar.canvas.IconItem import IconItem from FriendPopup import FriendPopup from sugar.canvas.Grid import Grid +class _PopupShell: + def __init__(self): + self._popup_controller = None + + def set_active(self, controller): + if self._popup_controller: + self._popup_controller._popdown() + self._popup_controller = controller + class FriendIcon(IconItem): + _popup_shell = _PopupShell() + def __init__(self, shell, friend): IconItem.__init__(self, icon_name='stock-buddy', color=friend.get_color(), size=96) @@ -31,9 +42,10 @@ class FriendIcon(IconItem): def _popup_cb(self, icon, x1, y1, x2, y2): self._popdown() + FriendIcon._popup_shell.set_active(None) + grid = Grid() self._popup = FriendPopup(self._shell, grid, icon.get_friend()) - self._popup.connect('enter-notify-event', self._popup_enter_notify_event_cb) self._popup.connect('leave-notify-event', @@ -61,6 +73,8 @@ class FriendIcon(IconItem): self._popup.show() + FriendIcon._popup_shell.set_active(self) + def _popdown_cb(self, friend): if not self._hover_popup: self._popdown() From ae9adff40bda83fafe6e44ac9df7dfe9a981a8a8 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 15 Sep 2006 01:30:37 +0200 Subject: [PATCH 07/27] Cleanup --- shell/FriendIcon.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/shell/FriendIcon.py b/shell/FriendIcon.py index 36e702c5..eb2cf9dd 100644 --- a/shell/FriendIcon.py +++ b/shell/FriendIcon.py @@ -56,10 +56,9 @@ class FriendIcon(IconItem): [grid_x1, grid_y1] = grid.convert_from_screen(x1, y1) [grid_x2, grid_y2] = grid.convert_from_screen(x2, y2) - if grid_x2 + self._popup.get_width() + distance > Grid.ROWS: + grid_x = grid_x2 + distance + if grid_x + self._popup.get_width() > Grid.ROWS: grid_x = grid_x1 - self._popup.get_width() - distance - else: - grid_x = grid_x2 + distance grid_y = grid_y1 From 40ac3960554373fd6fed54f193f932d3e050ab51 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 15 Sep 2006 01:56:59 +0200 Subject: [PATCH 08/27] Fix small bugs in the grid logic --- shell/FriendIcon.py | 2 +- sugar/canvas/Grid.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/shell/FriendIcon.py b/shell/FriendIcon.py index eb2cf9dd..8d1017c2 100644 --- a/shell/FriendIcon.py +++ b/shell/FriendIcon.py @@ -58,7 +58,7 @@ class FriendIcon(IconItem): grid_x = grid_x2 + distance if grid_x + self._popup.get_width() > Grid.ROWS: - grid_x = grid_x1 - self._popup.get_width() - distance + grid_x = grid_x1 - self._popup.get_width() + 1 - distance grid_y = grid_y1 diff --git a/sugar/canvas/Grid.py b/sugar/canvas/Grid.py index e4c377ab..50b5dbe6 100644 --- a/sugar/canvas/Grid.py +++ b/sugar/canvas/Grid.py @@ -10,7 +10,11 @@ class Grid: def convert_from_screen(self, x, y): factor = Grid.COLS / gtk.gdk.screen_width() - return [int(x * factor), int(y * factor)] + + grid_x = round(x * factor) - 1 + grid_y = round(y * factor) - 1 + + return [grid_x, grid_y] def set_constraints(self, component, x, y, width=-1, height=-1): if isinstance(component, gtk.Window): From dd15b0d063ccfa2e76a81231b969dc0ec4293efd Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 15 Sep 2006 01:59:49 +0200 Subject: [PATCH 09/27] Improve function naming --- sugar/canvas/IconItem.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sugar/canvas/IconItem.py b/sugar/canvas/IconItem.py index f7626151..dcc65cdb 100644 --- a/sugar/canvas/IconItem.py +++ b/sugar/canvas/IconItem.py @@ -240,17 +240,17 @@ class IconItem(goocanvas.ItemSimple, goocanvas.Item): def _button_press_cb(self, view, target, event): self.emit('clicked') - def _start_popup_timeout(self): - self._stop_popup_timeout() + def _start_popdown_timeout(self): + self._stop_popdown_timeout() self._popdown_timeout = gobject.timeout_add(1000, self._popdown) - def _stop_popup_timeout(self): + def _stop_popdown_timeout(self): if self._popdown_timeout > 0: gobject.source_remove(self._popdown_timeout) self._popdown_timeout = 0 def _enter_notify_event_cb(self, view, target, event, canvas): - self._stop_popup_timeout() + self._stop_popdown_timeout() [x1, y1] = canvas.convert_to_pixels(view.get_bounds().x1, view.get_bounds().y1) @@ -272,4 +272,4 @@ class IconItem(goocanvas.ItemSimple, goocanvas.Item): return False def _leave_notify_event_cb(self, view, target, event): - self._start_popup_timeout() + self._start_popdown_timeout() From 3a10f80aa1bc003329498f4e2df7d9d4ef6f3770 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 15 Sep 2006 02:54:25 +0200 Subject: [PATCH 10/27] A bunch of cleanups and fixes --- shell/FriendIcon.py | 19 ++++++++++++++++++- shell/FriendPopup.py | 31 ++++++++++++++++--------------- sugar/canvas/IconItem.py | 14 +++++++------- 3 files changed, 41 insertions(+), 23 deletions(-) diff --git a/shell/FriendIcon.py b/shell/FriendIcon.py index 8d1017c2..0c6b1e67 100644 --- a/shell/FriendIcon.py +++ b/shell/FriendIcon.py @@ -45,7 +45,8 @@ class FriendIcon(IconItem): FriendIcon._popup_shell.set_active(None) grid = Grid() - self._popup = FriendPopup(self._shell, grid, icon.get_friend()) + self._popup = FriendPopup(grid, icon.get_friend()) + self._popup.connect('action', self._popup_action_cb) self._popup.connect('enter-notify-event', self._popup_enter_notify_event_cb) self._popup.connect('leave-notify-event', @@ -74,9 +75,25 @@ class FriendIcon(IconItem): FriendIcon._popup_shell.set_active(self) + def _popup_action_cb(self, popup, action): + self._popdown() + + buddy = self._friend.get_buddy() + if buddy == None: + return + + if action == FriendPopup.ACTION_INVITE: + activity = self._shell.get_current_activity() + activity.invite(buddy) + elif action == FriendPopup.ACTION_MAKE_FRIEND: + friends = self._shell.get_owner().get_friends() + friends.add_buddy(buddy) + def _popdown_cb(self, friend): if not self._hover_popup: self._popdown() + else: + self._popdown_on_leave = True def _popup_enter_notify_event_cb(self, widget, event): self._hover_popup = True diff --git a/shell/FriendPopup.py b/shell/FriendPopup.py index 4a2cd1b1..e2085942 100644 --- a/shell/FriendPopup.py +++ b/shell/FriendPopup.py @@ -1,15 +1,23 @@ import gtk import goocanvas +import gobject from sugar.canvas.CanvasView import CanvasView from sugar.canvas.CanvasBox import CanvasBox from sugar.canvas.IconItem import IconItem class FriendPopup(gtk.Window): - def __init__(self, shell, grid, friend): + ACTION_MAKE_FRIEND = 0 + ACTION_INVITE = 0 + + __gsignals__ = { + 'action': (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, ([int])), + } + + def __init__(self, grid, friend): gtk.Window.__init__(self, gtk.WINDOW_POPUP) - self._shell = shell self._friend = friend self._hover = False self._popdown_on_leave = False @@ -46,7 +54,8 @@ class FriendPopup(gtk.Window): grid.set_constraints(box, 0, 5) icon = IconItem(icon_name='stock-make-friend') - icon.connect('clicked', self._make_friend_clicked_cb) + icon.connect('clicked', self._action_clicked_cb, + FriendPopup.ACTION_MAKE_FRIEND) box.set_constraints(icon, 3, 3) box.add_child(icon) @@ -55,7 +64,8 @@ class FriendPopup(gtk.Window): box.add_child(icon) icon = IconItem(icon_name='stock-invite') - icon.connect('clicked', self._invite_clicked_cb) + icon.connect('clicked', self._action_clicked_cb, + FriendPopup.ACTION_INVITE) box.set_constraints(icon, 3, 3) box.add_child(icon) @@ -63,17 +73,8 @@ class FriendPopup(gtk.Window): canvas.set_model(model) - def _invite_clicked_cb(self, icon): - activity = self._shell.get_current_activity() - buddy = self._friend.get_buddy() - if buddy != None: - activity.invite(buddy) - - def _make_friend_clicked_cb(self, icon): - friends = self._shell.get_owner().get_friends() - buddy = self._friend.get_buddy() - if buddy != None: - friends.add_buddy(buddy) + def _action_clicked_cb(self, icon, action): + self.emit('action', action) def get_width(self): return self._width diff --git a/sugar/canvas/IconItem.py b/sugar/canvas/IconItem.py index dcc65cdb..d4be1e53 100644 --- a/sugar/canvas/IconItem.py +++ b/sugar/canvas/IconItem.py @@ -195,7 +195,7 @@ class IconItem(goocanvas.ItemSimple, goocanvas.Item): self.size = 24 self.color = None self.icon_name = None - self._popdown_timeout = 0 + self._popdown_sid = 0 goocanvas.ItemSimple.__init__(self, **kwargs) @@ -242,12 +242,12 @@ class IconItem(goocanvas.ItemSimple, goocanvas.Item): def _start_popdown_timeout(self): self._stop_popdown_timeout() - self._popdown_timeout = gobject.timeout_add(1000, self._popdown) + self._popdown_sid = gobject.timeout_add(1000, self._popdown_timeout_cb) def _stop_popdown_timeout(self): - if self._popdown_timeout > 0: - gobject.source_remove(self._popdown_timeout) - self._popdown_timeout = 0 + if self._popdown_sid > 0: + gobject.source_remove(self._popdown_sid) + self._popdown_sid = 0 def _enter_notify_event_cb(self, view, target, event, canvas): self._stop_popdown_timeout() @@ -266,8 +266,8 @@ class IconItem(goocanvas.ItemSimple, goocanvas.Item): self.emit('popup', int(x1), int(y1), int(x2), int(y2)) - def _popdown(self): - self._popdown_timeout = 0 + def _popdown_timeout_cb(self): + self._popdown_sid = 0 self.emit('popdown') return False From 86c2de3e68b6e7ff5370add495d6276ee46676b5 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 15 Sep 2006 03:08:22 +0200 Subject: [PATCH 11/27] Urgh I had fill/stroke inverted, no wonder I was getting ugly colors! --- sugar/canvas/IconColor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sugar/canvas/IconColor.py b/sugar/canvas/IconColor.py index 8babea0d..68739b0a 100644 --- a/sugar/canvas/IconColor.py +++ b/sugar/canvas/IconColor.py @@ -19,9 +19,9 @@ class IconColor: def __init__(self, color_string=None): if color_string == None or not is_valid(color_string): n = int(random.random() * (len(Colors.colors) - 1)) - [self._fill, self._stroke] = Colors.colors[n] + [self._stroke, self._fill] = Colors.colors[n] else: - [self._fill, self._stroke] = _parse_string(color_string) + [self._stroke, self._fill] = _parse_string(color_string) def get_stroke_color(self): return self._stroke From b7a5854a0bf365eda66c66cf4db7818c7f739188 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 15 Sep 2006 03:22:01 +0200 Subject: [PATCH 12/27] More color fixes --- sugar/canvas/IconColor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sugar/canvas/IconColor.py b/sugar/canvas/IconColor.py index 68739b0a..84ca409e 100644 --- a/sugar/canvas/IconColor.py +++ b/sugar/canvas/IconColor.py @@ -4,7 +4,7 @@ from sugar.canvas import Colors def _parse_string(color_string): if color_string == 'white': - return ['#4f4f4f', 'white'] + return ['white', '#4f4f4f'] splitted = color_string.split(',') if len(splitted) == 2: @@ -30,5 +30,5 @@ class IconColor: return self._fill def to_string(self): - return '%s,%s' % (self._fill, self._stroke) + return '%s,%s' % (self._stroke, self._fill) From 207f643d388fc24d997f622d7980c26a5494dabf Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 15 Sep 2006 03:33:09 +0200 Subject: [PATCH 13/27] Typo --- shell/FriendPopup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/FriendPopup.py b/shell/FriendPopup.py index e2085942..06f10da1 100644 --- a/shell/FriendPopup.py +++ b/shell/FriendPopup.py @@ -8,7 +8,7 @@ from sugar.canvas.IconItem import IconItem class FriendPopup(gtk.Window): ACTION_MAKE_FRIEND = 0 - ACTION_INVITE = 0 + ACTION_INVITE = 1 __gsignals__ = { 'action': (gobject.SIGNAL_RUN_FIRST, From 0232dc73b55b5246c927bcbc4b63d4a195b1e9c1 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 15 Sep 2006 11:49:04 +0200 Subject: [PATCH 14/27] Remove unused code --- shell/ChatController.py | 54 ----------------------------------------- shell/Makefile.am | 1 - shell/Shell.py | 7 ------ 3 files changed, 62 deletions(-) delete mode 100644 shell/ChatController.py diff --git a/shell/ChatController.py b/shell/ChatController.py deleted file mode 100644 index 022d6080..00000000 --- a/shell/ChatController.py +++ /dev/null @@ -1,54 +0,0 @@ -import conf -from sugar.chat.BuddyChat import BuddyChat -from sugar.activity import ActivityFactory -from sugar.presence import PresenceService -from sugar.p2p.Stream import Stream -from sugar.chat.Chat import Chat - -class ChatController: - def __init__(self, shell): - self._shell = shell - self._id_to_name = {} - self._name_to_chat = {} - - self._shell.connect('activity-closed', self.__activity_closed_cb) - - def __activity_closed_cb(self, shell, activity): - activity_id = activity.get_id() - if self._id_to_name.has_key(activity_id): - name = self._id_to_name[activity_id] - del self._name_to_chat[name] - del self._id_to_name[activity_id] - - def listen(self): - self._pservice = PresenceService.get_instance() - - self._pservice.register_service_type(BuddyChat.SERVICE_TYPE) - profile = conf.get_profile() - self._service = self._pservice.register_service(profile.get_nick_name(), - BuddyChat.SERVICE_TYPE) - - self._buddy_stream = Stream.new_from_service(self._service) - self._buddy_stream.set_data_listener(self._recv_message) - - def open_chat_activity(self, buddy): - service = buddy.get_service_of_type(BuddyChat.SERVICE_TYPE) - if service: - activity = self._shell.start_activity('com.redhat.Sugar.ChatActivity') - activity.execute('connect', [service.object_path()]) - self._name_to_chat[buddy.get_name()] = activity - self._id_to_name[activity.get_id()] = buddy.get_name() - - def _get_chat_activity(self, buddy): - nick = buddy.get_name() - if not self._name_to_chat.has_key(nick): - self.open_chat_activity(buddy) - return self._name_to_chat[nick] - - def _recv_message(self, address, message): - [nick, msg] = Chat.deserialize_message(message) - buddy = self._pservice.get_buddy_by_name(nick) - if buddy: - activity = self._get_chat_activity(buddy) - if activity: - activity.execute('message', [message]) diff --git a/shell/Makefile.am b/shell/Makefile.am index f48be4e9..80aad02b 100644 --- a/shell/Makefile.am +++ b/shell/Makefile.am @@ -11,7 +11,6 @@ sugardir = $(pkgdatadir)/shell sugar_PYTHON = \ __init__.py \ ActivityHost.py \ - ChatController.py \ ConsoleWindow.py \ FirstTimeDialog.py \ FriendIcon.py \ diff --git a/shell/Shell.py b/shell/Shell.py index 044d25d2..92baaa23 100755 --- a/shell/Shell.py +++ b/shell/Shell.py @@ -11,7 +11,6 @@ from home.HomeWindow import HomeWindow from Owner import ShellOwner from sugar.presence import PresenceService from ActivityHost import ActivityHost -from ChatController import ChatController from sugar.activity import ActivityFactory from sugar.activity import Activity from frame.Frame import Frame @@ -78,9 +77,6 @@ class Shell(gobject.GObject): self._home_window.set_owner(self._owner) - self._chat_controller = ChatController(self) - self._chat_controller.listen() - self._frame = Frame(self, self._owner) self._frame.show_and_hide(10) @@ -166,9 +162,6 @@ class Shell(gobject.GObject): activity.execute('test', []) return activity - def get_chat_controller(self): - return self._chat_controller - def set_zoom_level(self, level): if level == sugar.ZOOM_ACTIVITY: self._screen.toggle_showing_desktop(False) From 645aa93e50288547dda88c156795839178426df9 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 15 Sep 2006 12:40:22 +0200 Subject: [PATCH 15/27] Split shell in model/view, cleanup things a lot --- shell/ActivityHost.py | 3 + shell/FriendIcon.py | 8 +-- shell/Owner.py | 10 ---- shell/Session.py | 8 +-- shell/Shell.py | 116 ++++--------------------------------- shell/frame/BottomPanel.py | 18 +++--- shell/frame/Frame.py | 8 ++- shell/frame/RightPanel.py | 12 ++-- shell/frame/TopPanel.py | 3 +- shell/home/FriendsGroup.py | 10 ++-- shell/home/HomeGroup.py | 17 +++--- shell/home/HomeWindow.py | 13 ++--- shell/home/MeshGroup.py | 3 +- 13 files changed, 63 insertions(+), 166 deletions(-) diff --git a/shell/ActivityHost.py b/shell/ActivityHost.py index b3703e7a..456406bc 100644 --- a/shell/ActivityHost.py +++ b/shell/ActivityHost.py @@ -31,6 +31,9 @@ class ActivityHost: def get_id(self): return self._id + def get_xid(self): + return self._xid + def get_icon_name(self): return self._icon_name diff --git a/shell/FriendIcon.py b/shell/FriendIcon.py index 0c6b1e67..49eecfbb 100644 --- a/shell/FriendIcon.py +++ b/shell/FriendIcon.py @@ -14,11 +14,11 @@ class _PopupShell: class FriendIcon(IconItem): _popup_shell = _PopupShell() - def __init__(self, shell, friend): + def __init__(self, shell_model, friend): IconItem.__init__(self, icon_name='stock-buddy', color=friend.get_color(), size=96) - self._shell = shell + self._shell_model = shell_model self._friend = friend self._popup = None self._popup_distance = 0 @@ -83,10 +83,10 @@ class FriendIcon(IconItem): return if action == FriendPopup.ACTION_INVITE: - activity = self._shell.get_current_activity() + activity = self._shell_model.get_current_activity() activity.invite(buddy) elif action == FriendPopup.ACTION_MAKE_FRIEND: - friends = self._shell.get_owner().get_friends() + friends = self._shell_model.get_friends() friends.add_buddy(buddy) def _popdown_cb(self, friend): diff --git a/shell/Owner.py b/shell/Owner.py index b6590589..7dec04a7 100644 --- a/shell/Owner.py +++ b/shell/Owner.py @@ -6,8 +6,6 @@ import conf from sugar import env from sugar.p2p import Stream from sugar.presence import PresenceService -from Friends import Friends -from Invites import Invites PRESENCE_SERVICE_TYPE = "_presence_olpc._tcp" @@ -31,14 +29,6 @@ class ShellOwner(object): break self._pservice = PresenceService.get_instance() - self._friends = Friends() - self._invites = Invites() - - def get_friends(self): - return self._friends - - def get_invites(self): - return self._invites def announce(self): # Create and announce our presence diff --git a/shell/Session.py b/shell/Session.py index 07337d68..0bf3fa4f 100644 --- a/shell/Session.py +++ b/shell/Session.py @@ -2,6 +2,7 @@ import os import gtk from Shell import Shell +from ShellModel import ShellModel from ConsoleWindow import ConsoleWindow from sugar import env from sugar import logger @@ -47,11 +48,8 @@ class Session: dbm = DBusMonitorProcess() dbm.start() - console = ConsoleWindow() - logger.start('Shell', console) - - shell = Shell() - shell.set_console(console) + model = ShellModel() + shell = Shell(model) from sugar import TracebackUtils tbh = TracebackUtils.TracebackHelper() diff --git a/shell/Shell.py b/shell/Shell.py index 92baaa23..30a79576 100755 --- a/shell/Shell.py +++ b/shell/Shell.py @@ -1,51 +1,19 @@ -import os -import logging - -import dbus -import dbus.glib import gtk import gobject import wnck from home.HomeWindow import HomeWindow -from Owner import ShellOwner -from sugar.presence import PresenceService from ActivityHost import ActivityHost -from sugar.activity import ActivityFactory -from sugar.activity import Activity from frame.Frame import Frame from globalkeys import KeyGrabber -import conf import sugar -class ShellDbusService(dbus.service.Object): - def __init__(self, shell, bus_name): - dbus.service.Object.__init__(self, bus_name, '/com/redhat/Sugar/Shell') - self._shell = shell - - def __show_console_idle(self): - self._shell.show_console() - - @dbus.service.method('com.redhat.Sugar.Shell') - def show_console(self): - gobject.idle_add(self.__show_console_idle) - 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): + def __init__(self, model): gobject.GObject.__init__(self) + self._model = model self._screen = wnck.screen_get_default() - self._hosts = {} - self._current_window = None self._key_grabber = KeyGrabber() self._key_grabber.connect('key-pressed', self.__global_key_pressed_cb) @@ -56,7 +24,7 @@ class Shell(gobject.GObject): self._key_grabber.grab('F5') self._key_grabber.grab('F6') - self._home_window = HomeWindow(self) + self._home_window = HomeWindow(self.get_model()) self._home_window.show() self.set_zoom_level(sugar.ZOOM_HOME) @@ -65,24 +33,9 @@ class Shell(gobject.GObject): self._screen.connect('active-window-changed', self.__active_window_changed_cb) - session_bus = dbus.SessionBus() - bus_name = dbus.service.BusName('com.redhat.Sugar.Shell', bus=session_bus) - ShellDbusService(self, bus_name) - - PresenceService.start() - self._pservice = PresenceService.get_instance() - - self._owner = ShellOwner() - self._owner.announce() - - self._home_window.set_owner(self._owner) - - self._frame = Frame(self, self._owner) + self._frame = Frame(self) self._frame.show_and_hide(10) - def get_owner(self): - return self._owner - def __global_key_pressed_cb(self, grabber, key): if key == 'F1': self.set_zoom_level(sugar.ZOOM_ACTIVITY) @@ -95,72 +48,23 @@ class Shell(gobject.GObject): elif key == 'F5': self._frame.toggle_visibility() elif key == 'F6': - ActivityFactory.create('org.sugar.Terminal') - - def set_console(self, console): - self._console = console + self._model.start_activity('org.sugar.Terminal') def __window_opened_cb(self, screen, window): if window.get_window_type() == wnck.WINDOW_NORMAL: - host = ActivityHost(self, window) - self._hosts[window.get_xid()] = host - self.emit('activity-opened', host) + self._model.add_activity(ActivityHost(self, window)) def __active_window_changed_cb(self, screen): window = screen.get_active_window() if window and window.get_window_type() == wnck.WINDOW_NORMAL: - if self._current_window != window: - self._current_window = window - self.emit('activity-changed', self.get_current_activity()) + self._model.set_current_activity(window.get_xid()) def __window_closed_cb(self, screen, window): if window.get_window_type() == wnck.WINDOW_NORMAL: - xid = window.get_xid() - if self._hosts.has_key(xid): - host = self._hosts[xid] - self.emit('activity-closed', host) + self._model.remove_activity(window.get_xid()) - del self._hosts[xid] - - def get_activity(self, activity_id): - for host in self._hosts.values(): - if host.get_id() == activity_id: - return host - return None - - def get_current_activity(self): - if self._current_window != None: - xid = self._current_window.get_xid() - return self._hosts[xid] - else: - return None - - def show_console(self): - self._console.show() - - activity = self.get_current_activity() - if activity: - registry = conf.get_activity_registry() - module = registry.get_activity(activity.get_type()) - self._console.set_page(module.get_id()) - - def join_activity(self, bundle_id, activity_id): - activity = self.get_activity(activity_id) - if activity: - activity.present() - else: - activity_ps = self._pservice.get_activity(activity_id) - - if activity_ps: - activity = ActivityFactory.create(bundle_id) - activity.join(activity_ps.object_path()) - else: - logging.error('Cannot start activity.') - - def start_activity(self, activity_type): - activity = ActivityFactory.create(activity_type) - activity.execute('test', []) - return activity + def get_model(self): + return self._model def set_zoom_level(self, level): if level == sugar.ZOOM_ACTIVITY: diff --git a/shell/frame/BottomPanel.py b/shell/frame/BottomPanel.py index 2da51e77..d43160db 100644 --- a/shell/frame/BottomPanel.py +++ b/shell/frame/BottomPanel.py @@ -33,30 +33,30 @@ class InviteItem(IconItem): return self._invite class BottomPanel(CanvasBox): - def __init__(self, grid, shell, invites): + def __init__(self, grid, shell_model): CanvasBox.__init__(self, grid, CanvasBox.HORIZONTAL, 1) - self._shell = shell + self._shell_model = shell_model self._invite_to_item = {} - self._invites = invites + self._invites = shell_model.get_invites() registry = conf.get_activity_registry() for activity in registry.list_activities(): if activity.get_show_launcher(): self.add_activity(activity) - for invite in invites: + for invite in self._invites: self.add_invite(invite) - invites.connect('invite-added', self.__invite_added_cb) - invites.connect('invite-removed', self.__invite_removed_cb) + self._invites.connect('invite-added', self.__invite_added_cb) + self._invites.connect('invite-removed', self.__invite_removed_cb) def __activity_clicked_cb(self, icon): - self._shell.start_activity(icon.get_bundle_id()) + self._shell_model.start_activity(icon.get_bundle_id()) def __invite_clicked_cb(self, icon): self._invites.remove_invite(icon.get_invite()) - self._shell.join_activity(icon.get_bundle_id(), - icon.get_activity_id()) + self._shell_model.join_activity(icon.get_bundle_id(), + icon.get_activity_id()) def __invite_added_cb(self, invites, invite): self.add_invite(invite) diff --git a/shell/frame/Frame.py b/shell/frame/Frame.py index 1da50f0e..826295f1 100644 --- a/shell/frame/Frame.py +++ b/shell/frame/Frame.py @@ -9,9 +9,11 @@ from frame.PanelWindow import PanelWindow from sugar.canvas.Grid import Grid class Frame: - def __init__(self, shell, owner): + def __init__(self, shell): self._windows = [] + shell_model = shell.get_model() + model = goocanvas.CanvasModelSimple() root = model.get_root_item() @@ -21,7 +23,7 @@ class Frame: grid.set_constraints(bg, 0, 0, 80, 60) root.add_child(bg) - panel = BottomPanel(grid, shell, owner.get_invites()) + panel = BottomPanel(grid, shell_model) grid.set_constraints(panel, 5, 55) root.add_child(panel) @@ -34,7 +36,7 @@ class Frame: panel_window = PanelWindow(grid, model, 0, 0, 80, 5) self._windows.append(panel_window) - panel = RightPanel(grid, shell, owner.get_friends()) + panel = RightPanel(grid, shell_model) grid.set_constraints(panel, 75, 5) root.add_child(panel) diff --git a/shell/frame/RightPanel.py b/shell/frame/RightPanel.py index be55abf2..1bc27f5c 100644 --- a/shell/frame/RightPanel.py +++ b/shell/frame/RightPanel.py @@ -8,10 +8,10 @@ from FriendIcon import FriendIcon from Friends import Friend class RightPanel(CanvasBox): - def __init__(self, grid, shell, friends): + def __init__(self, grid, shell_model): CanvasBox.__init__(self, grid, CanvasBox.VERTICAL, 1) - self._shell = shell - self._friends = friends + self._shell_model = shell_model + self._friends = shell_model.get_friends() self._activity_ps = None self._joined_hid = -1 self._left_hid = -1 @@ -21,11 +21,11 @@ class RightPanel(CanvasBox): self._pservice.connect('activity-appeared', self.__activity_appeared_cb) - shell.connect('activity-changed', self.__activity_changed_cb) + shell_model.connect('activity-changed', self.__activity_changed_cb) def add(self, buddy): friend = Friend(buddy.get_name(), buddy.get_color()) - icon = FriendIcon(self._shell, friend) + icon = FriendIcon(self._shell_model, friend) icon.set_popup_distance(1) self.set_constraints(icon, 3, 3) self.add_child(icon) @@ -42,7 +42,7 @@ class RightPanel(CanvasBox): self._buddies = {} def __activity_appeared_cb(self, pservice, activity_ps): - activity = self._shell.get_current_activity() + activity = self._shell_model.get_current_activity() if activity and activity_ps.get_id() == activity.get_id(): self._set_activity_ps(activity_ps) diff --git a/shell/frame/TopPanel.py b/shell/frame/TopPanel.py index 14c0fb7c..1409d854 100644 --- a/shell/frame/TopPanel.py +++ b/shell/frame/TopPanel.py @@ -58,7 +58,8 @@ class TopPanel(goocanvas.Group): self._shell.set_zoom_level(level) def __share_clicked_cb(self, item): - activity = self._shell.get_current_activity() + shell_model = self._shell.get_model() + activity = shell_model.get_current_activity() if activity != None: activity.share() diff --git a/shell/home/FriendsGroup.py b/shell/home/FriendsGroup.py index ed87015b..adb3de8d 100644 --- a/shell/home/FriendsGroup.py +++ b/shell/home/FriendsGroup.py @@ -7,12 +7,12 @@ from home.MyIcon import MyIcon from FriendIcon import FriendIcon class FriendsGroup(goocanvas.Group): - def __init__(self, shell, friends): + def __init__(self, shell_model): goocanvas.Group.__init__(self) - self._shell = shell + self._shell_model = shell_model self._icon_layout = IconLayout(1200, 900) - self._friends = friends + self._friends = shell_model.get_friends() me = MyIcon(100) me.translate(600 - (me.get_property('size') / 2), @@ -22,10 +22,10 @@ class FriendsGroup(goocanvas.Group): for friend in self._friends: self.add_friend(friend) - friends.connect('friend-added', self._friend_added_cb) + self._friends.connect('friend-added', self._friend_added_cb) def add_friend(self, friend): - icon = FriendIcon(self._shell, friend) + icon = FriendIcon(self._shell_model, friend) self.add_child(icon) self._icon_layout.add_icon(icon) diff --git a/shell/home/HomeGroup.py b/shell/home/HomeGroup.py index 0f088132..3834bda6 100644 --- a/shell/home/HomeGroup.py +++ b/shell/home/HomeGroup.py @@ -4,19 +4,19 @@ from home.DonutItem import DonutItem from home.MyIcon import MyIcon class TasksItem(DonutItem): - def __init__(self, shell): + def __init__(self, shell_model): DonutItem.__init__(self, 250) self._items = {} - self._shell = shell - self._shell.connect('activity_opened', self.__activity_opened_cb) - self._shell.connect('activity_closed', self.__activity_closed_cb) + self._shell_model = shell_model + self._shell_model.connect('activity_opened', self.__activity_opened_cb) + self._shell_model.connect('activity_closed', self.__activity_closed_cb) - def __activity_opened_cb(self, shell, activity): + def __activity_opened_cb(self, model, activity): self._add(activity) - def __activity_closed_cb(self, shell, activity): + def __activity_closed_cb(self, model, activity): self._remove(activity) def _remove(self, activity): @@ -27,6 +27,7 @@ class TasksItem(DonutItem): def _add(self, activity): icon_name = activity.get_icon_name() icon_color = activity.get_icon_color() + print 'Add activity %s' % icon_color.to_string() item = self.add_piece(100 / 8, icon_name, icon_color) item.get_icon().connect('clicked', @@ -39,10 +40,10 @@ class TasksItem(DonutItem): activity.present() class HomeGroup(goocanvas.Group): - def __init__(self, shell): + def __init__(self, shell_model): goocanvas.Group.__init__(self) - tasks = TasksItem(shell) + tasks = TasksItem(shell_model) tasks.translate(600, 450) self.add_child(tasks) diff --git a/shell/home/HomeWindow.py b/shell/home/HomeWindow.py index 259ddc4f..3c895fab 100644 --- a/shell/home/HomeWindow.py +++ b/shell/home/HomeWindow.py @@ -9,9 +9,9 @@ from home.FriendsGroup import FriendsGroup import sugar class HomeWindow(gtk.Window): - def __init__(self, shell): + def __init__(self, shell_model): gtk.Window.__init__(self) - self._shell = shell + self._shell_model = shell_model self.realize() self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DESKTOP) @@ -23,6 +23,10 @@ class HomeWindow(gtk.Window): self.add(self._nb) self._nb.show() + self._add_page(HomeGroup(shell_model)) + self._add_page(FriendsGroup(shell_model)) + self._add_page(MeshGroup()) + def _add_page(self, group): view = CanvasView() self._nb.append_page(view) @@ -37,11 +41,6 @@ class HomeWindow(gtk.Window): root.add_child(bg) root.add_child(group) - def set_owner(self, owner): - self._add_page(HomeGroup(self._shell)) - self._add_page(FriendsGroup(self._shell, owner.get_friends())) - self._add_page(MeshGroup(self._shell)) - def set_zoom_level(self, level): if level == sugar.ZOOM_HOME: self._nb.set_current_page(0) diff --git a/shell/home/MeshGroup.py b/shell/home/MeshGroup.py index f7bc1c99..3247b734 100644 --- a/shell/home/MeshGroup.py +++ b/shell/home/MeshGroup.py @@ -32,9 +32,8 @@ class ActivityItem(IconItem): return self._service class MeshGroup(goocanvas.Group): - def __init__(self, shell): + def __init__(self): goocanvas.Group.__init__(self) - self._shell = shell self._icon_layout = IconLayout(1200, 900) self._activities = {} From 14383f4fc7c6e182fc8a79e5f9d56c740b2bc7e7 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 15 Sep 2006 12:40:46 +0200 Subject: [PATCH 16/27] Forgot to add the model --- shell/ShellModel.py | 86 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 shell/ShellModel.py diff --git a/shell/ShellModel.py b/shell/ShellModel.py new file mode 100644 index 00000000..c0c8bccf --- /dev/null +++ b/shell/ShellModel.py @@ -0,0 +1,86 @@ +import gobject + +from Owner import ShellOwner +from sugar.presence import PresenceService +from sugar.activity import ActivityFactory +from sugar.activity import Activity +from Friends import Friends +from Invites import Invites + +class ShellModel(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): + gobject.GObject.__init__(self) + + self._hosts = {} + self._current_activity = None + + PresenceService.start() + self._pservice = PresenceService.get_instance() + + self._owner = ShellOwner() + self._owner.announce() + self._friends = Friends() + self._invites = Invites() + + def get_friends(self): + return self._friends + + def get_invites(self): + return self._invites + + def get_owner(self): + return self._owner + + def add_activity(self, activity_host): + self._hosts[activity_host.get_xid()] = activity_host + self.emit('activity-opened', activity_host) + + def set_current_activity(self, activity_xid): + activity_host = self._hosts[activity_xid] + if self._current_activity == activity_host: + return + + self._current_activity = activity_host + self.emit('activity-changed', activity_host) + + def remove_activity(self, activity_xid): + if self._hosts.has_key(activity_xid): + host = self._hosts[activity_xid] + self.emit('activity-closed', host) + del self._hosts[activity_xid] + + def get_activity(self, activity_id): + for host in self._hosts.values(): + if host.get_id() == activity_id: + return host + return None + + def get_current_activity(self): + return self._current_activity + + def join_activity(self, bundle_id, activity_id): + activity = self.get_activity(activity_id) + if activity: + activity.present() + else: + activity_ps = self._pservice.get_activity(activity_id) + + if activity_ps: + activity = ActivityFactory.create(bundle_id) + activity.join(activity_ps.object_path()) + else: + logging.error('Cannot start activity.') + + def start_activity(self, activity_type): + activity = ActivityFactory.create(activity_type) + activity.execute('test', []) + return activity From ca19f0f25100006c0f6c84e405e2e6a0cecdd15b Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 15 Sep 2006 12:52:37 +0200 Subject: [PATCH 17/27] Move the model to his own module --- configure.ac | 1 + shell/Makefile.am | 5 +---- shell/Session.py | 2 +- shell/Shell.py | 0 shell/frame/RightPanel.py | 2 +- shell/home/HomeGroup.py | 1 - shell/{ => model}/Friends.py | 0 shell/{ => model}/Invites.py | 0 shell/model/Makefile.am | 7 +++++++ shell/{ => model}/Owner.py | 0 shell/{ => model}/ShellModel.py | 6 +++--- shell/model/__init__.py | 0 12 files changed, 14 insertions(+), 10 deletions(-) mode change 100755 => 100644 shell/Shell.py rename shell/{ => model}/Friends.py (100%) rename shell/{ => model}/Invites.py (100%) create mode 100644 shell/model/Makefile.am rename shell/{ => model}/Owner.py (100%) rename shell/{ => model}/ShellModel.py (95%) create mode 100644 shell/model/__init__.py diff --git a/configure.ac b/configure.ac index 842a1133..dfebdf2e 100644 --- a/configure.ac +++ b/configure.ac @@ -50,6 +50,7 @@ shell/conf/Makefile shell/data/Makefile shell/home/Makefile shell/frame/Makefile +shell/model/Makefile shell/PresenceService/Makefile sugar/Makefile sugar/__installed__.py diff --git a/shell/Makefile.am b/shell/Makefile.am index 80aad02b..69dbe870 100644 --- a/shell/Makefile.am +++ b/shell/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = conf data frame home PresenceService +SUBDIRS = conf data frame home model PresenceService bin_SCRIPTS = \ sugar \ @@ -15,9 +15,6 @@ sugar_PYTHON = \ FirstTimeDialog.py \ FriendIcon.py \ FriendPopup.py \ - Friends.py \ - Invites.py \ - Owner.py \ Shell.py \ Session.py diff --git a/shell/Session.py b/shell/Session.py index 0bf3fa4f..bbd1c73a 100644 --- a/shell/Session.py +++ b/shell/Session.py @@ -2,7 +2,7 @@ import os import gtk from Shell import Shell -from ShellModel import ShellModel +from model.ShellModel import ShellModel from ConsoleWindow import ConsoleWindow from sugar import env from sugar import logger diff --git a/shell/Shell.py b/shell/Shell.py old mode 100755 new mode 100644 diff --git a/shell/frame/RightPanel.py b/shell/frame/RightPanel.py index 1bc27f5c..c60cc46c 100644 --- a/shell/frame/RightPanel.py +++ b/shell/frame/RightPanel.py @@ -5,7 +5,7 @@ from sugar.canvas.IconColor import IconColor from sugar.canvas.CanvasBox import CanvasBox from sugar.presence import PresenceService from FriendIcon import FriendIcon -from Friends import Friend +from model.Friends import Friend class RightPanel(CanvasBox): def __init__(self, grid, shell_model): diff --git a/shell/home/HomeGroup.py b/shell/home/HomeGroup.py index 3834bda6..90fc079c 100644 --- a/shell/home/HomeGroup.py +++ b/shell/home/HomeGroup.py @@ -27,7 +27,6 @@ class TasksItem(DonutItem): def _add(self, activity): icon_name = activity.get_icon_name() icon_color = activity.get_icon_color() - print 'Add activity %s' % icon_color.to_string() item = self.add_piece(100 / 8, icon_name, icon_color) item.get_icon().connect('clicked', diff --git a/shell/Friends.py b/shell/model/Friends.py similarity index 100% rename from shell/Friends.py rename to shell/model/Friends.py diff --git a/shell/Invites.py b/shell/model/Invites.py similarity index 100% rename from shell/Invites.py rename to shell/model/Invites.py diff --git a/shell/model/Makefile.am b/shell/model/Makefile.am new file mode 100644 index 00000000..2ce494ba --- /dev/null +++ b/shell/model/Makefile.am @@ -0,0 +1,7 @@ +sugardir = $(pkgdatadir)/shell/model +sugar_PYTHON = \ + __init__.py \ + Friends.py \ + Invites.py \ + Owner.py \ + ShellModel.py diff --git a/shell/Owner.py b/shell/model/Owner.py similarity index 100% rename from shell/Owner.py rename to shell/model/Owner.py diff --git a/shell/ShellModel.py b/shell/model/ShellModel.py similarity index 95% rename from shell/ShellModel.py rename to shell/model/ShellModel.py index c0c8bccf..2f9dd255 100644 --- a/shell/ShellModel.py +++ b/shell/model/ShellModel.py @@ -1,11 +1,11 @@ import gobject -from Owner import ShellOwner from sugar.presence import PresenceService from sugar.activity import ActivityFactory from sugar.activity import Activity -from Friends import Friends -from Invites import Invites +from model.Friends import Friends +from model.Invites import Invites +from model.Owner import ShellOwner class ShellModel(gobject.GObject): __gsignals__ = { diff --git a/shell/model/__init__.py b/shell/model/__init__.py new file mode 100644 index 00000000..e69de29b From bcc1740f7f514f04629cecb7536c93d4feaf83cf Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 15 Sep 2006 13:23:21 +0200 Subject: [PATCH 18/27] Move the view to his own module --- configure.ac | 5 +++-- shell/Makefile.am | 8 +------- shell/Session.py | 5 ++--- shell/{ => view}/ActivityHost.py | 0 shell/{ => view}/ConsoleWindow.py | 0 shell/{ => view}/FirstTimeDialog.py | 0 shell/{ => view}/FriendIcon.py | 2 +- shell/{ => view}/FriendPopup.py | 0 shell/view/Makefile.am | 11 +++++++++++ shell/{ => view}/Shell.py | 6 +++--- shell/{frame => view}/__init__.py | 0 shell/{ => view}/frame/BottomPanel.py | 0 shell/{ => view}/frame/Frame.py | 8 ++++---- shell/{ => view}/frame/Makefile.am | 2 +- shell/{ => view}/frame/PanelWindow.py | 0 shell/{ => view}/frame/RightPanel.py | 2 +- shell/{ => view}/frame/TopPanel.py | 0 shell/{home => view/frame}/__init__.py | 0 shell/{ => view}/home/DonutItem.py | 0 shell/{ => view}/home/FriendsGroup.py | 6 +++--- shell/{ => view}/home/HomeGroup.py | 4 ++-- shell/{ => view}/home/HomeWindow.py | 6 +++--- shell/{ => view}/home/IconLayout.py | 0 shell/{ => view}/home/Makefile.am | 2 +- shell/{ => view}/home/MeshGroup.py | 2 +- shell/{ => view}/home/MyIcon.py | 0 shell/view/home/__init__.py | 0 27 files changed, 37 insertions(+), 32 deletions(-) rename shell/{ => view}/ActivityHost.py (100%) rename shell/{ => view}/ConsoleWindow.py (100%) rename shell/{ => view}/FirstTimeDialog.py (100%) rename shell/{ => view}/FriendIcon.py (98%) rename shell/{ => view}/FriendPopup.py (100%) create mode 100644 shell/view/Makefile.am rename shell/{ => view}/Shell.py (94%) rename shell/{frame => view}/__init__.py (100%) rename shell/{ => view}/frame/BottomPanel.py (100%) rename shell/{ => view}/frame/Frame.py (88%) rename shell/{ => view}/frame/Makefile.am (74%) rename shell/{ => view}/frame/PanelWindow.py (100%) rename shell/{ => view}/frame/RightPanel.py (98%) rename shell/{ => view}/frame/TopPanel.py (100%) rename shell/{home => view/frame}/__init__.py (100%) rename shell/{ => view}/home/DonutItem.py (100%) rename shell/{ => view}/home/FriendsGroup.py (86%) rename shell/{ => view}/home/HomeGroup.py (94%) rename shell/{ => view}/home/HomeWindow.py (89%) rename shell/{ => view}/home/IconLayout.py (100%) rename shell/{ => view}/home/Makefile.am (79%) rename shell/{ => view}/home/MeshGroup.py (98%) rename shell/{ => view}/home/MyIcon.py (100%) create mode 100644 shell/view/home/__init__.py diff --git a/configure.ac b/configure.ac index dfebdf2e..52214ddb 100644 --- a/configure.ac +++ b/configure.ac @@ -48,8 +48,9 @@ bindings/threadframe/Makefile shell/Makefile shell/conf/Makefile shell/data/Makefile -shell/home/Makefile -shell/frame/Makefile +shell/view/Makefile +shell/view/home/Makefile +shell/view/frame/Makefile shell/model/Makefile shell/PresenceService/Makefile sugar/Makefile diff --git a/shell/Makefile.am b/shell/Makefile.am index 69dbe870..1bf373dc 100644 --- a/shell/Makefile.am +++ b/shell/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = conf data frame home model PresenceService +SUBDIRS = conf data model view PresenceService bin_SCRIPTS = \ sugar \ @@ -10,12 +10,6 @@ bin_SCRIPTS = \ sugardir = $(pkgdatadir)/shell sugar_PYTHON = \ __init__.py \ - ActivityHost.py \ - ConsoleWindow.py \ - FirstTimeDialog.py \ - FriendIcon.py \ - FriendPopup.py \ - Shell.py \ Session.py EXTRA_DIST = $(bin_SCRIPTS) diff --git a/shell/Session.py b/shell/Session.py index bbd1c73a..da17cd71 100644 --- a/shell/Session.py +++ b/shell/Session.py @@ -1,9 +1,8 @@ import os import gtk -from Shell import Shell +from view.Shell import Shell from model.ShellModel import ShellModel -from ConsoleWindow import ConsoleWindow from sugar import env from sugar import logger @@ -11,7 +10,7 @@ from sugar.session.Process import Process from sugar.session.DbusProcess import DbusProcess from sugar.session.MatchboxProcess import MatchboxProcess -from FirstTimeDialog import FirstTimeDialog +from view.FirstTimeDialog import FirstTimeDialog import conf class DBusMonitorProcess(Process): diff --git a/shell/ActivityHost.py b/shell/view/ActivityHost.py similarity index 100% rename from shell/ActivityHost.py rename to shell/view/ActivityHost.py diff --git a/shell/ConsoleWindow.py b/shell/view/ConsoleWindow.py similarity index 100% rename from shell/ConsoleWindow.py rename to shell/view/ConsoleWindow.py diff --git a/shell/FirstTimeDialog.py b/shell/view/FirstTimeDialog.py similarity index 100% rename from shell/FirstTimeDialog.py rename to shell/view/FirstTimeDialog.py diff --git a/shell/FriendIcon.py b/shell/view/FriendIcon.py similarity index 98% rename from shell/FriendIcon.py rename to shell/view/FriendIcon.py index 49eecfbb..e5158e2b 100644 --- a/shell/FriendIcon.py +++ b/shell/view/FriendIcon.py @@ -1,6 +1,6 @@ from sugar.canvas.IconItem import IconItem -from FriendPopup import FriendPopup from sugar.canvas.Grid import Grid +from view.FriendPopup import FriendPopup class _PopupShell: def __init__(self): diff --git a/shell/FriendPopup.py b/shell/view/FriendPopup.py similarity index 100% rename from shell/FriendPopup.py rename to shell/view/FriendPopup.py diff --git a/shell/view/Makefile.am b/shell/view/Makefile.am new file mode 100644 index 00000000..7481dbe5 --- /dev/null +++ b/shell/view/Makefile.am @@ -0,0 +1,11 @@ +SUBDIRS = frame home + +sugardir = $(pkgdatadir)/shell/view +sugar_PYTHON = \ + __init__.py \ + ActivityHost.py \ + ConsoleWindow.py \ + FirstTimeDialog.py \ + FriendIcon.py \ + FriendPopup.py \ + Shell.py diff --git a/shell/Shell.py b/shell/view/Shell.py similarity index 94% rename from shell/Shell.py rename to shell/view/Shell.py index 30a79576..7e1050e0 100644 --- a/shell/Shell.py +++ b/shell/view/Shell.py @@ -2,9 +2,9 @@ import gtk import gobject import wnck -from home.HomeWindow import HomeWindow -from ActivityHost import ActivityHost -from frame.Frame import Frame +from view.home.HomeWindow import HomeWindow +from view.ActivityHost import ActivityHost +from view.frame.Frame import Frame from globalkeys import KeyGrabber import sugar diff --git a/shell/frame/__init__.py b/shell/view/__init__.py similarity index 100% rename from shell/frame/__init__.py rename to shell/view/__init__.py diff --git a/shell/frame/BottomPanel.py b/shell/view/frame/BottomPanel.py similarity index 100% rename from shell/frame/BottomPanel.py rename to shell/view/frame/BottomPanel.py diff --git a/shell/frame/Frame.py b/shell/view/frame/Frame.py similarity index 88% rename from shell/frame/Frame.py rename to shell/view/frame/Frame.py index 826295f1..5ebecccb 100644 --- a/shell/frame/Frame.py +++ b/shell/view/frame/Frame.py @@ -2,10 +2,10 @@ import gtk import gobject import goocanvas -from frame.BottomPanel import BottomPanel -from frame.RightPanel import RightPanel -from frame.TopPanel import TopPanel -from frame.PanelWindow import PanelWindow +from view.frame.BottomPanel import BottomPanel +from view.frame.RightPanel import RightPanel +from view.frame.TopPanel import TopPanel +from view.frame.PanelWindow import PanelWindow from sugar.canvas.Grid import Grid class Frame: diff --git a/shell/frame/Makefile.am b/shell/view/frame/Makefile.am similarity index 74% rename from shell/frame/Makefile.am rename to shell/view/frame/Makefile.am index 9f455439..a737e018 100644 --- a/shell/frame/Makefile.am +++ b/shell/view/frame/Makefile.am @@ -1,4 +1,4 @@ -sugardir = $(pkgdatadir)/shell/frame +sugardir = $(pkgdatadir)/shell/view/frame sugar_PYTHON = \ __init__.py \ RightPanel.py \ diff --git a/shell/frame/PanelWindow.py b/shell/view/frame/PanelWindow.py similarity index 100% rename from shell/frame/PanelWindow.py rename to shell/view/frame/PanelWindow.py diff --git a/shell/frame/RightPanel.py b/shell/view/frame/RightPanel.py similarity index 98% rename from shell/frame/RightPanel.py rename to shell/view/frame/RightPanel.py index c60cc46c..f12ccf5f 100644 --- a/shell/frame/RightPanel.py +++ b/shell/view/frame/RightPanel.py @@ -4,7 +4,7 @@ from sugar.canvas.IconItem import IconItem from sugar.canvas.IconColor import IconColor from sugar.canvas.CanvasBox import CanvasBox from sugar.presence import PresenceService -from FriendIcon import FriendIcon +from view.FriendIcon import FriendIcon from model.Friends import Friend class RightPanel(CanvasBox): diff --git a/shell/frame/TopPanel.py b/shell/view/frame/TopPanel.py similarity index 100% rename from shell/frame/TopPanel.py rename to shell/view/frame/TopPanel.py diff --git a/shell/home/__init__.py b/shell/view/frame/__init__.py similarity index 100% rename from shell/home/__init__.py rename to shell/view/frame/__init__.py diff --git a/shell/home/DonutItem.py b/shell/view/home/DonutItem.py similarity index 100% rename from shell/home/DonutItem.py rename to shell/view/home/DonutItem.py diff --git a/shell/home/FriendsGroup.py b/shell/view/home/FriendsGroup.py similarity index 86% rename from shell/home/FriendsGroup.py rename to shell/view/home/FriendsGroup.py index adb3de8d..1e2fb8f2 100644 --- a/shell/home/FriendsGroup.py +++ b/shell/view/home/FriendsGroup.py @@ -2,9 +2,9 @@ import random import goocanvas -from home.IconLayout import IconLayout -from home.MyIcon import MyIcon -from FriendIcon import FriendIcon +from view.home.IconLayout import IconLayout +from view.home.MyIcon import MyIcon +from view.FriendIcon import FriendIcon class FriendsGroup(goocanvas.Group): def __init__(self, shell_model): diff --git a/shell/home/HomeGroup.py b/shell/view/home/HomeGroup.py similarity index 94% rename from shell/home/HomeGroup.py rename to shell/view/home/HomeGroup.py index 90fc079c..e6376cde 100644 --- a/shell/home/HomeGroup.py +++ b/shell/view/home/HomeGroup.py @@ -1,7 +1,7 @@ import goocanvas -from home.DonutItem import DonutItem -from home.MyIcon import MyIcon +from view.home.DonutItem import DonutItem +from view.home.MyIcon import MyIcon class TasksItem(DonutItem): def __init__(self, shell_model): diff --git a/shell/home/HomeWindow.py b/shell/view/home/HomeWindow.py similarity index 89% rename from shell/home/HomeWindow.py rename to shell/view/home/HomeWindow.py index 3c895fab..b89420f0 100644 --- a/shell/home/HomeWindow.py +++ b/shell/view/home/HomeWindow.py @@ -3,9 +3,9 @@ import goocanvas import cairo from sugar.canvas.CanvasView import CanvasView -from home.MeshGroup import MeshGroup -from home.HomeGroup import HomeGroup -from home.FriendsGroup import FriendsGroup +from view.home.MeshGroup import MeshGroup +from view.home.HomeGroup import HomeGroup +from view.home.FriendsGroup import FriendsGroup import sugar class HomeWindow(gtk.Window): diff --git a/shell/home/IconLayout.py b/shell/view/home/IconLayout.py similarity index 100% rename from shell/home/IconLayout.py rename to shell/view/home/IconLayout.py diff --git a/shell/home/Makefile.am b/shell/view/home/Makefile.am similarity index 79% rename from shell/home/Makefile.am rename to shell/view/home/Makefile.am index 5d5436e3..ddf9653a 100644 --- a/shell/home/Makefile.am +++ b/shell/view/home/Makefile.am @@ -1,4 +1,4 @@ -sugardir = $(pkgdatadir)/shell/home +sugardir = $(pkgdatadir)/shell/view/home sugar_PYTHON = \ __init__.py \ DonutItem.py \ diff --git a/shell/home/MeshGroup.py b/shell/view/home/MeshGroup.py similarity index 98% rename from shell/home/MeshGroup.py rename to shell/view/home/MeshGroup.py index 3247b734..90dce0e0 100644 --- a/shell/home/MeshGroup.py +++ b/shell/view/home/MeshGroup.py @@ -6,7 +6,7 @@ import conf from sugar.canvas.IconItem import IconItem from sugar.canvas.IconItem import IconColor from sugar.presence import PresenceService -from home.IconLayout import IconLayout +from view.home.IconLayout import IconLayout class ActivityItem(IconItem): def __init__(self, activity, service): diff --git a/shell/home/MyIcon.py b/shell/view/home/MyIcon.py similarity index 100% rename from shell/home/MyIcon.py rename to shell/view/home/MyIcon.py diff --git a/shell/view/home/__init__.py b/shell/view/home/__init__.py new file mode 100644 index 00000000..e69de29b From 5f99dcf9a5375847c970cfd769b3c85b84cf66b0 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 15 Sep 2006 13:54:16 +0200 Subject: [PATCH 19/27] Move the presence service out of the shell --- .gitignore | 2 +- Makefile.am | 2 +- configure.ac | 2 +- services/Makefile.am | 1 + {shell/PresenceService => services/presence}/Activity.py | 0 {shell/PresenceService => services/presence}/Buddy.py | 0 {shell/PresenceService => services/presence}/Makefile.am | 6 ++++-- .../presence}/PresenceService.py | 0 {shell/PresenceService => services/presence}/Service.py | 0 {shell/PresenceService => services/presence}/__init__.py | 0 .../presence}/org.laptop.Presence.service.in | 0 {shell => services/presence}/sugar-presence-service | 2 +- shell/Makefile.am | 5 ++--- sugar/__installed__.py.in | 3 ++- sugar/__uninstalled__.py.in | 2 ++ sugar/env.py | 3 ++- 16 files changed, 17 insertions(+), 11 deletions(-) create mode 100644 services/Makefile.am rename {shell/PresenceService => services/presence}/Activity.py (100%) rename {shell/PresenceService => services/presence}/Buddy.py (100%) rename {shell/PresenceService => services/presence}/Makefile.am (74%) rename {shell/PresenceService => services/presence}/PresenceService.py (100%) rename {shell/PresenceService => services/presence}/Service.py (100%) rename {shell/PresenceService => services/presence}/__init__.py (100%) rename {shell/PresenceService => services/presence}/org.laptop.Presence.service.in (100%) rename {shell => services/presence}/sugar-presence-service (78%) diff --git a/.gitignore b/.gitignore index d0ca2394..ffd6362b 100644 --- a/.gitignore +++ b/.gitignore @@ -38,7 +38,7 @@ po/*.gmo sugar/__installed__.py sugar/__uninstalled__.py tools/sugar-setup-activity -shell/PresenceService/org.laptop.Presence.service +services/presence/org.laptop.Presence.service threadframe config.guess config.sub diff --git a/Makefile.am b/Makefile.am index 72ff820f..323f1f43 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = activities bindings po shell sugar tools +SUBDIRS = activities bindings po shell sugar services tools ACLOCAL_AMFLAGS = -I m4 diff --git a/configure.ac b/configure.ac index 52214ddb..7d50fb28 100644 --- a/configure.ac +++ b/configure.ac @@ -45,6 +45,7 @@ activities/terminal/Makefile bindings/Makefile bindings/globalkeys/Makefile bindings/threadframe/Makefile +services/Makefile shell/Makefile shell/conf/Makefile shell/data/Makefile @@ -52,7 +53,6 @@ shell/view/Makefile shell/view/home/Makefile shell/view/frame/Makefile shell/model/Makefile -shell/PresenceService/Makefile sugar/Makefile sugar/__installed__.py sugar/__uninstalled__.py diff --git a/services/Makefile.am b/services/Makefile.am new file mode 100644 index 00000000..da404414 --- /dev/null +++ b/services/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = presence diff --git a/shell/PresenceService/Activity.py b/services/presence/Activity.py similarity index 100% rename from shell/PresenceService/Activity.py rename to services/presence/Activity.py diff --git a/shell/PresenceService/Buddy.py b/services/presence/Buddy.py similarity index 100% rename from shell/PresenceService/Buddy.py rename to services/presence/Buddy.py diff --git a/shell/PresenceService/Makefile.am b/services/presence/Makefile.am similarity index 74% rename from shell/PresenceService/Makefile.am rename to services/presence/Makefile.am index 1710d540..c095cb63 100644 --- a/shell/PresenceService/Makefile.am +++ b/services/presence/Makefile.am @@ -5,7 +5,7 @@ service_DATA = $(service_in_files:.service.in=.service) $(service_DATA): $(service_in_files) Makefile @sed -e "s|\@bindir\@|$(bindir)|" $< > $@ -sugardir = $(pkgdatadir)/shell/PresenceService +sugardir = $(pkgdatadir)/services/presence sugar_PYTHON = \ __init__.py \ Activity.py \ @@ -13,6 +13,8 @@ sugar_PYTHON = \ PresenceService.py \ Service.py +bin_SCRIPTS = sugar-presence-service + DISTCLEANFILES = $(service_DATA) -EXTRA_DIST = $(service_in_files) +EXTRA_DIST = $(service_in_files) $(bin_SCRIPTS) diff --git a/shell/PresenceService/PresenceService.py b/services/presence/PresenceService.py similarity index 100% rename from shell/PresenceService/PresenceService.py rename to services/presence/PresenceService.py diff --git a/shell/PresenceService/Service.py b/services/presence/Service.py similarity index 100% rename from shell/PresenceService/Service.py rename to services/presence/Service.py diff --git a/shell/PresenceService/__init__.py b/services/presence/__init__.py similarity index 100% rename from shell/PresenceService/__init__.py rename to services/presence/__init__.py diff --git a/shell/PresenceService/org.laptop.Presence.service.in b/services/presence/org.laptop.Presence.service.in similarity index 100% rename from shell/PresenceService/org.laptop.Presence.service.in rename to services/presence/org.laptop.Presence.service.in diff --git a/shell/sugar-presence-service b/services/presence/sugar-presence-service similarity index 78% rename from shell/sugar-presence-service rename to services/presence/sugar-presence-service index fda0d12c..88fd2e71 100755 --- a/shell/sugar-presence-service +++ b/services/presence/sugar-presence-service @@ -1,7 +1,7 @@ #!/usr/bin/python import logging -from PresenceService import PresenceService +from presence import PresenceService import sugar.logger sugar.logger.start('PresenceService') diff --git a/shell/Makefile.am b/shell/Makefile.am index 1bf373dc..a4fd7192 100644 --- a/shell/Makefile.am +++ b/shell/Makefile.am @@ -1,11 +1,10 @@ -SUBDIRS = conf data model view PresenceService +SUBDIRS = conf data model view bin_SCRIPTS = \ sugar \ sugar-activity \ sugar-activity-factory \ - sugar-console \ - sugar-presence-service + sugar-console sugardir = $(pkgdatadir)/shell sugar_PYTHON = \ diff --git a/sugar/__installed__.py.in b/sugar/__installed__.py.in index 5ebed29a..fd1b8554 100644 --- a/sugar/__installed__.py.in +++ b/sugar/__installed__.py.in @@ -6,5 +6,6 @@ sugar_dbus_config = '@prefix@/share/sugar/dbus-installed.conf' sugar_python_path = ['@prefix@/share/sugar/shell', '@prefix@/share/sugar/bindings', - '@prefix@/share/sugar/activities'] + '@prefix@/share/sugar/activities', + '@prefix@/share/sugar/services'] sugar_bin_path = [] diff --git a/sugar/__uninstalled__.py.in b/sugar/__uninstalled__.py.in index 860cb21a..02b43f1c 100644 --- a/sugar/__uninstalled__.py.in +++ b/sugar/__uninstalled__.py.in @@ -14,6 +14,8 @@ sugar_python_path = ['@prefix@/share/sugar/bindings'] sugar_python_path.append(sugar_source_dir) sugar_python_path.append(os.path.join(sugar_source_dir, 'shell')) sugar_python_path.append(os.path.join(sugar_source_dir, 'activities')) +sugar_python_path.append(os.path.join(sugar_source_dir, 'services')) sugar_bin_path = [] sugar_bin_path.append(os.path.join(sugar_source_dir, 'shell')) +sugar_bin_path.append(os.path.join(sugar_source_dir, 'services/presence')) diff --git a/sugar/env.py b/sugar/env.py index 8fc131a1..b0c5443c 100644 --- a/sugar/env.py +++ b/sugar/env.py @@ -43,7 +43,8 @@ def setup_system(): runner = os.path.join(sugar_source_dir, 'shell/sugar-activity-factory') sugar.setup.setup_activities(source, sugar_activities_dir, runner) - bin = os.path.join(sugar_source_dir, 'shell/sugar-presence-service') + bin = os.path.join(sugar_source_dir, + 'services/presence/sugar-presence-service') sugar.setup.write_service('org.laptop.Presence', bin, sugar_activities_dir) From 844216585a1d4e8f6ec9033a213d0d6cf1e1694a Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 15 Sep 2006 14:24:26 +0200 Subject: [PATCH 20/27] Pass around the shell so that groups can reuse the grid --- shell/view/FriendIcon.py | 13 +++++++------ shell/view/FriendPopup.py | 4 +++- shell/view/Shell.py | 7 ++++++- shell/view/frame/BottomPanel.py | 8 ++++---- shell/view/frame/Frame.py | 10 ++++------ shell/view/frame/RightPanel.py | 14 +++++++------- shell/view/frame/TopPanel.py | 9 +++++---- shell/view/home/FriendsGroup.py | 13 +++++++------ shell/view/home/HomeGroup.py | 12 ++++++------ shell/view/home/HomeWindow.py | 8 ++++---- 10 files changed, 53 insertions(+), 45 deletions(-) diff --git a/shell/view/FriendIcon.py b/shell/view/FriendIcon.py index e5158e2b..3e506008 100644 --- a/shell/view/FriendIcon.py +++ b/shell/view/FriendIcon.py @@ -14,11 +14,11 @@ class _PopupShell: class FriendIcon(IconItem): _popup_shell = _PopupShell() - def __init__(self, shell_model, friend): + def __init__(self, shell, friend): IconItem.__init__(self, icon_name='stock-buddy', color=friend.get_color(), size=96) - self._shell_model = shell_model + self._shell = shell self._friend = friend self._popup = None self._popup_distance = 0 @@ -44,8 +44,8 @@ class FriendIcon(IconItem): FriendIcon._popup_shell.set_active(None) - grid = Grid() - self._popup = FriendPopup(grid, icon.get_friend()) + grid = self._shell.get_grid() + self._popup = FriendPopup(self._shell, icon.get_friend()) self._popup.connect('action', self._popup_action_cb) self._popup.connect('enter-notify-event', self._popup_enter_notify_event_cb) @@ -82,11 +82,12 @@ class FriendIcon(IconItem): if buddy == None: return + model = self._shell.get_model() if action == FriendPopup.ACTION_INVITE: - activity = self._shell_model.get_current_activity() + activity = model.get_current_activity() activity.invite(buddy) elif action == FriendPopup.ACTION_MAKE_FRIEND: - friends = self._shell_model.get_friends() + friends = model.get_friends() friends.add_buddy(buddy) def _popdown_cb(self, friend): diff --git a/shell/view/FriendPopup.py b/shell/view/FriendPopup.py index 06f10da1..5baff098 100644 --- a/shell/view/FriendPopup.py +++ b/shell/view/FriendPopup.py @@ -15,7 +15,7 @@ class FriendPopup(gtk.Window): gobject.TYPE_NONE, ([int])), } - def __init__(self, grid, friend): + def __init__(self, shell, friend): gtk.Window.__init__(self, gtk.WINDOW_POPUP) self._friend = friend @@ -24,6 +24,8 @@ class FriendPopup(gtk.Window): self._width = 13 self._height = 10 + grid = shell.get_grid() + canvas = CanvasView() self.add(canvas) canvas.show() diff --git a/shell/view/Shell.py b/shell/view/Shell.py index 7e1050e0..6236df99 100644 --- a/shell/view/Shell.py +++ b/shell/view/Shell.py @@ -2,6 +2,7 @@ import gtk import gobject import wnck +from sugar.canvas.Grid import Grid from view.home.HomeWindow import HomeWindow from view.ActivityHost import ActivityHost from view.frame.Frame import Frame @@ -14,6 +15,7 @@ class Shell(gobject.GObject): self._model = model self._screen = wnck.screen_get_default() + self._grid = Grid() self._key_grabber = KeyGrabber() self._key_grabber.connect('key-pressed', self.__global_key_pressed_cb) @@ -24,7 +26,7 @@ class Shell(gobject.GObject): self._key_grabber.grab('F5') self._key_grabber.grab('F6') - self._home_window = HomeWindow(self.get_model()) + self._home_window = HomeWindow(self) self._home_window.show() self.set_zoom_level(sugar.ZOOM_HOME) @@ -66,6 +68,9 @@ class Shell(gobject.GObject): def get_model(self): return self._model + def get_grid(self): + return self._grid + def set_zoom_level(self, level): if level == sugar.ZOOM_ACTIVITY: self._screen.toggle_showing_desktop(False) diff --git a/shell/view/frame/BottomPanel.py b/shell/view/frame/BottomPanel.py index d43160db..31bd2b46 100644 --- a/shell/view/frame/BottomPanel.py +++ b/shell/view/frame/BottomPanel.py @@ -33,12 +33,12 @@ class InviteItem(IconItem): return self._invite class BottomPanel(CanvasBox): - def __init__(self, grid, shell_model): - CanvasBox.__init__(self, grid, CanvasBox.HORIZONTAL, 1) + def __init__(self, shell): + CanvasBox.__init__(self, shell.get_grid(), CanvasBox.HORIZONTAL, 1) - self._shell_model = shell_model + self._shell_model = shell.get_model() self._invite_to_item = {} - self._invites = shell_model.get_invites() + self._invites = self._shell_model.get_invites() registry = conf.get_activity_registry() for activity in registry.list_activities(): diff --git a/shell/view/frame/Frame.py b/shell/view/frame/Frame.py index 5ebecccb..9967a505 100644 --- a/shell/view/frame/Frame.py +++ b/shell/view/frame/Frame.py @@ -12,31 +12,29 @@ class Frame: def __init__(self, shell): self._windows = [] - shell_model = shell.get_model() - model = goocanvas.CanvasModelSimple() root = model.get_root_item() - grid = Grid() + grid = shell.get_grid() bg = goocanvas.Rect(fill_color="#4f4f4f", line_width=0) grid.set_constraints(bg, 0, 0, 80, 60) root.add_child(bg) - panel = BottomPanel(grid, shell_model) + panel = BottomPanel(shell) grid.set_constraints(panel, 5, 55) root.add_child(panel) panel_window = PanelWindow(grid, model, 0, 55, 80, 5) self._windows.append(panel_window) - panel = TopPanel(grid, shell) + panel = TopPanel(shell) root.add_child(panel) panel_window = PanelWindow(grid, model, 0, 0, 80, 5) self._windows.append(panel_window) - panel = RightPanel(grid, shell_model) + panel = RightPanel(shell) grid.set_constraints(panel, 75, 5) root.add_child(panel) diff --git a/shell/view/frame/RightPanel.py b/shell/view/frame/RightPanel.py index f12ccf5f..7a064b57 100644 --- a/shell/view/frame/RightPanel.py +++ b/shell/view/frame/RightPanel.py @@ -8,10 +8,9 @@ from view.FriendIcon import FriendIcon from model.Friends import Friend class RightPanel(CanvasBox): - def __init__(self, grid, shell_model): - CanvasBox.__init__(self, grid, CanvasBox.VERTICAL, 1) - self._shell_model = shell_model - self._friends = shell_model.get_friends() + def __init__(self, shell): + CanvasBox.__init__(self, shell.get_grid(), CanvasBox.VERTICAL, 1) + self._shell = shell self._activity_ps = None self._joined_hid = -1 self._left_hid = -1 @@ -21,11 +20,12 @@ class RightPanel(CanvasBox): self._pservice.connect('activity-appeared', self.__activity_appeared_cb) - shell_model.connect('activity-changed', self.__activity_changed_cb) + shell.get_model().connect('activity-changed', + self.__activity_changed_cb) def add(self, buddy): friend = Friend(buddy.get_name(), buddy.get_color()) - icon = FriendIcon(self._shell_model, friend) + icon = FriendIcon(self._shell, friend) icon.set_popup_distance(1) self.set_constraints(icon, 3, 3) self.add_child(icon) @@ -42,7 +42,7 @@ class RightPanel(CanvasBox): self._buddies = {} def __activity_appeared_cb(self, pservice, activity_ps): - activity = self._shell_model.get_current_activity() + activity = self._shell.get_model().get_current_activity() if activity and activity_ps.get_id() == activity.get_id(): self._set_activity_ps(activity_ps) diff --git a/shell/view/frame/TopPanel.py b/shell/view/frame/TopPanel.py index 1409d854..b1611d70 100644 --- a/shell/view/frame/TopPanel.py +++ b/shell/view/frame/TopPanel.py @@ -5,14 +5,15 @@ from sugar.canvas.IconItem import IconItem import sugar class TopPanel(goocanvas.Group): - def __init__(self, grid, shell): + def __init__(self, shell): goocanvas.Group.__init__(self) - self._grid = grid self._shell = shell + grid = shell.get_grid() + box = CanvasBox(grid, CanvasBox.HORIZONTAL, 1) - self._grid.set_constraints(box, 5, 0) + grid.set_constraints(box, 5, 0) self.add_child(box) icon = IconItem(icon_name='stock-zoom-activity') @@ -36,7 +37,7 @@ class TopPanel(goocanvas.Group): box.add_child(icon) box = CanvasBox(grid, CanvasBox.HORIZONTAL, 1) - self._grid.set_constraints(box, 60, 0) + grid.set_constraints(box, 60, 0) self.add_child(box) icon = IconItem(icon_name='stock-share') diff --git a/shell/view/home/FriendsGroup.py b/shell/view/home/FriendsGroup.py index 1e2fb8f2..2f69a6e0 100644 --- a/shell/view/home/FriendsGroup.py +++ b/shell/view/home/FriendsGroup.py @@ -7,25 +7,26 @@ from view.home.MyIcon import MyIcon from view.FriendIcon import FriendIcon class FriendsGroup(goocanvas.Group): - def __init__(self, shell_model): + def __init__(self, shell): goocanvas.Group.__init__(self) - self._shell_model = shell_model + self._shell = shell self._icon_layout = IconLayout(1200, 900) - self._friends = shell_model.get_friends() me = MyIcon(100) me.translate(600 - (me.get_property('size') / 2), 450 - (me.get_property('size') / 2)) self.add_child(me) - for friend in self._friends: + friends = self._shell.get_model().get_friends() + + for friend in friends: self.add_friend(friend) - self._friends.connect('friend-added', self._friend_added_cb) + friends.connect('friend-added', self._friend_added_cb) def add_friend(self, friend): - icon = FriendIcon(self._shell_model, friend) + icon = FriendIcon(self._shell, friend) self.add_child(icon) self._icon_layout.add_icon(icon) diff --git a/shell/view/home/HomeGroup.py b/shell/view/home/HomeGroup.py index e6376cde..d01ba167 100644 --- a/shell/view/home/HomeGroup.py +++ b/shell/view/home/HomeGroup.py @@ -4,14 +4,14 @@ from view.home.DonutItem import DonutItem from view.home.MyIcon import MyIcon class TasksItem(DonutItem): - def __init__(self, shell_model): + def __init__(self, shell): DonutItem.__init__(self, 250) self._items = {} - self._shell_model = shell_model - self._shell_model.connect('activity_opened', self.__activity_opened_cb) - self._shell_model.connect('activity_closed', self.__activity_closed_cb) + shell_model = shell.get_model() + shell_model.connect('activity_opened', self.__activity_opened_cb) + shell_model.connect('activity_closed', self.__activity_closed_cb) def __activity_opened_cb(self, model, activity): self._add(activity) @@ -39,10 +39,10 @@ class TasksItem(DonutItem): activity.present() class HomeGroup(goocanvas.Group): - def __init__(self, shell_model): + def __init__(self, shell): goocanvas.Group.__init__(self) - tasks = TasksItem(shell_model) + tasks = TasksItem(shell) tasks.translate(600, 450) self.add_child(tasks) diff --git a/shell/view/home/HomeWindow.py b/shell/view/home/HomeWindow.py index b89420f0..773ee770 100644 --- a/shell/view/home/HomeWindow.py +++ b/shell/view/home/HomeWindow.py @@ -9,9 +9,9 @@ from view.home.FriendsGroup import FriendsGroup import sugar class HomeWindow(gtk.Window): - def __init__(self, shell_model): + def __init__(self, shell): gtk.Window.__init__(self) - self._shell_model = shell_model + self._shell = shell self.realize() self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DESKTOP) @@ -23,8 +23,8 @@ class HomeWindow(gtk.Window): self.add(self._nb) self._nb.show() - self._add_page(HomeGroup(shell_model)) - self._add_page(FriendsGroup(shell_model)) + self._add_page(HomeGroup(shell)) + self._add_page(FriendsGroup(shell)) self._add_page(MeshGroup()) def _add_page(self, group): From 16574cbfccdd5a5bb8da7a8c6165a0063f5f7ce3 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 15 Sep 2006 14:41:56 +0200 Subject: [PATCH 21/27] s/FriendIcon/BuddyIcon since that is generic now --- shell/view/{FriendIcon.py => BuddyIcon.py} | 14 +++++++------- shell/view/{FriendPopup.py => BuddyPopup.py} | 6 +++--- shell/view/frame/RightPanel.py | 4 ++-- shell/view/home/FriendsGroup.py | 4 ++-- 4 files changed, 14 insertions(+), 14 deletions(-) rename shell/view/{FriendIcon.py => BuddyIcon.py} (88%) rename shell/view/{FriendPopup.py => BuddyPopup.py} (95%) diff --git a/shell/view/FriendIcon.py b/shell/view/BuddyIcon.py similarity index 88% rename from shell/view/FriendIcon.py rename to shell/view/BuddyIcon.py index 3e506008..1743b79b 100644 --- a/shell/view/FriendIcon.py +++ b/shell/view/BuddyIcon.py @@ -1,6 +1,6 @@ from sugar.canvas.IconItem import IconItem from sugar.canvas.Grid import Grid -from view.FriendPopup import FriendPopup +from view.BuddyPopup import BuddyPopup class _PopupShell: def __init__(self): @@ -11,7 +11,7 @@ class _PopupShell: self._popup_controller._popdown() self._popup_controller = controller -class FriendIcon(IconItem): +class BuddyIcon(IconItem): _popup_shell = _PopupShell() def __init__(self, shell, friend): @@ -42,10 +42,10 @@ class FriendIcon(IconItem): def _popup_cb(self, icon, x1, y1, x2, y2): self._popdown() - FriendIcon._popup_shell.set_active(None) + BuddyIcon._popup_shell.set_active(None) grid = self._shell.get_grid() - self._popup = FriendPopup(self._shell, icon.get_friend()) + self._popup = BuddyPopup(self._shell, icon.get_friend()) self._popup.connect('action', self._popup_action_cb) self._popup.connect('enter-notify-event', self._popup_enter_notify_event_cb) @@ -73,7 +73,7 @@ class FriendIcon(IconItem): self._popup.show() - FriendIcon._popup_shell.set_active(self) + BuddyIcon._popup_shell.set_active(self) def _popup_action_cb(self, popup, action): self._popdown() @@ -83,10 +83,10 @@ class FriendIcon(IconItem): return model = self._shell.get_model() - if action == FriendPopup.ACTION_INVITE: + if action == BuddyPopup.ACTION_INVITE: activity = model.get_current_activity() activity.invite(buddy) - elif action == FriendPopup.ACTION_MAKE_FRIEND: + elif action == BuddyPopup.ACTION_MAKE_FRIEND: friends = model.get_friends() friends.add_buddy(buddy) diff --git a/shell/view/FriendPopup.py b/shell/view/BuddyPopup.py similarity index 95% rename from shell/view/FriendPopup.py rename to shell/view/BuddyPopup.py index 5baff098..a5a04fd6 100644 --- a/shell/view/FriendPopup.py +++ b/shell/view/BuddyPopup.py @@ -6,7 +6,7 @@ from sugar.canvas.CanvasView import CanvasView from sugar.canvas.CanvasBox import CanvasBox from sugar.canvas.IconItem import IconItem -class FriendPopup(gtk.Window): +class BuddyPopup(gtk.Window): ACTION_MAKE_FRIEND = 0 ACTION_INVITE = 1 @@ -57,7 +57,7 @@ class FriendPopup(gtk.Window): icon = IconItem(icon_name='stock-make-friend') icon.connect('clicked', self._action_clicked_cb, - FriendPopup.ACTION_MAKE_FRIEND) + BuddyPopup.ACTION_MAKE_FRIEND) box.set_constraints(icon, 3, 3) box.add_child(icon) @@ -67,7 +67,7 @@ class FriendPopup(gtk.Window): icon = IconItem(icon_name='stock-invite') icon.connect('clicked', self._action_clicked_cb, - FriendPopup.ACTION_INVITE) + BuddyPopup.ACTION_INVITE) box.set_constraints(icon, 3, 3) box.add_child(icon) diff --git a/shell/view/frame/RightPanel.py b/shell/view/frame/RightPanel.py index 7a064b57..20e96222 100644 --- a/shell/view/frame/RightPanel.py +++ b/shell/view/frame/RightPanel.py @@ -4,7 +4,7 @@ from sugar.canvas.IconItem import IconItem from sugar.canvas.IconColor import IconColor from sugar.canvas.CanvasBox import CanvasBox from sugar.presence import PresenceService -from view.FriendIcon import FriendIcon +from view.BuddyIcon import BuddyIcon from model.Friends import Friend class RightPanel(CanvasBox): @@ -25,7 +25,7 @@ class RightPanel(CanvasBox): def add(self, buddy): friend = Friend(buddy.get_name(), buddy.get_color()) - icon = FriendIcon(self._shell, friend) + icon = BuddyIcon(self._shell, friend) icon.set_popup_distance(1) self.set_constraints(icon, 3, 3) self.add_child(icon) diff --git a/shell/view/home/FriendsGroup.py b/shell/view/home/FriendsGroup.py index 2f69a6e0..3904080b 100644 --- a/shell/view/home/FriendsGroup.py +++ b/shell/view/home/FriendsGroup.py @@ -4,7 +4,7 @@ import goocanvas from view.home.IconLayout import IconLayout from view.home.MyIcon import MyIcon -from view.FriendIcon import FriendIcon +from view.BuddyIcon import BuddyIcon class FriendsGroup(goocanvas.Group): def __init__(self, shell): @@ -26,7 +26,7 @@ class FriendsGroup(goocanvas.Group): friends.connect('friend-added', self._friend_added_cb) def add_friend(self, friend): - icon = FriendIcon(self._shell, friend) + icon = BuddyIcon(self._shell, friend) self.add_child(icon) self._icon_layout.add_icon(icon) From f2f25f874d639c31d4c8182c18ee8f11acb0b579 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 15 Sep 2006 15:28:18 +0200 Subject: [PATCH 22/27] Implement friends removal, lots of cleanups --- shell/model/Friends.py | 51 ++++++++++++--------------------- shell/model/ShellModel.py | 20 ------------- shell/view/BuddyIcon.py | 5 +++- shell/view/BuddyPopup.py | 22 +++++++++----- shell/view/Shell.py | 23 +++++++++++++++ shell/view/frame/RightPanel.py | 5 ++-- shell/view/home/FriendsGroup.py | 16 ++++++++--- shell/view/home/HomeWindow.py | 2 +- shell/view/home/MeshGroup.py | 5 +++- 9 files changed, 80 insertions(+), 69 deletions(-) diff --git a/shell/model/Friends.py b/shell/model/Friends.py index 6beca663..a11acc06 100644 --- a/shell/model/Friends.py +++ b/shell/model/Friends.py @@ -3,67 +3,54 @@ from ConfigParser import ConfigParser import gobject -from sugar.canvas.IconColor import IconColor -from sugar.presence import PresenceService +from model.BuddyInfo import BuddyInfo from sugar import env -class Friend: - def __init__(self, name, color): - self._name = name - self._color = color - - def get_name(self): - return self._name - - def get_color(self): - return IconColor(self._color) - - def get_buddy(self): - pservice = PresenceService.get_instance() - return pservice.get_buddy_by_name(self._name) - class Friends(gobject.GObject): __gsignals__ = { 'friend-added': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([object])), 'friend-removed': (gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, ([object])), + gobject.TYPE_NONE, ([str])), } def __init__(self): gobject.GObject.__init__(self) - self._list = [] + self._friends = {} self._path = os.path.join(env.get_profile_path(), 'friends') self.load() def has_buddy(self, buddy): - for friend in self: - if friend.get_name() == buddy.get_name(): - return True - return False + return self._friends.has_key(buddy.get_name()) - def add_friend(self, name, color): - friend = Friend(name, color) - self._list.append(friend) + def add_friend(self, buddy_info): + self._friends[buddy_info.get_name()] = buddy_info + self.emit('friend-added', buddy_info) - self.emit('friend-added', friend) - - def add_buddy(self, buddy): + def make_friend(self, buddy): if not self.has_buddy(buddy): - self.add_friend(buddy.get_name(), buddy.get_color()) + self.add_friend(BuddyInfo(buddy)) self.save() + def remove(self, buddy_info): + del self._friends[buddy_info.get_name()] + self.save() + self.emit('friend-removed', buddy_info.get_name()) + def __iter__(self): - return self._list.__iter__() + return self._friends.values().__iter__() def load(self): cp = ConfigParser() if cp.read([self._path]): for name in cp.sections(): - self.add_friend(name, cp.get(name, 'color')) + buddy = BuddyInfo() + buddy.set_name(name) + buddy.set_color(cp.get(name, 'color')) + self.add_friend(buddy) def save(self): cp = ConfigParser() diff --git a/shell/model/ShellModel.py b/shell/model/ShellModel.py index 2f9dd255..4929fe79 100644 --- a/shell/model/ShellModel.py +++ b/shell/model/ShellModel.py @@ -1,8 +1,6 @@ import gobject from sugar.presence import PresenceService -from sugar.activity import ActivityFactory -from sugar.activity import Activity from model.Friends import Friends from model.Invites import Invites from model.Owner import ShellOwner @@ -66,21 +64,3 @@ class ShellModel(gobject.GObject): def get_current_activity(self): return self._current_activity - - def join_activity(self, bundle_id, activity_id): - activity = self.get_activity(activity_id) - if activity: - activity.present() - else: - activity_ps = self._pservice.get_activity(activity_id) - - if activity_ps: - activity = ActivityFactory.create(bundle_id) - activity.join(activity_ps.object_path()) - else: - logging.error('Cannot start activity.') - - def start_activity(self, activity_type): - activity = ActivityFactory.create(activity_type) - activity.execute('test', []) - return activity diff --git a/shell/view/BuddyIcon.py b/shell/view/BuddyIcon.py index 1743b79b..3e26b084 100644 --- a/shell/view/BuddyIcon.py +++ b/shell/view/BuddyIcon.py @@ -88,7 +88,10 @@ class BuddyIcon(IconItem): activity.invite(buddy) elif action == BuddyPopup.ACTION_MAKE_FRIEND: friends = model.get_friends() - friends.add_buddy(buddy) + friends.make_friend(buddy) + elif action == BuddyPopup.ACTION_REMOVE_FRIEND: + friends = model.get_friends() + friends.remove(buddy) def _popdown_cb(self, friend): if not self._hover_popup: diff --git a/shell/view/BuddyPopup.py b/shell/view/BuddyPopup.py index a5a04fd6..4aab3f6b 100644 --- a/shell/view/BuddyPopup.py +++ b/shell/view/BuddyPopup.py @@ -9,16 +9,17 @@ from sugar.canvas.IconItem import IconItem class BuddyPopup(gtk.Window): ACTION_MAKE_FRIEND = 0 ACTION_INVITE = 1 + ACTION_REMOVE_FRIEND = 2 __gsignals__ = { 'action': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([int])), } - def __init__(self, shell, friend): + def __init__(self, shell, buddy): gtk.Window.__init__(self, gtk.WINDOW_POPUP) - self._friend = friend + self._buddy = buddy self._hover = False self._popdown_on_leave = False self._width = 13 @@ -35,14 +36,14 @@ class BuddyPopup(gtk.Window): model = goocanvas.CanvasModelSimple() root = model.get_root_item() - color = friend.get_color() + color = buddy.get_color() rect = goocanvas.Rect(fill_color=color.get_fill_color(), stroke_color=color.get_stroke_color(), line_width=3) grid.set_constraints(rect, 0, 0, self._width, self._height) root.add_child(rect) - text = goocanvas.Text(text=friend.get_name(), font="Sans bold 18", + text = goocanvas.Text(text=buddy.get_name(), font="Sans bold 18", fill_color='black', anchor=gtk.ANCHOR_SW) grid.set_constraints(text, 1, 3, self._width, self._height) root.add_child(text) @@ -55,9 +56,16 @@ class BuddyPopup(gtk.Window): box = CanvasBox(grid, CanvasBox.HORIZONTAL, 1) grid.set_constraints(box, 0, 5) - icon = IconItem(icon_name='stock-make-friend') - icon.connect('clicked', self._action_clicked_cb, - BuddyPopup.ACTION_MAKE_FRIEND) + friends = shell.get_model().get_friends() + if friends.has_buddy(buddy): + icon = IconItem(icon_name='stock-remove-friend') + icon.connect('clicked', self._action_clicked_cb, + BuddyPopup.ACTION_REMOVE_FRIEND) + else: + icon = IconItem(icon_name='stock-make-friend') + icon.connect('clicked', self._action_clicked_cb, + BuddyPopup.ACTION_MAKE_FRIEND) + box.set_constraints(icon, 3, 3) box.add_child(icon) diff --git a/shell/view/Shell.py b/shell/view/Shell.py index 6236df99..76d3f263 100644 --- a/shell/view/Shell.py +++ b/shell/view/Shell.py @@ -4,7 +4,10 @@ import wnck from sugar.canvas.Grid import Grid from view.home.HomeWindow import HomeWindow +from sugar.presence import PresenceService from view.ActivityHost import ActivityHost +from sugar.activity import ActivityFactory +from sugar.activity import Activity from view.frame.Frame import Frame from globalkeys import KeyGrabber import sugar @@ -71,6 +74,26 @@ class Shell(gobject.GObject): def get_grid(self): return self._grid + def join_activity(self, bundle_id, activity_id): + pservice = PresenceService.get_instance() + + activity = self._model.get_activity(activity_id) + if activity: + activity.present() + else: + activity_ps = pservice.get_activity(activity_id) + + if activity_ps: + activity = ActivityFactory.create(bundle_id) + activity.join(activity_ps.object_path()) + else: + logging.error('Cannot start activity.') + + def start_activity(self, activity_type): + activity = ActivityFactory.create(activity_type) + activity.execute('test', []) + return activity + def set_zoom_level(self, level): if level == sugar.ZOOM_ACTIVITY: self._screen.toggle_showing_desktop(False) diff --git a/shell/view/frame/RightPanel.py b/shell/view/frame/RightPanel.py index 20e96222..6ed4a0d6 100644 --- a/shell/view/frame/RightPanel.py +++ b/shell/view/frame/RightPanel.py @@ -5,7 +5,7 @@ from sugar.canvas.IconColor import IconColor from sugar.canvas.CanvasBox import CanvasBox from sugar.presence import PresenceService from view.BuddyIcon import BuddyIcon -from model.Friends import Friend +from model.BuddyInfo import BuddyInfo class RightPanel(CanvasBox): def __init__(self, shell): @@ -24,8 +24,7 @@ class RightPanel(CanvasBox): self.__activity_changed_cb) def add(self, buddy): - friend = Friend(buddy.get_name(), buddy.get_color()) - icon = BuddyIcon(self._shell, friend) + icon = BuddyIcon(self._shell, BuddyInfo(buddy)) icon.set_popup_distance(1) self.set_constraints(icon, 3, 3) self.add_child(icon) diff --git a/shell/view/home/FriendsGroup.py b/shell/view/home/FriendsGroup.py index 3904080b..17497388 100644 --- a/shell/view/home/FriendsGroup.py +++ b/shell/view/home/FriendsGroup.py @@ -12,6 +12,7 @@ class FriendsGroup(goocanvas.Group): self._shell = shell self._icon_layout = IconLayout(1200, 900) + self._friends = {} me = MyIcon(100) me.translate(600 - (me.get_property('size') / 2), @@ -24,11 +25,18 @@ class FriendsGroup(goocanvas.Group): self.add_friend(friend) friends.connect('friend-added', self._friend_added_cb) + friends.connect('friend-removed', self._friend_removed_cb) - def add_friend(self, friend): - icon = BuddyIcon(self._shell, friend) + def add_friend(self, buddy_info): + icon = BuddyIcon(self._shell, buddy_info) self.add_child(icon) self._icon_layout.add_icon(icon) - def _friend_added_cb(self, data_model, friend): - self.add_friend(friend) + self._friends[buddy_info.get_name()] = icon + + def _friend_added_cb(self, data_model, buddy_info): + self.add_friend(buddy_info) + + def _friend_removed_cb(self, data_model, name): + self.remove_child(self._friends[name]) + del self._friends[name] diff --git a/shell/view/home/HomeWindow.py b/shell/view/home/HomeWindow.py index 773ee770..ba1129e4 100644 --- a/shell/view/home/HomeWindow.py +++ b/shell/view/home/HomeWindow.py @@ -25,7 +25,7 @@ class HomeWindow(gtk.Window): self._add_page(HomeGroup(shell)) self._add_page(FriendsGroup(shell)) - self._add_page(MeshGroup()) + self._add_page(MeshGroup(shell)) def _add_page(self, group): view = CanvasView() diff --git a/shell/view/home/MeshGroup.py b/shell/view/home/MeshGroup.py index 90dce0e0..61118238 100644 --- a/shell/view/home/MeshGroup.py +++ b/shell/view/home/MeshGroup.py @@ -32,8 +32,11 @@ class ActivityItem(IconItem): return self._service class MeshGroup(goocanvas.Group): - def __init__(self): + def __init__(self, shell): goocanvas.Group.__init__(self) + + self._shell = shell + self._icon_layout = IconLayout(1200, 900) self._activities = {} From 7b37c4d38b0ae6fe6f5a346b3685414185237a09 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 15 Sep 2006 15:30:46 +0200 Subject: [PATCH 23/27] Fix opening new activities --- shell/model/BuddyInfo.py | 24 ++++++++++++++++++++++++ shell/view/frame/BottomPanel.py | 10 +++++----- 2 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 shell/model/BuddyInfo.py diff --git a/shell/model/BuddyInfo.py b/shell/model/BuddyInfo.py new file mode 100644 index 00000000..68f0a445 --- /dev/null +++ b/shell/model/BuddyInfo.py @@ -0,0 +1,24 @@ +from sugar.presence import PresenceService +from sugar.canvas.IconColor import IconColor + +class BuddyInfo: + def __init__(self, buddy=None): + if buddy: + self.set_name(buddy.get_name()) + self.set_color(buddy.get_color()) + + def set_name(self, name): + self._name = name + + def set_color(self, color_string): + self._color = IconColor(color_string) + + def get_name(self): + return self._name + + def get_color(self): + return self._color + + def get_buddy(self): + pservice = PresenceService.get_instance() + return pservice.get_buddy_by_name(self._name) diff --git a/shell/view/frame/BottomPanel.py b/shell/view/frame/BottomPanel.py index 31bd2b46..5f98f016 100644 --- a/shell/view/frame/BottomPanel.py +++ b/shell/view/frame/BottomPanel.py @@ -36,9 +36,9 @@ class BottomPanel(CanvasBox): def __init__(self, shell): CanvasBox.__init__(self, shell.get_grid(), CanvasBox.HORIZONTAL, 1) - self._shell_model = shell.get_model() + self._shell = shell self._invite_to_item = {} - self._invites = self._shell_model.get_invites() + self._invites = self._shell.get_model().get_invites() registry = conf.get_activity_registry() for activity in registry.list_activities(): @@ -51,12 +51,12 @@ class BottomPanel(CanvasBox): self._invites.connect('invite-removed', self.__invite_removed_cb) def __activity_clicked_cb(self, icon): - self._shell_model.start_activity(icon.get_bundle_id()) + self._shell.start_activity(icon.get_bundle_id()) def __invite_clicked_cb(self, icon): self._invites.remove_invite(icon.get_invite()) - self._shell_model.join_activity(icon.get_bundle_id(), - icon.get_activity_id()) + self._shell.join_activity(icon.get_bundle_id(), + icon.get_activity_id()) def __invite_added_cb(self, invites, invite): self.add_invite(invite) From a2655faa7d373b40b917cb061f9058e6f0fabc41 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 15 Sep 2006 15:35:20 +0200 Subject: [PATCH 24/27] Fix makefiles --- shell/model/Makefile.am | 1 + shell/view/Makefile.am | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/shell/model/Makefile.am b/shell/model/Makefile.am index 2ce494ba..ce246686 100644 --- a/shell/model/Makefile.am +++ b/shell/model/Makefile.am @@ -1,6 +1,7 @@ sugardir = $(pkgdatadir)/shell/model sugar_PYTHON = \ __init__.py \ + BuddyInfo.py \ Friends.py \ Invites.py \ Owner.py \ diff --git a/shell/view/Makefile.am b/shell/view/Makefile.am index 7481dbe5..4b1c901d 100644 --- a/shell/view/Makefile.am +++ b/shell/view/Makefile.am @@ -6,6 +6,6 @@ sugar_PYTHON = \ ActivityHost.py \ ConsoleWindow.py \ FirstTimeDialog.py \ - FriendIcon.py \ - FriendPopup.py \ + BuddyIcon.py \ + BuddyPopup.py \ Shell.py From 7fb01c51e3dff5eb49ade044f15de30778355854 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 15 Sep 2006 15:49:52 +0200 Subject: [PATCH 25/27] Missing directory --- configure.ac | 1 + 1 file changed, 1 insertion(+) diff --git a/configure.ac b/configure.ac index 7d50fb28..a81c6d59 100644 --- a/configure.ac +++ b/configure.ac @@ -46,6 +46,7 @@ bindings/Makefile bindings/globalkeys/Makefile bindings/threadframe/Makefile services/Makefile +services/presence/Makefile shell/Makefile shell/conf/Makefile shell/data/Makefile From fe64b7c6d4d2351652cb311849b37fe95888834d Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 15 Sep 2006 16:04:30 +0200 Subject: [PATCH 26/27] Fix invites --- shell/model/Owner.py | 6 ++++++ shell/model/ShellModel.py | 4 +--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/shell/model/Owner.py b/shell/model/Owner.py index 7dec04a7..5443eb97 100644 --- a/shell/model/Owner.py +++ b/shell/model/Owner.py @@ -6,6 +6,7 @@ import conf from sugar import env from sugar.p2p import Stream from sugar.presence import PresenceService +from model.Friends import Friends PRESENCE_SERVICE_TYPE = "_presence_olpc._tcp" @@ -30,6 +31,11 @@ class ShellOwner(object): self._pservice = PresenceService.get_instance() + self._friends = Friends() + + def get_friends(self): + return self._friends + def announce(self): # Create and announce our presence color = conf.get_profile().get_color() diff --git a/shell/model/ShellModel.py b/shell/model/ShellModel.py index 4929fe79..2bdf08ab 100644 --- a/shell/model/ShellModel.py +++ b/shell/model/ShellModel.py @@ -1,7 +1,6 @@ import gobject from sugar.presence import PresenceService -from model.Friends import Friends from model.Invites import Invites from model.Owner import ShellOwner @@ -26,11 +25,10 @@ class ShellModel(gobject.GObject): self._owner = ShellOwner() self._owner.announce() - self._friends = Friends() self._invites = Invites() def get_friends(self): - return self._friends + return self._owner.get_friends() def get_invites(self): return self._invites From e79a5f5e989fa062366295c3f236692fc3c889e5 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 15 Sep 2006 16:19:56 +0200 Subject: [PATCH 27/27] Really fix invites --- shell/model/Owner.py | 8 ++++---- shell/model/ShellModel.py | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/shell/model/Owner.py b/shell/model/Owner.py index 5443eb97..1a6e3e85 100644 --- a/shell/model/Owner.py +++ b/shell/model/Owner.py @@ -6,7 +6,7 @@ import conf from sugar import env from sugar.p2p import Stream from sugar.presence import PresenceService -from model.Friends import Friends +from model.Invites import Invites PRESENCE_SERVICE_TYPE = "_presence_olpc._tcp" @@ -31,10 +31,10 @@ class ShellOwner(object): self._pservice = PresenceService.get_instance() - self._friends = Friends() + self._invites = Invites() - def get_friends(self): - return self._friends + def get_invites(self): + return self._invites def announce(self): # Create and announce our presence diff --git a/shell/model/ShellModel.py b/shell/model/ShellModel.py index 2bdf08ab..a20ac98d 100644 --- a/shell/model/ShellModel.py +++ b/shell/model/ShellModel.py @@ -1,7 +1,7 @@ import gobject from sugar.presence import PresenceService -from model.Invites import Invites +from model.Friends import Friends from model.Owner import ShellOwner class ShellModel(gobject.GObject): @@ -25,13 +25,13 @@ class ShellModel(gobject.GObject): self._owner = ShellOwner() self._owner.announce() - self._invites = Invites() + self._friends = Friends() def get_friends(self): - return self._owner.get_friends() + return self._friends def get_invites(self): - return self._invites + return self._owner.get_invites() def get_owner(self): return self._owner