Always center the owner in the home views
This commit is contained in:
parent
b2e0f257ce
commit
5bfc64d9be
@ -84,6 +84,11 @@ class BuddyModel(gobject.GObject):
|
|||||||
def get_buddy(self):
|
def get_buddy(self):
|
||||||
return self._buddy
|
return self._buddy
|
||||||
|
|
||||||
|
def is_owner(self):
|
||||||
|
if not self._buddy:
|
||||||
|
return False
|
||||||
|
return self._buddy.props.owner
|
||||||
|
|
||||||
def is_present(self):
|
def is_present(self):
|
||||||
if self._buddy:
|
if self._buddy:
|
||||||
return True
|
return True
|
||||||
|
@ -24,7 +24,7 @@ from sugar.graphics import units
|
|||||||
from view.home.MyIcon import MyIcon
|
from view.home.MyIcon import MyIcon
|
||||||
from view.home.FriendView import FriendView
|
from view.home.FriendView import FriendView
|
||||||
|
|
||||||
class FriendsBox(SpreadBox, hippo.CanvasItem):
|
class FriendsBox(SpreadBox):
|
||||||
__gtype_name__ = 'SugarFriendsBox'
|
__gtype_name__ = 'SugarFriendsBox'
|
||||||
def __init__(self, shell, menu_shell):
|
def __init__(self, shell, menu_shell):
|
||||||
SpreadBox.__init__(self, background_color=0xe2e2e2ff)
|
SpreadBox.__init__(self, background_color=0xe2e2e2ff)
|
||||||
@ -34,7 +34,7 @@ class FriendsBox(SpreadBox, hippo.CanvasItem):
|
|||||||
self._friends = {}
|
self._friends = {}
|
||||||
|
|
||||||
self._my_icon = MyIcon(units.LARGE_ICON_SCALE)
|
self._my_icon = MyIcon(units.LARGE_ICON_SCALE)
|
||||||
self.append(self._my_icon, hippo.PACK_FIXED)
|
self.set_center_item(self._my_icon)
|
||||||
|
|
||||||
friends = self._shell.get_model().get_friends()
|
friends = self._shell.get_model().get_friends()
|
||||||
|
|
||||||
@ -56,10 +56,3 @@ class FriendsBox(SpreadBox, hippo.CanvasItem):
|
|||||||
def _friend_removed_cb(self, data_model, key):
|
def _friend_removed_cb(self, data_model, key):
|
||||||
self.remove_item(self._friends[key])
|
self.remove_item(self._friends[key])
|
||||||
del self._friends[key]
|
del self._friends[key]
|
||||||
|
|
||||||
def do_allocate(self, width, height, origin_changed):
|
|
||||||
SpreadBox.do_allocate(self, width, height, origin_changed)
|
|
||||||
|
|
||||||
[icon_width, icon_height] = self._my_icon.get_allocation()
|
|
||||||
self.set_position(self._my_icon, (width - icon_width) / 2,
|
|
||||||
(height - icon_height) / 2)
|
|
||||||
|
@ -278,7 +278,10 @@ class MeshBox(SpreadBox):
|
|||||||
|
|
||||||
def _add_alone_buddy(self, buddy_model):
|
def _add_alone_buddy(self, buddy_model):
|
||||||
icon = BuddyIcon(self._shell, self._menu_shell, buddy_model)
|
icon = BuddyIcon(self._shell, self._menu_shell, buddy_model)
|
||||||
self.add_item(icon)
|
if buddy_model.is_owner():
|
||||||
|
self.set_center_item(icon)
|
||||||
|
else:
|
||||||
|
self.add_item(icon)
|
||||||
|
|
||||||
self._buddies[buddy_model.get_key()] = icon
|
self._buddies[buddy_model.get_key()] = icon
|
||||||
|
|
||||||
|
@ -22,20 +22,31 @@ import gtk
|
|||||||
|
|
||||||
from sugar.graphics import units
|
from sugar.graphics import units
|
||||||
|
|
||||||
|
_WIDTH = gtk.gdk.screen_width()
|
||||||
|
_HEIGHT = gtk.gdk.screen_height()
|
||||||
_CELL_WIDTH = units.grid_to_pixels(1)
|
_CELL_WIDTH = units.grid_to_pixels(1)
|
||||||
_CELL_HEIGHT = units.grid_to_pixels(1)
|
_CELL_HEIGHT = units.grid_to_pixels(1)
|
||||||
_GRID_WIDTH = gtk.gdk.screen_width() / _CELL_WIDTH
|
_GRID_WIDTH = _WIDTH / _CELL_WIDTH
|
||||||
_GRID_HEIGHT = gtk.gdk.screen_height() / _CELL_HEIGHT
|
_GRID_HEIGHT = _HEIGHT / _CELL_HEIGHT
|
||||||
|
|
||||||
class SpreadBox(hippo.CanvasBox):
|
class SpreadBox(hippo.CanvasBox, hippo.CanvasItem):
|
||||||
|
__gtype_name__ = 'SugarSpreadBox'
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
hippo.CanvasBox.__init__(self, **kwargs)
|
hippo.CanvasBox.__init__(self, **kwargs)
|
||||||
|
|
||||||
self._grid = []
|
self._grid = []
|
||||||
|
self._center = None
|
||||||
|
|
||||||
for i in range(0, _GRID_WIDTH * _GRID_HEIGHT):
|
for i in range(0, _GRID_WIDTH * _GRID_HEIGHT):
|
||||||
self._grid.append(None)
|
self._grid.append(None)
|
||||||
|
|
||||||
|
def set_center_item(self, item):
|
||||||
|
if self._center:
|
||||||
|
self.remove(self._center)
|
||||||
|
|
||||||
|
self._center = item
|
||||||
|
self.append(item, hippo.PACK_FIXED)
|
||||||
|
|
||||||
def add_item(self, item):
|
def add_item(self, item):
|
||||||
start_pos = int(random.random() * len(self._grid))
|
start_pos = int(random.random() * len(self._grid))
|
||||||
|
|
||||||
@ -60,3 +71,11 @@ class SpreadBox(hippo.CanvasBox):
|
|||||||
if self._grid[i] == item:
|
if self._grid[i] == item:
|
||||||
self._grid[i] = None
|
self._grid[i] = None
|
||||||
self.remove(item)
|
self.remove(item)
|
||||||
|
|
||||||
|
def do_allocate(self, width, height, origin_changed):
|
||||||
|
hippo.CanvasBox.do_allocate(self, width, height, origin_changed)
|
||||||
|
|
||||||
|
if self._center:
|
||||||
|
[icon_width, icon_height] = self._center.get_allocation()
|
||||||
|
self.set_position(self._center, (width - icon_width) / 2,
|
||||||
|
(height - icon_height) / 2)
|
||||||
|
Loading…
Reference in New Issue
Block a user