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 |
| 238 | if radius < _MAXIMUM_RADIUS: |
| 239 | self._spiral = False |
| 240 | self._icon_size = style.MEDIUM_ICON_SIZE |
| 241 | if self._spiral: |
| 242 | distance = style.STANDARD_ICON_SIZE + style.DEFAULT_SPACING |
| 243 | radius = children_count * distance / (2 * math.pi) |
| 244 | radius = max(radius, _MINIMUM_RADIUS) |
| 245 | if radius < _MAXIMUM_RADIUS: |
| 246 | self._spiral = False |
| 247 | self._icon_size = style.STANDARD_ICON_SIZE |
| 248 | else: |
| 249 | self._spiral = True |
| 250 | radius = _MAXIMUM_RADIUS |
| 251 | |
| 252 | # If there are fewer children, try increasing icon_size. |
| 253 | if self._count > children_count: |
| 254 | if self._icon_size == style.SMALL_ICON_SIZE: |
| 255 | self._icon_size = _INTERMEDIATE |
| 256 | elif self._icon_size == _INTERMEDIATE: |
| 257 | self._icon_size = style.STANDARD_ICON_SIZE |
| 258 | elif self._icon_size == style.STANDARD_ICON_SIZE: |
| 259 | self._icon_size = style.MEDIUM_ICON_SIZE |
| 260 | self._count = children_count |
| 261 | |
| 262 | # If the radius exceeds the minimun, try decreasing icon_size. |
| 263 | if self._radius < _MINIMUM_RADIUS: |
| 264 | if self._icon_size == style.STANDARD_ICON_SIZE: |
| 265 | self._icon_size = _INTERMEDIATE |
| 266 | elif self._icon_size == _INTERMEDIATE: |
| 267 | self._icon_size = style.SMALL_ICON_SIZE |
| 268 | |
| 269 | return radius, self._icon_size |
| 270 | |
| 271 | def _calculate_xy(self, icon_size, width, height): |
| 272 | """ Convert r, o to x, y """ |
| 273 | x = -math.sin(self._orientation) * self._radius |
| 274 | y = math.cos(self._orientation) * self._radius |
| 275 | self._calculate_new_radius_orientation(icon_size +\ |
| 276 | style.DEFAULT_SPACING) |
| 277 | |
| 278 | x = int(x) + (width - icon_size) / 2 |
| 279 | y = int(y) + (height - icon_size - (style.GRID_CELL_SIZE / 2) ) / 2 |
| 280 | return x, y |
| 281 | |
| 282 | def _calculate_new_radius_orientation(self, icon_size): |
| 283 | """ Based upon current radius, calculate new increments """ |
| 284 | circumference = self._radius * 2 * math.pi |
| 285 | n = circumference / icon_size |
| 286 | self._orientation += 2 * math.pi / n |
| 287 | 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 |
| 294 | if not self._spiral: |
| 295 | angle = index * (2 * math.pi / children_count) - math.pi / 2 |
| 296 | x = radius * cos(angle) + (width - icon_size) / 2 |
| 297 | y = radius * sin(angle) + (height - icon_size - |
| 298 | (style.GRID_CELL_SIZE/2) ) / 2 |
| 299 | else: |
| 300 | min_width_, box_width = self.box.get_width_request() |
| 301 | min_height_, box_height = self.box.get_height_request(box_width) |
| 302 | if index == 0: |
| 303 | self._radius = _MAXIMUM_RADIUS |
| 304 | self._orientation = math.pi |
| 305 | x, y = self._calculate_xy(icon_size, width, height) |
| 306 | |