Ticket #2235: 0001-updated-Ring-view-layout-details.patch

File 0001-updated-Ring-view-layout-details.patch, 7.8 KB (added by walter, 11 years ago)

first, apply layout changes to existing Ring

  • src/jarabe/desktop/favoriteslayout.py

    From 38a15ede4bcdb58e249771b15baa5a84672a2cd1 Mon Sep 17 00:00:00 2001
    From: Walter Bender <walter@sugarlabs.org>
    Date: Wed, 25 Aug 2010 09:39:51 -0400
    Subject: [PATCH 1/2] updated Ring view layout details
    
    ---
     src/jarabe/desktop/favoriteslayout.py |   99 ++++++++++-----------------------
     1 files changed, 30 insertions(+), 69 deletions(-)
    
    diff --git a/src/jarabe/desktop/favoriteslayout.py b/src/jarabe/desktop/favoriteslayout.py
    index 7b847ac..160ce0e 100644
    a b _logger = logging.getLogger('FavoritesLayout') 
    3333
    3434_CELL_SIZE = 4
    3535_BASE_SCALE = 1000
    36 _INTERMEDIATE_B = (style.STANDARD_ICON_SIZE + style.SMALL_ICON_SIZE) / 2
    37 _INTERMEDIATE_A = (style.STANDARD_ICON_SIZE + _INTERMEDIATE_B) / 2
    38 _INTERMEDIATE_C = (_INTERMEDIATE_B + style.SMALL_ICON_SIZE) / 2
    39 _ICON_SIZES = [style.MEDIUM_ICON_SIZE, style.STANDARD_ICON_SIZE,
    40                _INTERMEDIATE_A, _INTERMEDIATE_B, _INTERMEDIATE_C,
    41                style.SMALL_ICON_SIZE]
    42 
    4336
    4437class FavoritesLayout(gobject.GObject, hippo.CanvasLayout):
    4538    """Base class of the different layout types."""
    class RandomLayout(FavoritesLayout): 
    189182    def allow_dnd(self):
    190183        return True
    191184
     185
    192186_MINIMUM_RADIUS = style.XLARGE_ICON_SIZE / 2 + style.DEFAULT_SPACING + \
    193187        style.STANDARD_ICON_SIZE * 2
    194188_MAXIMUM_RADIUS = (gtk.gdk.screen_height() - style.GRID_CELL_SIZE) / 2 - \
    195189        style.STANDARD_ICON_SIZE - style.DEFAULT_SPACING
    196 _ICON_SPACING_FACTORS = [1.5, 1.4, 1.3, 1.2, 1.1, 1.0]
    197 _SPIRAL_SPACING_FACTORS = [1.5, 1.5, 1.5, 1.4, 1.3, 1.2]
    198 _MIMIMUM_RADIUS_ENCROACHMENT = 0.75
    199 _INITIAL_ANGLE = math.pi
     190_INTERMEDIATE_C = (style.STANDARD_ICON_SIZE + style.SMALL_ICON_SIZE) / 2
     191_INTERMEDIATE_A = (style.STANDARD_ICON_SIZE * 2 + _INTERMEDIATE_C) / 3
     192_INTERMEDIATE_E = (_INTERMEDIATE_C + style.SMALL_ICON_SIZE * 2) / 3
     193_INTERMEDIATE_B = (_INTERMEDIATE_A + _INTERMEDIATE_C) / 2
     194_INTERMEDIATE_D = (_INTERMEDIATE_C + _INTERMEDIATE_E) / 2
     195_ICON_SIZES = [style.MEDIUM_ICON_SIZE, style.STANDARD_ICON_SIZE,
     196               _INTERMEDIATE_A, _INTERMEDIATE_B, _INTERMEDIATE_C,
     197               _INTERMEDIATE_D, _INTERMEDIATE_E, style.SMALL_ICON_SIZE]
     198_ICON_SPACING_FACTORS = [1.5, 1.4, 1.3, 1.2, 1.15, 1.1, 1.05, 1.0]
    200199
    201200
    202201class RingLayout(FavoritesLayout):
    203     """Lay out icons in a ring or spiral around the XO man."""
     202    """Lay out icons in a ring around the XO man."""
    204203
    205204    __gtype_name__ = 'RingLayout'
    206205    icon_name = 'view-radial'
    class RingLayout(FavoritesLayout): 
    214213    def __init__(self):
    215214        FavoritesLayout.__init__(self)
    216215        self._locked_children = {}
    217         self._spiral_mode = False
    218216
    219217    def append(self, icon, locked=False):
    220218        FavoritesLayout.append(self, icon, locked)
    class RingLayout(FavoritesLayout): 
    235233            self._locked_children[child] = (x, y)
    236234
    237235    def _calculate_radius_and_icon_size(self, children_count):
    238         """ Adjust the ring or spiral radius and icon size as needed. """
    239         self._spiral_mode = False
     236        """ Adjust the ring radius and icon size as needed. """
     237        # Begin by increasing the radius.
    240238        distance = style.MEDIUM_ICON_SIZE + style.DEFAULT_SPACING * \
    241239            _ICON_SPACING_FACTORS[_ICON_SIZES.index(style.MEDIUM_ICON_SIZE)]
    242240        radius = max(children_count * distance / (2 * math.pi), _MINIMUM_RADIUS)
    243241        if radius < _MAXIMUM_RADIUS:
    244242            return radius, style.MEDIUM_ICON_SIZE
    245243
    246         distance = style.STANDARD_ICON_SIZE + style.DEFAULT_SPACING * \
    247             _ICON_SPACING_FACTORS[_ICON_SIZES.index(style.STANDARD_ICON_SIZE)]
    248         radius = max(children_count * distance / (2 * math.pi), _MINIMUM_RADIUS)
    249         if radius < _MAXIMUM_RADIUS:
    250             return radius, style.STANDARD_ICON_SIZE
    251 
    252         self._spiral_mode = True
    253         icon_size = style.STANDARD_ICON_SIZE
    254         angle, radius = self._calculate_angle_and_radius(children_count,
    255                                                                icon_size)
    256         while radius > _MAXIMUM_RADIUS:
    257             i = _ICON_SIZES.index(icon_size)
    258             if i < len(_ICON_SIZES) - 1:
    259                 icon_size = _ICON_SIZES[i + 1]
    260                 angle, radius = self._calculate_angle_and_radius(
    261                     children_count, icon_size)
    262             else:
    263                 break
     244        # Continue by shrinking the icon size to STANDARD_ICON_SIZE.
     245        radius = _MAXIMUM_RADIUS
     246        distance = radius * (2 * math.pi) / children_count
     247        icon_size = int(distance - style.DEFAULT_SPACING * \
     248            _ICON_SPACING_FACTORS[_ICON_SIZES.index(style.STANDARD_ICON_SIZE)])
     249        if icon_size >= style.STANDARD_ICON_SIZE:
     250            return radius, icon_size
     251
     252        # Continue by shrinking the icon size to SMALL_ICON_SIZE.
     253        icon_size = max(int(distance - style.DEFAULT_SPACING * \
     254                            _ICON_SPACING_FACTORS[_ICON_SIZES.index(
     255                    style.SMALL_ICON_SIZE)]), style.SMALL_ICON_SIZE)
    264256        return radius, icon_size
    265257
    266258    def _calculate_position(self, radius, icon_size, icon_index, children_count,
    267259                            sin=math.sin, cos=math.cos):
    268         """ Calculate an icon position on a circle or a spiral. """
     260        """ Calculate an icon position on a circle. """
    269261        width, height = self.box.get_allocation()
    270         if self._spiral_mode:
    271             min_width_, box_width = self.box.get_width_request()
    272             min_height_, box_height = self.box.get_height_request(box_width)
    273             angle, radius = self._calculate_angle_and_radius(icon_index,
    274                                                              icon_size)
    275             x, y = self._convert_from_polar_to_cartesian(angle, radius,
    276                                                          icon_size,
    277                                                          width, height)
    278         else:
    279             angle = icon_index * (2 * math.pi / children_count) - math.pi / 2
    280             x = radius * cos(angle) + (width - icon_size) / 2
    281             y = radius * sin(angle) + (height - icon_size - \
     262        angle = icon_index * (2 * math.pi / children_count) - math.pi / 2
     263        x = radius * cos(angle) + (width - icon_size) / 2
     264        y = radius * sin(angle) + (height - icon_size - \
    282265                                       (style.GRID_CELL_SIZE / 2)) / 2
    283266        return x, y
    284267
    285     def _convert_from_polar_to_cartesian(self, angle, radius, icon_size, width,
    286                                          height):
    287         """ Convert angle, radius to x, y """
    288         x = int(math.sin(angle) * radius)
    289         y = int(math.cos(angle) * radius)
    290         x = - x + (width - icon_size) / 2
    291         y = y + (height - icon_size - (style.GRID_CELL_SIZE / 2)) / 2
    292         return x, y
    293 
    294     def _calculate_angle_and_radius(self, icon_count, icon_size):
    295         """ Based on icon_count and icon_size, calculate radius and angle. """
    296         spiral_spacing = _SPIRAL_SPACING_FACTORS[_ICON_SIZES.index(icon_size)]
    297         icon_spacing = icon_size + style.DEFAULT_SPACING * \
    298             _ICON_SPACING_FACTORS[_ICON_SIZES.index(icon_size)]
    299         angle = _INITIAL_ANGLE
    300         radius = _MINIMUM_RADIUS - (icon_size * _MIMIMUM_RADIUS_ENCROACHMENT)
    301         for i in range(icon_count):
    302             circumference = radius * 2 * math.pi
    303             n = circumference / icon_spacing
    304             angle += (2 * math.pi / n)
    305             radius += (float(icon_spacing) * spiral_spacing / n)
    306         return angle, radius
    307 
    308268    def _get_children_in_ring(self):
    309269        children_in_ring = [child for child in self.box.get_layout_children() \
    310270                if child not in self._locked_children]
    class RingLayout(FavoritesLayout): 
    351311        else:
    352312            return 0
    353313
     314
    354315_SUNFLOWER_CONSTANT = style.STANDARD_ICON_SIZE * .75
    355316"""Chose a constant such that STANDARD_ICON_SIZE icons are nicely spaced."""
    356317