Some cleanups of the IconLayout

This commit is contained in:
Marco Pesenti Gritti 2006-09-24 22:55:13 +02:00
parent eac58dcfed
commit 3f73da0549
5 changed files with 20 additions and 25 deletions

View File

@ -12,7 +12,7 @@ class FriendsGroup(goocanvas.Group):
self._shell = shell self._shell = shell
self._menu_shell = menu_shell self._menu_shell = menu_shell
self._icon_layout = IconLayout(1200, 900) self._icon_layout = IconLayout(shell.get_grid())
self._friends = {} self._friends = {}
me = MyIcon(112) me = MyIcon(112)

View File

@ -1,10 +1,9 @@
import random import random
class IconLayout: class IconLayout:
def __init__(self, width, height): def __init__(self, grid):
self._icons = [] self._icons = []
self._width = width self._grid = grid
self._height = height
def add_icon(self, icon): def add_icon(self, icon):
self._icons.append(icon) self._icons.append(icon)
@ -13,22 +12,13 @@ class IconLayout:
def remove_icon(self, icon): def remove_icon(self, icon):
self._icons.remove(icon) self._icons.remove(icon)
def _is_valid_position(self, icon, x, y):
icon_size = icon.props.size
border = 20
if not (border < x < self._width - icon_size - border and \
border < y < self._height - icon_size - border):
return False
return True
def _layout_icon(self, icon): def _layout_icon(self, icon):
while True: [x1, y1] = self._grid.convert_to_canvas(1, 1)
x = random.random() * self._width [x2, y2] = self._grid.convert_to_canvas(78, 59)
y = random.random() * self._height size = icon.props.size
if self._is_valid_position(icon, x, y):
break
icon.props.x = x x = random.random() * (x2 - x1 - size)
icon.props.y = y y = random.random() * (y2 - y1 - size)
icon.props.x = x + x1
icon.props.y = y + y1

View File

@ -37,7 +37,7 @@ class MeshGroup(goocanvas.Group):
self._shell = shell self._shell = shell
self._icon_layout = IconLayout(1200, 900) self._icon_layout = IconLayout(shell.get_grid())
self._activities = {} self._activities = {}
self._pservice = PresenceService.get_instance() self._pservice = PresenceService.get_instance()

View File

@ -31,6 +31,10 @@ class Grid:
return [grid_x, grid_y] return [grid_x, grid_y]
def convert_to_canvas(self, grid_x, grid_y):
scale = 1200 / Grid.COLS
return [grid_x * scale, grid_y * scale]
def set_constraints(self, component, x, y, width=-1, height=-1): def set_constraints(self, component, x, y, width=-1, height=-1):
if isinstance(component, gtk.Window): if isinstance(component, gtk.Window):
self._layout_window(component, x, y, width, height) self._layout_window(component, x, y, width, height)

View File

@ -17,6 +17,7 @@ from view.home.IconLayout import IconLayout
from sugar.canvas import IconColor from sugar.canvas import IconColor
from sugar.canvas.IconItem import IconItem from sugar.canvas.IconItem import IconItem
from sugar.canvas.CanvasView import CanvasView from sugar.canvas.CanvasView import CanvasView
from sugar.canvas.Grid import Grid
window = gtk.Window() window = gtk.Window()
window.connect("destroy", lambda w: gtk.main_quit()) window.connect("destroy", lambda w: gtk.main_quit())
@ -33,12 +34,12 @@ item = goocanvas.Rect(x=0, y=0, width=1200, height=900,
line_width=0.0, fill_color='#e2e2e2') line_width=0.0, fill_color='#e2e2e2')
root.add_child(item) root.add_child(item)
icon_layout = IconLayout(1200, 900) icon_layout = IconLayout(Grid())
for i in range(0, 20): for i in range(0, 200):
color = IconColor.IconColor() color = IconColor.IconColor()
icon = IconItem(size=75, color=color, icon = IconItem(size=125, color=color,
icon_name='stock-buddy') icon_name='stock-buddy')
root.add_child(icon) root.add_child(icon)