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 |
| 243 | if radius < _MAXIMUM_RADIUS: |
| 244 | self._spiral = False |
| 245 | self._icon_size = style.MEDIUM_ICON_SIZE |
| 246 | if self._spiral: |
| 247 | distance = style.STANDARD_ICON_SIZE + style.DEFAULT_SPACING |
| 248 | radius = children_count * distance / (2 * math.pi) |
| 249 | radius = max(radius, _MINIMUM_RADIUS) |
| 250 | if radius < _MAXIMUM_RADIUS: |
| 251 | self._spiral = False |
| 252 | self._icon_size = style.STANDARD_ICON_SIZE |
| 253 | else: |
| 254 | self._spiral = True |
| 255 | radius = _MAXIMUM_RADIUS |
| 256 | |
| 257 | # If there are fewer children, try increasing icon_size. |
| 258 | if self._count > children_count: |
| 259 | if self._icon_size == style.SMALL_ICON_SIZE: |
| 260 | self._icon_size = _INTERMEDIATE_C |
| 261 | elif self._icon_size == _INTERMEDIATE_C: |
| 262 | self._icon_size = _INTERMEDIATE_B |
| 263 | elif self._icon_size == _INTERMEDIATE_B: |
| 264 | self._icon_size = _INTERMEDIATE_A |
| 265 | elif self._icon_size == _INTERMEDIATE_A: |
| 266 | self._icon_size = style.STANDARD_ICON_SIZE |
| 267 | elif self._icon_size == style.STANDARD_ICON_SIZE: |
| 268 | self._icon_size = style.MEDIUM_ICON_SIZE |
| 269 | self._count = children_count |
| 270 | |
| 271 | # If the radius exceeds the minimun, try decreasing icon_size. |
| 272 | if self._radius < _MINIMUM_RADIUS: |
| 273 | if self._icon_size == style.MEDIUM_ICON_SIZE: |
| 274 | self._icon_size = style.STANDARD_ICON_SIZE |
| 275 | elif self._icon_size == style.STANDARD_ICON_SIZE: |
| 276 | self._icon_size = _INTERMEDIATE_A |
| 277 | elif self._icon_size == _INTERMEDIATE_A: |
| 278 | self._icon_size = _INTERMEDIATE_B |
| 279 | elif self._icon_size == _INTERMEDIATE_B: |
| 280 | self._icon_size = _INTERMEDIATE_C |
| 281 | elif self._icon_size == _INTERMEDIATE_C: |
| 282 | self._icon_size = style.SMALL_ICON_SIZE |
| 283 | print ">>>>>>>>>>>>>> setting icon sixe to %d" % (self._icon_size) |
| 284 | |
| 285 | return radius, self._icon_size |
| 286 | |
| 287 | def _calculate_xy(self, icon_size, width, height): |
| 288 | """ Convert r, o to x, y """ |
| 289 | x = -math.sin(self._orientation) * self._radius |
| 290 | y = math.cos(self._orientation) * self._radius |
| 291 | self._calculate_new_radius_orientation(icon_size +\ |
| 292 | style.DEFAULT_SPACING) |
| 293 | |
| 294 | x = int(x) + (width - icon_size) / 2 |
| 295 | y = int(y) + (height - icon_size - (style.GRID_CELL_SIZE / 2) ) / 2 |
| 296 | return x, y |
| 297 | |
| 298 | def _calculate_new_radius_orientation(self, icon_size): |
| 299 | """ Based upon current radius, calculate new increments """ |
| 300 | circumference = self._radius * 2 * math.pi |
| 301 | n = circumference / icon_size |
| 302 | self._orientation += 2 * math.pi / n |
| 303 | self._radius -= float(icon_size + style.DEFAULT_SPACING) / 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 |
| 310 | if not self._spiral: |
| 311 | angle = index * (2 * math.pi / children_count) - math.pi / 2 |
| 312 | x = radius * cos(angle) + (width - icon_size) / 2 |
| 313 | y = radius * sin(angle) + (height - icon_size - |
| 314 | (style.GRID_CELL_SIZE/2) ) / 2 |
| 315 | else: |
| 316 | min_width_, box_width = self.box.get_width_request() |
| 317 | min_height_, box_height = self.box.get_height_request(box_width) |
| 318 | if index == 0: |
| 319 | self._radius = _MAXIMUM_RADIUS |
| 320 | self._orientation = math.pi |
| 321 | x, y = self._calculate_xy(icon_size, width, height) |
| 322 | |