Complete transition to new spread layout.

This commit is contained in:
Marco Pesenti Gritti 2007-07-06 00:46:12 +02:00
parent cc11d5ebd5
commit f1ecb99207
5 changed files with 42 additions and 26 deletions

View File

@ -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]

View File

@ -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):

View File

@ -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)

View File

@ -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)):

View File

@ -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()