Line 131: |
Line 131: |
| self.my_orientation += 2 * math.pi / n | | self.my_orientation += 2 * math.pi / n |
| self.my_radius += float(icon_size) / n | | self.my_radius += float(icon_size) / n |
| + | </code> |
| + | |
| + | This version inherits from RandomLayout and lets you rearrange the icons. |
| + | |
| + | <code> |
| + | class MyLayout(RandomLayout): |
| + | """Spiral layout based on Archimedean spiral: r = a + b*theta.""" |
| + | |
| + | __gtype_name__ = 'MyLayout' |
| + | |
| + | icon_name = 'view-mylayout' |
| + | """Name of icon used in home view dropdown palette.""" |
| + | |
| + | profile_key = 'my-layout' |
| + | """String used in profile to represent this view.""" |
| + | |
| + | def __init__(self): |
| + | RandomLayout.__init__(self) |
| + | self.my_radius = _MINIMUM_RADIUS |
| + | self.my_orientation = math.pi |
| + | |
| + | def _calculate_radius_and_icon_size(self, children_count): |
| + | """Stub out this method; not used in `My Layout`.""" |
| + | return _MINIMUM_RADIUS, style.STANDARD_ICON_SIZE |
| + | |
| + | def _calculate_position(self, icon_size): |
| + | """ Increment the radius as you go """ |
| + | x, y = self._calculate_xy() |
| + | |
| + | # add some buffering around the icon |
| + | self._calculate_new_radius_orientation(icon_size + 10) |
| + | |
| + | width, height = self.box.get_allocation() |
| + | return int(x) + (width - icon_size) / 2, \ |
| + | int(y) + (height - icon_size - (style.GRID_CELL_SIZE / 2) ) / 2 |
| + | |
| + | def _calculate_xy(self): |
| + | """ Convert r, o to x, y """ |
| + | return -math.sin(self.my_orientation) * self.my_radius, \ |
| + | math.cos(self.my_orientation) * self.my_radius |
| + | |
| + | def _calculate_new_radius_orientation(self, icon_size): |
| + | """ Based upon current radius, calculate new increments """ |
| + | circumference = self.my_radius * 2 * math.pi |
| + | n = circumference / icon_size |
| + | self.my_orientation += 2 * math.pi / n |
| + | self.my_radius += float(icon_size) / n |
| + | |
| + | def append(self, icon, locked=False): |
| + | """ Instead of assigning the position based on a hash, use spiral """ |
| + | FavoritesLayout.append(self, icon, locked) |
| + | |
| + | min_width_, child_width = icon.get_width_request() |
| + | min_height_, child_height = icon.get_height_request(child_width) |
| + | min_width_, width = self.box.get_width_request() |
| + | min_height_, height = self.box.get_height_request(width) |
| + | |
| + | if icon in self.fixed_positions: |
| + | x, y = self.fixed_positions[icon] |
| + | x = min(x, width - child_width) |
| + | y = min(y, height - child_height) |
| + | else: |
| + | x, y = self._calculate_position(child_width) |
| + | |
| + | if x is None or y is None: |
| + | self._grid.add(icon, |
| + | child_width / _CELL_SIZE, child_height / _CELL_SIZE) |
| + | else: |
| + | self._grid.add(icon, |
| + | child_width / _CELL_SIZE, child_height / _CELL_SIZE, |
| + | x / _CELL_SIZE, y / _CELL_SIZE) |
| </code> | | </code> |
| | | |