Spread box cleanups and fixes
This commit is contained in:
parent
55f82602c4
commit
8c3ac8960f
@ -29,8 +29,6 @@ class FriendsBox(SpreadBox, hippo.CanvasItem):
|
|||||||
friends.connect('friend-added', self._friend_added_cb)
|
friends.connect('friend-added', self._friend_added_cb)
|
||||||
friends.connect('friend-removed', self._friend_removed_cb)
|
friends.connect('friend-removed', self._friend_removed_cb)
|
||||||
|
|
||||||
gobject.idle_add(self.spread)
|
|
||||||
|
|
||||||
def add_friend(self, buddy_info):
|
def add_friend(self, buddy_info):
|
||||||
icon = FriendView(self._shell, self._menu_shell, buddy_info)
|
icon = FriendView(self._shell, self._menu_shell, buddy_info)
|
||||||
self.add(icon)
|
self.add(icon)
|
||||||
|
@ -13,6 +13,9 @@ class HomeWindow(gtk.Window):
|
|||||||
gtk.Window.__init__(self)
|
gtk.Window.__init__(self)
|
||||||
self._shell = shell
|
self._shell = shell
|
||||||
|
|
||||||
|
self.set_default_size(gtk.gdk.screen_width(),
|
||||||
|
gtk.gdk.screen_height())
|
||||||
|
|
||||||
self.realize()
|
self.realize()
|
||||||
self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DESKTOP)
|
self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DESKTOP)
|
||||||
|
|
||||||
|
@ -65,8 +65,6 @@ class MeshBox(SpreadBox):
|
|||||||
self._model.connect('activity-added', self._activity_added_cb)
|
self._model.connect('activity-added', self._activity_added_cb)
|
||||||
self._model.connect('activity-removed', self._activity_removed_cb)
|
self._model.connect('activity-removed', self._activity_removed_cb)
|
||||||
|
|
||||||
gobject.idle_add(self.spread)
|
|
||||||
|
|
||||||
def _buddy_added_cb(self, model, buddy_model):
|
def _buddy_added_cb(self, model, buddy_model):
|
||||||
self._add_alone_buddy(buddy_model)
|
self._add_alone_buddy(buddy_model)
|
||||||
|
|
||||||
|
@ -19,21 +19,6 @@ class SpreadBox(hippo.CanvasBox, hippo.CanvasItem):
|
|||||||
def add(self, item):
|
def add(self, item):
|
||||||
self._items_to_position.append(item)
|
self._items_to_position.append(item)
|
||||||
self.append(item, hippo.PACK_FIXED)
|
self.append(item, hippo.PACK_FIXED)
|
||||||
if self._spread_on_add:
|
|
||||||
self.spread()
|
|
||||||
|
|
||||||
def spread(self):
|
|
||||||
self._spread_on_add = True
|
|
||||||
|
|
||||||
[width, height] = self.get_allocation()
|
|
||||||
for item in self._items_to_position:
|
|
||||||
x = int(random.random() * width)
|
|
||||||
y = int(random.random() * height)
|
|
||||||
|
|
||||||
[x, y] = self._clamp_position(item, x, y)
|
|
||||||
self.move(item, x, y)
|
|
||||||
|
|
||||||
self._items_to_position = []
|
|
||||||
|
|
||||||
def _get_distance(self, icon1, icon2):
|
def _get_distance(self, icon1, icon2):
|
||||||
[icon1_x, icon1_y] = self.get_position(icon1)
|
[icon1_x, icon1_y] = self.get_position(icon1)
|
||||||
@ -57,8 +42,7 @@ class SpreadBox(hippo.CanvasBox, hippo.CanvasItem):
|
|||||||
x = max(0, x)
|
x = max(0, x)
|
||||||
y = max(0, y)
|
y = max(0, y)
|
||||||
|
|
||||||
item_w = icon.get_width_request()
|
[item_w, item_h] = icon.get_request()
|
||||||
item_h = icon.get_height_request(item_w)
|
|
||||||
[box_w, box_h] = self.get_allocation()
|
[box_w, box_h] = self.get_allocation()
|
||||||
|
|
||||||
x = min(box_w - item_w, x)
|
x = min(box_w - item_w, x)
|
||||||
@ -94,6 +78,17 @@ class SpreadBox(hippo.CanvasBox, hippo.CanvasItem):
|
|||||||
def do_allocate(self, width, height):
|
def do_allocate(self, width, height):
|
||||||
hippo.CanvasBox.do_allocate(self, width, height)
|
hippo.CanvasBox.do_allocate(self, width, height)
|
||||||
|
|
||||||
|
for item in self._items_to_position:
|
||||||
|
[item_w, item_h] = item.get_request()
|
||||||
|
|
||||||
|
x = int(random.random() * width - item_w)
|
||||||
|
y = int(random.random() * height - item_h)
|
||||||
|
|
||||||
|
[x, y] = self._clamp_position(item, x, y)
|
||||||
|
self.move(item, x, y)
|
||||||
|
|
||||||
|
self._items_to_position = []
|
||||||
|
|
||||||
tries = 10
|
tries = 10
|
||||||
self._spread_icons()
|
self._spread_icons()
|
||||||
while not self._stable and tries > 0:
|
while not self._stable and tries > 0:
|
||||||
|
@ -25,7 +25,7 @@ def _create_icon():
|
|||||||
icon_name='stock-buddy')
|
icon_name='stock-buddy')
|
||||||
box.add(icon)
|
box.add(icon)
|
||||||
|
|
||||||
return (len(box.get_children()) < 20)
|
return (len(box.get_children()) < 15)
|
||||||
|
|
||||||
window = gtk.Window()
|
window = gtk.Window()
|
||||||
window.connect("destroy", lambda w: gtk.main_quit())
|
window.connect("destroy", lambda w: gtk.main_quit())
|
||||||
@ -35,10 +35,9 @@ canvas = hippo.Canvas()
|
|||||||
|
|
||||||
box = SpreadBox(background_color=0xe2e2e2ff)
|
box = SpreadBox(background_color=0xe2e2e2ff)
|
||||||
canvas.set_root(box)
|
canvas.set_root(box)
|
||||||
box.spread()
|
|
||||||
|
|
||||||
canvas.show()
|
|
||||||
window.add(canvas)
|
window.add(canvas)
|
||||||
|
canvas.show()
|
||||||
|
|
||||||
gobject.timeout_add(500, _create_icon)
|
gobject.timeout_add(500, _create_icon)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user