diff options
author | Marco Pesenti Gritti <marco@localhost.localdomain> | 2006-09-25 09:35:30 (GMT) |
---|---|---|
committer | Marco Pesenti Gritti <marco@localhost.localdomain> | 2006-09-25 09:35:30 (GMT) |
commit | d5f8d62d35646466162592b6f9634529216fa25b (patch) | |
tree | 35637935e059ad0c5f27880f11a035b30ec6fe87 /shell | |
parent | 3e4c8cabc7b7f3304134295fb26bbeab7bd5f4e6 (diff) |
Add size request to BuddyActivityView and use it in IconLayout
Diffstat (limited to 'shell')
-rw-r--r-- | shell/view/BuddyActivityView.py | 50 | ||||
-rw-r--r-- | shell/view/home/IconLayout.py | 56 |
2 files changed, 45 insertions, 61 deletions
diff --git a/shell/view/BuddyActivityView.py b/shell/view/BuddyActivityView.py index 033bc02..f4d351a 100644 --- a/shell/view/BuddyActivityView.py +++ b/shell/view/BuddyActivityView.py @@ -8,16 +8,6 @@ import gobject class BuddyActivityView(goocanvas.Group): - __gproperties__ = { - 'x' : (float, None, None, -10e6, 10e6, 0, - gobject.PARAM_READWRITE), - 'y' : (float, None, None, -10e6, 10e6, 0, - gobject.PARAM_READWRITE), - 'size' : (float, None, None, - 0, 1024, 24, - gobject.PARAM_READABLE) - } - def __init__(self, shell, menu_shell, buddy, **kwargs): goocanvas.Group.__init__(self, **kwargs) @@ -25,12 +15,9 @@ class BuddyActivityView(goocanvas.Group): self._activity_registry = conf.get_activity_registry() self._buddy = buddy - self._x = 0 - self._y = 0 - self._buddy_icon = BuddyIcon.BuddyIcon(shell, menu_shell, buddy) self.add_child(self._buddy_icon) - self._activity_icon = IconItem(size=48) + self._activity_icon = IconItem(y=50, size=48) self._activity_icon_visible = False curact = self._buddy.get_current_activity() if curact: @@ -41,41 +28,14 @@ class BuddyActivityView(goocanvas.Group): self._buddy.connect('disappeared', self.__buddy_presence_change_cb) self._buddy.connect('color-changed', self.__buddy_presence_change_cb) - def do_set_property(self, pspec, value): - if pspec.name == 'x': - self._x = value - self._buddy_icon.props.x = value + 20 - self._activity_icon.props.x = value - elif pspec.name == 'y': - self._y = value - self._buddy_icon.props.y = value - self._activity_icon.props.y = value + 50 - - def do_get_property(self, pspec): - if pspec.name == 'x': - return self._x - elif pspec.name == 'y': - return self._y - elif pspec.name == 'size': - return self._recompute_size() - - def _recompute_size(self): + def get_size_request(self): bi_size = self._buddy_icon.props.size - bi_x = self._buddy_icon.props.x - bi_y = self._buddy_icon.props.y acti_size = self._activity_icon.props.size - acti_x = self._activity_icon.props.x - acti_y = self._activity_icon.props.y - # Union the two rectangles - dest_x = min(bi_x, acti_x) - dest_y = min(bi_y, acti_y) - dest_width = max(bi_x + bi_size, acti_x + acti_size) - dest_x - dest_height = max(bi_y + bi_size, acti_y + acti_size) - dest_y + width = bi_size + height = bi_size + acti_size - # IconLayout can't deal with rectangular sizes yet - dest_size = max(dest_width, dest_height) - return dest_size + return [width, height] def _get_new_icon_name(self, activity): # FIXME: do something better here; we probably need to use "flagship" diff --git a/shell/view/home/IconLayout.py b/shell/view/home/IconLayout.py index 6df1708..3c8cb1e 100644 --- a/shell/view/home/IconLayout.py +++ b/shell/view/home/IconLayout.py @@ -1,11 +1,14 @@ import random import math +import cairo + class IconLayout: DISTANCE_THRESHOLD = 120.0 def __init__(self, grid): self._icons = [] + self._constraints = {} self._grid = grid [self._x1, self._y1] = self._grid.convert_to_canvas(1, 1) @@ -17,12 +20,26 @@ class IconLayout: def remove_icon(self, icon): self._icons.remove(icon) + del self._constraints[icon] + + def _get_distance(self, icon1, icon2): + [icon1_x, icon1_y] = self._constraints[icon1] + [icon2_x, icon2_y] = self._constraints[icon2] + + a = icon1_x - icon2_x + b = icon1_y - icon2_y - def _distance(self, icon1, icon2): - a = icon2.props.x - icon1.props.x - b = icon2.props.y - icon1.props.y return math.sqrt(a * a + b * b) + def _get_repulsion(self, icon1, icon2): + [icon1_x, icon1_y] = self._constraints[icon1] + [icon2_x, icon2_y] = self._constraints[icon2] + + f_x = icon1_x - icon2_x + f_y = icon1_y - icon2_y + + return [f_x, f_y] + def _spread_icons(self): self._stable = True @@ -30,32 +47,39 @@ class IconLayout: vx = 0 vy = 0 + [x, y] = self._constraints[icon1] + for icon2 in self._icons: if icon1 != icon2: - distance = self._distance(icon1, icon2) + distance = self._get_distance(icon1, icon2) if distance <= IconLayout.DISTANCE_THRESHOLD: self._stable = False - vx += icon1.props.x - icon2.props.x - vy += icon1.props.y - icon2.props.y + [f_x, f_y] = self._get_repulsion(icon1, icon2) + vx += f_x + vy += f_y - new_x = icon1.props.x + vx - new_y = icon1.props.y + vy + new_x = x + vx + new_y = y + vy new_x = max(self._x1, new_x) new_y = max(self._y1, new_y) - new_x = min(self._x2 - icon1.props.size, new_x) - new_y = min(self._y2 - icon1.props.size, new_y) + [width, height] = icon1.get_size_request() + new_x = min(self._x2 - width, new_x) + new_y = min(self._y2 - height, new_y) + + self._constraints[icon1] = [new_x, new_y] - icon1.props.x = new_x - icon1.props.y = new_y + matrix = cairo.Matrix(1, 0, 0, 1, 0, 0) + matrix.translate(new_x, new_y) + icon1.set_transform(matrix) def _layout_icon(self, icon): - x = random.random() * (self._x2 - self._x1 - icon.props.size) - y = random.random() * (self._y2 - self._y1 - icon.props.size) + [width, height] = icon.get_size_request() + x = random.random() * (self._x2 - self._x1 - width) + y = random.random() * (self._y2 - self._y1 - height) - icon.props.x = x + self._x1 - icon.props.y = y + self._y1 + self._constraints[icon] = [x, y] tries = 10 self._spread_icons() |