Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@localhost.localdomain>2007-07-05 22:46:12 (GMT)
committer Marco Pesenti Gritti <marco@localhost.localdomain>2007-07-05 22:46:12 (GMT)
commitf1ecb99207f00887ba51cc3d1303247dabc335b2 (patch)
tree22dcdd2b48856b90cf74a763a03f2b5568231a5c
parentcc11d5ebd5777ca258f2f821daa493f6d2f235e5 (diff)
Complete transition to new spread layout.
-rw-r--r--shell/view/home/FriendsBox.py15
-rw-r--r--shell/view/home/MeshBox.py22
-rw-r--r--shell/view/home/transitionbox.py11
-rw-r--r--sugar/graphics/spreadlayout.py18
-rwxr-xr-xtests/test-spread-layout.py2
5 files changed, 42 insertions, 26 deletions
diff --git a/shell/view/home/FriendsBox.py b/shell/view/home/FriendsBox.py
index 2ce2e3b..39afa0b 100644
--- a/shell/view/home/FriendsBox.py
+++ b/shell/view/home/FriendsBox.py
@@ -19,21 +19,24 @@ import random
import hippo
import gobject
-from sugar.graphics.spreadbox import SpreadBox
+from sugar.graphics.spreadlayout import SpreadLayout
from sugar.graphics import units
from view.home.MyIcon import MyIcon
from view.home.FriendView import FriendView
-class FriendsBox(SpreadBox):
+class FriendsBox(hippo.CanvasBox):
__gtype_name__ = 'SugarFriendsBox'
def __init__(self, shell):
- SpreadBox.__init__(self, background_color=0xe2e2e2ff)
+ hippo.CanvasBox.__init__(self, background_color=0xe2e2e2ff)
self._shell = shell
self._friends = {}
+ self._layout = SpreadLayout()
+ self.set_layout(self._layout)
+
self._my_icon = MyIcon(units.LARGE_ICON_SCALE)
- self.set_center_item(self._my_icon)
+ self._layout.add_center(self._my_icon)
friends = self._shell.get_model().get_friends()
@@ -45,7 +48,7 @@ class FriendsBox(SpreadBox):
def add_friend(self, buddy_info):
icon = FriendView(self._shell, buddy_info)
- self.add_item(icon)
+ self._layout.add(icon)
self._friends[buddy_info.get_key()] = icon
@@ -53,5 +56,5 @@ class FriendsBox(SpreadBox):
self.add_friend(buddy_info)
def _friend_removed_cb(self, data_model, key):
- self.remove_item(self._friends[key])
+ self._layout.remove(self._friends[key])
del self._friends[key]
diff --git a/shell/view/home/MeshBox.py b/shell/view/home/MeshBox.py
index a6c093e..bb47f79 100644
--- a/shell/view/home/MeshBox.py
+++ b/shell/view/home/MeshBox.py
@@ -215,8 +215,8 @@ class MeshBox(hippo.CanvasBox):
self._buddy_to_activity = {}
self._suspended = True
- self.layout = SpreadLayout()
- self.set_layout(self.layout)
+ self._layout = SpreadLayout()
+ self.set_layout(self._layout)
for buddy_model in self._model.get_buddies():
self._add_alone_buddy(buddy_model)
@@ -280,26 +280,26 @@ class MeshBox(hippo.CanvasBox):
if not mesh:
return
self._mesh = MeshDeviceView(mesh)
- self.layout.add(self._mesh)
+ self._layout.add(self._mesh)
def _remove_mesh(self):
if not self._mesh:
return
- self.layout.remove(self._mesh)
+ self._layout.remove(self._mesh)
self._mesh = None
def _add_alone_buddy(self, buddy_model):
icon = BuddyIcon(self._shell, buddy_model)
if buddy_model.is_owner():
- self.layout.add_center(icon)
+ self._layout.add_center(icon)
else:
- self.layout.add(icon)
+ self._layout.add(icon)
self._buddies[buddy_model.get_key()] = icon
def _remove_alone_buddy(self, buddy_model):
icon = self._buddies[buddy_model.get_key()]
- self.layout.remove(icon)
+ self._layout.remove(icon)
del self._buddies[buddy_model.get_key()]
def _remove_buddy(self, buddy_model):
@@ -326,24 +326,24 @@ class MeshBox(hippo.CanvasBox):
def _add_activity(self, activity_model):
icon = ActivityView(self._shell, activity_model)
- self.layout.add(icon)
+ self._layout.add(icon)
self._activities[activity_model.get_id()] = icon
def _remove_activity(self, activity_model):
icon = self._activities[activity_model.get_id()]
- self.layout.remove(icon)
+ self._layout.remove(icon)
del self._activities[activity_model.get_id()]
def _add_access_point(self, ap_model):
icon = AccessPointView(ap_model)
- self.layout.add(icon)
+ self._layout.add(icon)
self._access_points[ap_model.get_id()] = icon
def _remove_access_point(self, ap_model):
icon = self._access_points[ap_model.get_id()]
- self.layout.remove(icon)
+ self._layout.remove(icon)
del self._access_points[ap_model.get_id()]
def suspend(self):
diff --git a/shell/view/home/transitionbox.py b/shell/view/home/transitionbox.py
index 3d83347..1dd1d4d 100644
--- a/shell/view/home/transitionbox.py
+++ b/shell/view/home/transitionbox.py
@@ -19,7 +19,7 @@ import gobject
from sugar.graphics import units
from sugar.graphics import animator
-from sugar.graphics.spreadbox import SpreadBox
+from sugar.graphics.spreadlayout import SpreadLayout
from view.home.MyIcon import MyIcon
@@ -35,7 +35,7 @@ class _Animation(animator.Animation):
d = (self.end_scale - self.start_scale) * current
self._icon.props.scale = self.start_scale + d
-class TransitionBox(SpreadBox):
+class TransitionBox(hippo.CanvasBox):
__gtype_name__ = 'SugarTransitionBox'
__gsignals__ = {
@@ -44,12 +44,15 @@ class TransitionBox(SpreadBox):
}
def __init__(self):
- SpreadBox.__init__(self, background_color=0xe2e2e2ff)
+ hippo.CanvasBox.__init__(self, background_color=0xe2e2e2ff)
self._scale = units.XLARGE_ICON_SCALE
+ self._layout = SpreadLayout()
+ self.set_layout(self._layout)
+
self._my_icon = MyIcon(self._scale)
- self.set_center_item(self._my_icon)
+ self._layout.add_center(self._my_icon)
self._animator = animator.Animator(0.3)
self._animator.connect('completed', self._animation_completed_cb)
diff --git a/sugar/graphics/spreadlayout.py b/sugar/graphics/spreadlayout.py
index d85e69b..ad2a163 100644
--- a/sugar/graphics/spreadlayout.py
+++ b/sugar/graphics/spreadlayout.py
@@ -82,7 +82,11 @@ class _Grid(gobject.GObject):
self._add_weight(child.grid_rect)
def _move_child(self, child, new_rect):
+ self._remove_weight(child.grid_rect)
+ self._add_weight(new_rect)
+
child.grid_rect = new_rect
+
self.emit('child-changed', child)
def _shift_child(self, child):
@@ -128,14 +132,20 @@ class _Grid(gobject.GObject):
return (len(self._collisions) > 0)
def _detect_collisions(self, child):
+ collision_found = False
for c in self._children:
intersection = child.grid_rect.intersect(c.grid_rect)
if c != child and intersection.width > 0:
if c not in self._collisions:
+ collision_found = True
self._collisions.append(c)
- if not self._collisions_sid:
- self._collisions_sid = \
- gobject.idle_add(self._solve_collisions)
+
+ if collision_found:
+ if child not in self._collisions:
+ self._collisions.append(child)
+
+# if len(self._collisions) and not self._collisions_sid:
+# self._collisions_sid = gobject.idle_add(self._solve_collisions)
def _add_weight(self, rect):
for i in range(rect.x, rect.x + rect.width):
@@ -153,7 +163,7 @@ class _Grid(gobject.GObject):
for i in range(rect.x, rect.x + rect.width):
for j in range(rect.y, rect.y + rect.height):
weight += self[j, i]
-
+
return weight
def __getitem__(self, (row, col)):
diff --git a/tests/test-spread-layout.py b/tests/test-spread-layout.py
index 9ff964f..59b2875 100755
--- a/tests/test-spread-layout.py
+++ b/tests/test-spread-layout.py
@@ -56,6 +56,6 @@ canvas.set_root(box)
window.add(canvas)
canvas.show()
-gobject.timeout_add(100, _create_icon)
+gobject.timeout_add(200, _create_icon)
gtk.main()