From 59add6e9011bee1ab0fe9609659e0c5a04e91c6a Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Mon, 25 Sep 2006 18:38:01 +0200 Subject: [PATCH 1/3] More work on the mesh view --- shell/view/home/MeshGroup.py | 50 ++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/shell/view/home/MeshGroup.py b/shell/view/home/MeshGroup.py index 985d18df..d85809c7 100644 --- a/shell/view/home/MeshGroup.py +++ b/shell/view/home/MeshGroup.py @@ -12,18 +12,42 @@ class ActivityView(goocanvas.Group): def __init__(self, shell, menu_shell, model): goocanvas.Group.__init__(self) + self._shell = shell self._model = model self._layout = SnowflakeLayout() + self._icons = {} icon = IconItem(icon_name=model.get_icon_name(), color=model.get_color(), size=80) + icon.connect('clicked', self._clicked_cb) self.add_child(icon) self._layout.set_root(icon) + def has_buddy_icon(self, name): + return self._icons.has_key(name) + + def add_buddy_icon(self, name, icon): + self._icons[name] = icon + self.add_child(icon) + self._layout.add_child(icon) + + def remove_buddy_icon(self, name): + icon = self._icons[name] + self._layout.remove_child(icon) + self.remove_child(icon) + del self._icons[name] + def get_size_request(self): size = self._layout.get_size() return [size, size] + def _clicked_cb(self, item): + registry = conf.get_activity_registry() + default_type = self._model.get_service().get_type() + bundle = registry.get_activity_from_type(default_type) + self._shell.join_activity(bundle.get_id(), self._model.get_id()) + + class MeshGroup(goocanvas.Group): def __init__(self, shell, menu_shell): goocanvas.Group.__init__(self) @@ -34,12 +58,14 @@ class MeshGroup(goocanvas.Group): self._layout = IconLayout(shell.get_grid()) self._buddies = {} self._activities = {} + self._buddy_to_activity = {} for buddy_model in self._model.get_buddies(): self._add_buddy(buddy_model) self._model.connect('buddy-added', self._buddy_added_cb) self._model.connect('buddy-removed', self._buddy_removed_cb) + self._model.connect('buddy-moved', self._buddy_moved_cb) for activity_model in self._model.get_activities(): self._add_activity(activity_model) @@ -53,6 +79,9 @@ class MeshGroup(goocanvas.Group): def _buddy_removed_cb(self, model, buddy_model): self._remove_buddy(buddy_model) + def _buddy_moved_cb(self, model, buddy_model, activity_model): + self._move_buddy(buddy_model, activity_model) + def _activity_added_cb(self, model, activity_model): self._add_activity(activity_model) @@ -70,8 +99,28 @@ class MeshGroup(goocanvas.Group): def _remove_buddy(self, buddy_model): icon = self._buddies[buddy_model.get_name()] self.remove_child(icon) + self._layout.remove_icon(icon) del self._buddies[buddy_model.get_name()] + def _move_buddy(self, buddy_model, activity_model): + name = buddy_model.get_name() + + if self._buddies.has_key(name): + self._remove_buddy(buddy_model) + + for activity in self._activities.values(): + if activity.has_buddy_icon(name): + activity.remove_buddy_icon(name) + + if activity_model == None: + self.add_buddy(buddy_model) + else: + activity = self._activities[activity_model.get_id()] + + icon = BuddyIcon(self._shell, self._menu_shell, buddy_model) + icon.props.size = 60 + activity.add_buddy_icon(buddy_model.get_name(), icon) + def _add_activity(self, activity_model): icon = ActivityView(self._shell, self._menu_shell, activity_model) self.add_child(icon) @@ -82,4 +131,5 @@ class MeshGroup(goocanvas.Group): def _remove_activity(self, activity_model): icon = self._activities[activity_model.get_id()] self.remove_child(icon) + self._layout.remove_icon(icon) del self._activities[activity_model.get_id()] From d63180c4f402f16629006d699004df93ac685179 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Mon, 25 Sep 2006 18:55:35 +0200 Subject: [PATCH 2/3] Some fixes --- shell/view/home/MeshGroup.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/shell/view/home/MeshGroup.py b/shell/view/home/MeshGroup.py index d85809c7..689f759e 100644 --- a/shell/view/home/MeshGroup.py +++ b/shell/view/home/MeshGroup.py @@ -74,7 +74,7 @@ class MeshGroup(goocanvas.Group): self._model.connect('activity-removed', self._activity_removed_cb) def _buddy_added_cb(self, model, buddy_model): - self._add_buddy(buddy_model) + self._add_alone_buddy(buddy_model) def _buddy_removed_cb(self, model, buddy_model): self._remove_buddy(buddy_model) @@ -88,7 +88,7 @@ class MeshGroup(goocanvas.Group): def _activity_removed_cb(self, model, activity_model): self._remove_activity(activity_model) - def _add_buddy(self, buddy_model): + def _add_alone_buddy(self, buddy_model): icon = BuddyIcon(self._shell, self._menu_shell, buddy_model) icon.props.size = 80 self.add_child(icon) @@ -96,21 +96,25 @@ class MeshGroup(goocanvas.Group): self._buddies[buddy_model.get_name()] = icon self._layout.add_icon(icon) - def _remove_buddy(self, buddy_model): + def _remove_alone_buddy(self, buddy_model): icon = self._buddies[buddy_model.get_name()] self.remove_child(icon) self._layout.remove_icon(icon) del self._buddies[buddy_model.get_name()] + def _remove_buddy(self, buddy_model): + name = buddy_model.get_name() + if self._buddies.has_key(name): + self._remove_alone_buddy(buddy_model) + else: + for activity in self._activities.values(): + if activity.has_buddy_icon(name): + activity.remove_buddy_icon(name) + def _move_buddy(self, buddy_model, activity_model): name = buddy_model.get_name() - if self._buddies.has_key(name): - self._remove_buddy(buddy_model) - - for activity in self._activities.values(): - if activity.has_buddy_icon(name): - activity.remove_buddy_icon(name) + self._remove_buddy(buddy_model) if activity_model == None: self.add_buddy(buddy_model) From 2ac1bf73029b01d94ca750c2b9aa52821ff6ef97 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Mon, 25 Sep 2006 19:06:31 +0200 Subject: [PATCH 3/3] Handle image size allocation --- sugar/canvas/Grid.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sugar/canvas/Grid.py b/sugar/canvas/Grid.py index 70bafa38..5a488905 100644 --- a/sugar/canvas/Grid.py +++ b/sugar/canvas/Grid.py @@ -63,6 +63,9 @@ class Grid: item.props.height = height - (item.props.line_width - 1) * 2 elif isinstance(item, goocanvas.Text): item.props.width = width + elif isinstance(item, goocanvas.Image): + item.props.width = width + item.props.height = height elif isinstance(item, IconItem): item.props.size = width