[Sugar-devel] Home view activities layout

Walter Bender walter.bender at gmail.com
Sat Jul 31 07:40:41 EDT 2010


I am heading off to vacation for a week, but I may get a chance to
play with moving/snapping the icons as well. In the meantime, the code
is quite simple:

--- favoriteslayout.py	2010-07-20 13:31:05.000000000 -0400
+++ favoriteslayout.py	2010-07-30 23:26:56.000000000 -0400

+
+class MyLayout(RingLayout):
+    """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):
+        RingLayout.__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, radius, icon_size, index, children_count):
+        """ Increment the radius as you go; decrease the angle of rotation
+        as the radius increases to keep the distance between icons constant."""
+
+        print "index %d (r: %f, o: %f)" % (index, self.my_radius,
self.my_orientation)
+        if index == 0:
+            self.my_radius = _MINIMUM_RADIUS
+            self.my_orientation = math.pi
+
+        x, y = self._calculate_xy()
+        # add some buffering around the icon
+        self._calculate_new_radius_orientation(icon_size + 10)
+
+        """
+        # angle decreases as the radius increases
+        angle = index * (2 * math.pi / (12.0 + index / 6.0)) - math.pi / 2
+        # radius is proportional to index/children_count
+        myminimum = _MINIMUM_RADIUS * .67
+        newradius = ((_MAXIMUM_RADIUS - myminimum) * (index * 1.1) /
children_count) + myminimum
+        x = newradius * math.cos(angle) + (width - icon_size) / 2
+        y = newradius * math.sin(angle) + (height - icon_size -
style.GRID_CELL_SIZE) / 2
+        """
+        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):
+        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):
+        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

On Sat, Jul 31, 2010 at 7:36 AM, Walter Bender <walter.bender at gmail.com> wrote:
> On Sat, Jul 31, 2010 at 12:31 AM, Frederick Grose <fgrose at gmail.com> wrote:
>> On Fri, Jul 30, 2010 at 11:32 PM, Walter Bender <walter.bender at gmail.com>
>> wrote:
>>>
>>> On Fri, Jul 30, 2010 at 8:25 PM, Chris Ball <cjb at laptop.org> wrote:
>>>
>>>
>>>
>>> {...}
>>>
>>>
>>>
>>> Here is a tighter spiral of 74 icons for the home view (running in the
>>> Sugar emulator at 800x600).
>>
>> Running the emulator with usr/bin/sugar-emulator -i 832x624
>> give a close match to the XO screen proportions.
>
> Done. See http://wiki.sugarlabs.org/go/User:Walter#Home_View
>
> -walter
>> _______________________________________________
>> Sugar-devel mailing list
>> Sugar-devel at lists.sugarlabs.org
>> http://lists.sugarlabs.org/listinfo/sugar-devel
>>
>>
>
>
>
> --
> Walter Bender
> Sugar Labs
> http://www.sugarlabs.org
>



-- 
Walter Bender
Sugar Labs
http://www.sugarlabs.org


More information about the Sugar-devel mailing list