Keep the icon layout updated when adding buddies to the snow flake
This commit is contained in:
parent
9619921735
commit
5b3eeb0a9c
@ -17,10 +17,12 @@ class IconLayout:
|
||||
def add_icon(self, icon):
|
||||
self._icons.append(icon)
|
||||
self._layout_icon(icon)
|
||||
self.update()
|
||||
|
||||
def remove_icon(self, icon):
|
||||
self._icons.remove(icon)
|
||||
del self._constraints[icon]
|
||||
self.update()
|
||||
|
||||
def _get_distance(self, icon1, icon2):
|
||||
[icon1_x, icon1_y] = self._constraints[icon1]
|
||||
@ -74,15 +76,16 @@ class IconLayout:
|
||||
matrix.translate(new_x, new_y)
|
||||
icon1.set_transform(matrix)
|
||||
|
||||
def update(self):
|
||||
tries = 10
|
||||
self._spread_icons()
|
||||
while not self._stable and tries > 0:
|
||||
self._spread_icons()
|
||||
tries -= 1
|
||||
|
||||
def _layout_icon(self, icon):
|
||||
[width, height] = icon.get_size_request()
|
||||
x = random.random() * (self._x2 - self._x1 - width)
|
||||
y = random.random() * (self._y2 - self._y1 - height)
|
||||
|
||||
self._constraints[icon] = [x, y]
|
||||
|
||||
tries = 10
|
||||
self._spread_icons()
|
||||
while not self._stable and tries > 0:
|
||||
self._spread_icons()
|
||||
tries -= 1
|
||||
|
@ -110,6 +110,7 @@ class MeshGroup(goocanvas.Group):
|
||||
for activity in self._activities.values():
|
||||
if activity.has_buddy_icon(name):
|
||||
activity.remove_buddy_icon(name)
|
||||
self._layout.update()
|
||||
|
||||
def _move_buddy(self, buddy_model, activity_model):
|
||||
name = buddy_model.get_name()
|
||||
@ -125,6 +126,8 @@ class MeshGroup(goocanvas.Group):
|
||||
icon.props.size = 60
|
||||
activity.add_buddy_icon(buddy_model.get_name(), icon)
|
||||
|
||||
self._layout.update()
|
||||
|
||||
def _add_activity(self, activity_model):
|
||||
icon = ActivityView(self._shell, self._menu_shell, activity_model)
|
||||
self.add_child(icon)
|
||||
|
Loading…
Reference in New Issue
Block a user