230 | | # limit computed radius to reasonable bounds. |
231 | | radius = max(radius, _MINIMUM_RADIUS) |
232 | | radius = min(radius, _MAXIMUM_RADIUS) |
233 | | # recompute icon size from limited radius |
234 | | if children_count > 0: |
235 | | icon_size = (2 * math.pi * radius / children_count) \ |
236 | | - style.DEFAULT_SPACING |
237 | | # limit adjusted icon size. |
238 | | icon_size = max(icon_size, style.SMALL_ICON_SIZE) |
239 | | icon_size = min(icon_size, style.MEDIUM_ICON_SIZE) |
240 | | return radius, icon_size |
| 235 | if radius < _MAXIMUM_RADIUS: |
| 236 | self._spiral = False |
| 237 | self._icon_size = style.STANDARD_ICON_SIZE |
| 238 | else: |
| 239 | self._spiral = True |
| 240 | radius = _MAXIMUM_RADIUS |
| 241 | |
| 242 | # If there are fewer children, try increasing icon_size. |
| 243 | if self._count > children_count: |
| 244 | if self._icon_size == style.SMALL_ICON_SIZE: |
| 245 | self._icon_size = _INTERMEDIATE |
| 246 | elif self._icon_size == _INTERMEDIATE: |
| 247 | self._icon_size = style.STANDARD_ICON_SIZE |
| 248 | self._count = children_count |
| 249 | |
| 250 | if self._radius < _MINIMUM_RADIUS: |
| 251 | if self._icon_size == style.STANDARD_ICON_SIZE: |
| 252 | self._icon_size = _INTERMEDIATE |
| 253 | elif self._icon_size == _INTERMEDIATE: |
| 254 | self._icon_size = style.SMALL_ICON_SIZE |
| 255 | |
| 256 | return radius, self._icon_size |
| 257 | |
| 258 | def _calculate_xy(self, icon_size, width, height): |
| 259 | """ Convert r, o to x, y """ |
| 260 | x = -math.sin(self._orientation) * self._radius |
| 261 | y = math.cos(self._orientation) * self._radius |
| 262 | self._calculate_new_radius_orientation(icon_size +\ |
| 263 | style.DEFAULT_SPACING) |
| 264 | |
| 265 | x = int(x) + (width - icon_size) / 2 |
| 266 | y = int(y) + (height - icon_size - (style.GRID_CELL_SIZE / 2) ) / 2 |
| 267 | return x, y |
| 268 | |
| 269 | def _calculate_new_radius_orientation(self, icon_size): |
| 270 | """ Based upon current radius, calculate new increments """ |
| 271 | circumference = self._radius * 2 * math.pi |
| 272 | n = circumference / icon_size |
| 273 | self._orientation += 2 * math.pi / n |
| 274 | self._radius -= float(icon_size) / n |
245 | | angle = index * (2 * math.pi / children_count) - math.pi / 2 |
246 | | x = radius * cos(angle) + (width - icon_size) / 2 |
247 | | y = radius * sin(angle) + (height - icon_size - |
248 | | (style.GRID_CELL_SIZE/2) ) / 2 |
| 281 | if not self._spiral: |
| 282 | angle = index * (2 * math.pi / children_count) - math.pi / 2 |
| 283 | x = radius * cos(angle) + (width - icon_size) / 2 |
| 284 | y = radius * sin(angle) + (height - icon_size - |
| 285 | (style.GRID_CELL_SIZE/2) ) / 2 |
| 286 | else: |
| 287 | min_width_, box_width = self.box.get_width_request() |
| 288 | min_height_, box_height = self.box.get_height_request(box_width) |
| 289 | if index == 0: |
| 290 | self._radius = _MAXIMUM_RADIUS |
| 291 | self._orientation = math.pi |
| 292 | x, y = self._calculate_xy(icon_size, width, height) |
| 293 | |