Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xexamples/scene/scene.py4
-rw-r--r--sugar/scene/CircleLayout.py21
-rw-r--r--sugar/scene/Group.py12
-rw-r--r--sugar/scene/LayoutManager.py7
4 files changed, 44 insertions, 0 deletions
diff --git a/examples/scene/scene.py b/examples/scene/scene.py
index 5468cd1..f404f6f 100755
--- a/examples/scene/scene.py
+++ b/examples/scene/scene.py
@@ -7,6 +7,7 @@ import gtk
from sugar.scene.Stage import Stage
from sugar.scene.Group import Group
from sugar.scene.PixbufActor import PixbufActor
+from sugar.scene.CircleLayout import CircleLayout
def drawing_area_expose_cb(widget, event, stage):
stage.render(widget.window)
@@ -24,6 +25,9 @@ while i <= 5:
icons_group.add(PixbufActor(pixbuf))
i += 1
+layout = CircleLayout(100)
+icons_group.set_layout_manager(layout)
+
stage.add(icons_group)
window = gtk.Window()
diff --git a/sugar/scene/CircleLayout.py b/sugar/scene/CircleLayout.py
new file mode 100644
index 0000000..eb36ee4
--- /dev/null
+++ b/sugar/scene/CircleLayout.py
@@ -0,0 +1,21 @@
+import math
+
+from sugar.scene.LayoutManager import LayoutManager
+
+class CircleLayout(LayoutManager):
+ def __init__(self, radium):
+ LayoutManager.__init__(self)
+
+ self._radium = radium
+
+ def layout_group(self, group):
+ step = 2 * math.pi / len(group.get_actors())
+ angle = 2 * math.pi
+ for actor in group.get_actors():
+ self._update_position(actor, angle)
+ angle -= step
+
+ def _update_position(self, actor, angle):
+ x = math.cos(angle) * self._radium + self._radium
+ y = math.sin(angle) * self._radium + self._radium
+ actor.set_position(int(x), int(y))
diff --git a/sugar/scene/Group.py b/sugar/scene/Group.py
index b845cd8..1485d11 100644
--- a/sugar/scene/Group.py
+++ b/sugar/scene/Group.py
@@ -3,12 +3,24 @@ from sugar.scene.Actor import Actor
class Group(Actor):
def __init__(self):
self._actors = []
+ self._layout_manager = None
def add(self, actor):
self._actors.append(actor)
+ if self._layout_manager:
+ self._layout_manager.layout_group(slef)
def remove(self, actor):
self._actors.remove(actor)
+ if self._layout_manager:
+ self._layout_manager.layout_group(self)
+
+ def get_actors(self):
+ return self._actors
+
+ def set_layout_manager(self, layout_manager):
+ self._layout_manager = layout_manager
+ self._layout_manager.layout_group(self)
def render(self, drawable):
for actor in self._actors:
diff --git a/sugar/scene/LayoutManager.py b/sugar/scene/LayoutManager.py
new file mode 100644
index 0000000..c7ada5a
--- /dev/null
+++ b/sugar/scene/LayoutManager.py
@@ -0,0 +1,7 @@
+class LayoutManager:
+ def __init__(self):
+ pass
+
+ def layout_group(self, group):
+ pass
+