2006-08-29 16:07:23 +02:00
|
|
|
import random
|
|
|
|
|
|
|
|
class IconLayout:
|
2006-09-24 22:55:13 +02:00
|
|
|
def __init__(self, grid):
|
2006-08-29 16:07:23 +02:00
|
|
|
self._icons = []
|
2006-09-24 22:55:13 +02:00
|
|
|
self._grid = grid
|
2006-08-29 16:07:23 +02:00
|
|
|
|
|
|
|
def add_icon(self, icon):
|
|
|
|
self._icons.append(icon)
|
|
|
|
self._layout_icon(icon)
|
|
|
|
|
|
|
|
def remove_icon(self, icon):
|
|
|
|
self._icons.remove(icon)
|
|
|
|
|
|
|
|
def _layout_icon(self, icon):
|
2006-09-24 22:55:13 +02:00
|
|
|
[x1, y1] = self._grid.convert_to_canvas(1, 1)
|
|
|
|
[x2, y2] = self._grid.convert_to_canvas(78, 59)
|
|
|
|
size = icon.props.size
|
|
|
|
|
|
|
|
x = random.random() * (x2 - x1 - size)
|
|
|
|
y = random.random() * (y2 - y1 - size)
|
2006-08-29 16:07:23 +02:00
|
|
|
|
2006-09-24 22:55:13 +02:00
|
|
|
icon.props.x = x + x1
|
|
|
|
icon.props.y = y + y1
|