More work on the views layout
This commit is contained in:
parent
924fe94b16
commit
1b0e469dbd
@ -1,5 +1,6 @@
|
|||||||
import gtk
|
import gtk
|
||||||
import gobject
|
import gobject
|
||||||
|
import hippo
|
||||||
|
|
||||||
from sugar.graphics.menu import Menu
|
from sugar.graphics.menu import Menu
|
||||||
from sugar.graphics.canvasicon import CanvasIcon
|
from sugar.graphics.canvasicon import CanvasIcon
|
||||||
@ -22,7 +23,7 @@ class BuddyMenu(Menu):
|
|||||||
scaled_pixbuf = pixbuf.scale_simple(_ICON_SIZE, _ICON_SIZE,
|
scaled_pixbuf = pixbuf.scale_simple(_ICON_SIZE, _ICON_SIZE,
|
||||||
gtk.gdk.INTERP_BILINEAR)
|
gtk.gdk.INTERP_BILINEAR)
|
||||||
del pixbuf
|
del pixbuf
|
||||||
icon_item = hippo.Image(pixbuf=scaled_pixbuf)
|
icon_item = hippo.CanvasImage(pixbuf=scaled_pixbuf)
|
||||||
|
|
||||||
Menu.__init__(self, buddy.get_name(), icon_item)
|
Menu.__init__(self, buddy.get_name(), icon_item)
|
||||||
|
|
||||||
|
@ -8,7 +8,8 @@ from view.BuddyIcon import BuddyIcon
|
|||||||
from sugar.graphics.snowflakelayout import SnowflakeLayout
|
from sugar.graphics.snowflakelayout import SnowflakeLayout
|
||||||
import conf
|
import conf
|
||||||
|
|
||||||
class ActivityView(hippo.CanvasBox):
|
class ActivityView(hippo.CanvasBox, hippo.CanvasItem):
|
||||||
|
__gtype_name__ = 'SugarActivityView'
|
||||||
def __init__(self, shell, menu_shell, model):
|
def __init__(self, shell, menu_shell, model):
|
||||||
hippo.CanvasBox.__init__(self)
|
hippo.CanvasBox.__init__(self)
|
||||||
|
|
||||||
@ -35,16 +36,16 @@ class ActivityView(hippo.CanvasBox):
|
|||||||
self.remove(icon)
|
self.remove(icon)
|
||||||
del self._icons[name]
|
del self._icons[name]
|
||||||
|
|
||||||
def get_size_request(self):
|
|
||||||
size = self._layout.get_size()
|
|
||||||
return [size, size]
|
|
||||||
|
|
||||||
def _clicked_cb(self, item):
|
def _clicked_cb(self, item):
|
||||||
registry = conf.get_activity_registry()
|
registry = conf.get_activity_registry()
|
||||||
default_type = self._model.get_service().get_type()
|
default_type = self._model.get_service().get_type()
|
||||||
bundle = registry.get_activity_from_type(default_type)
|
bundle = registry.get_activity_from_type(default_type)
|
||||||
self._shell.join_activity(bundle.get_id(), self._model.get_id())
|
self._shell.join_activity(bundle.get_id(), self._model.get_id())
|
||||||
|
|
||||||
|
def do_allocate(self, width, height):
|
||||||
|
hippo.CanvasBox.do_allocate(self, width, height)
|
||||||
|
self._layout.layout(self)
|
||||||
|
|
||||||
class MeshBox(hippo.CanvasBox, hippo.CanvasItem):
|
class MeshBox(hippo.CanvasBox, hippo.CanvasItem):
|
||||||
__gtype_name__ = 'SugarMeshBox'
|
__gtype_name__ = 'SugarMeshBox'
|
||||||
def __init__(self, shell, menu_shell):
|
def __init__(self, shell, menu_shell):
|
||||||
|
@ -9,63 +9,53 @@ class SnowflakeLayout:
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._root = None
|
self._root = None
|
||||||
self._children = []
|
|
||||||
self._r = 0
|
self._r = 0
|
||||||
|
|
||||||
def set_root(self, icon):
|
def set_root(self, icon):
|
||||||
self._root = icon
|
self._root = icon
|
||||||
|
|
||||||
def add_child(self, icon):
|
def _layout_root(self, box):
|
||||||
self._children.append(icon)
|
[width, height] = self._root.get_allocation()
|
||||||
self._layout()
|
|
||||||
|
|
||||||
def remove_child(self, icon):
|
x = self._cx - (width / 2)
|
||||||
self._children.remove(icon)
|
y = self._cy - (height / 2)
|
||||||
self._layout()
|
|
||||||
|
|
||||||
def _layout_root(self):
|
box.move(self._root, int(x), int(y))
|
||||||
[width, height] = self._root.get_size_request()
|
|
||||||
|
|
||||||
matrix = cairo.Matrix(1, 0, 0, 1, 0, 0)
|
def _layout_child(self, box, child, index):
|
||||||
matrix.translate(self._cx - (width / 2), self._cy - (height / 2))
|
|
||||||
self._root.set_transform(matrix)
|
|
||||||
|
|
||||||
def _layout_child(self, child, index):
|
|
||||||
r = self._r
|
r = self._r
|
||||||
if (len(self._children) > 10):
|
if (len(box.get_children()) > 10):
|
||||||
r += SnowflakeLayout._FLAKE_DISTANCE * (index % 3)
|
r += SnowflakeLayout._FLAKE_DISTANCE * (index % 3)
|
||||||
|
|
||||||
angle = 2 * math.pi / len(self._children) * index
|
angle = 2 * math.pi / len(box.get_children()) * index
|
||||||
|
|
||||||
[width, height] = child.get_size_request()
|
[width, height] = child.get_allocation()
|
||||||
x = self._cx + math.cos(angle) * r - (width / 2)
|
x = self._cx + math.cos(angle) * r - (width / 2)
|
||||||
y = self._cy + math.sin(angle) * r - (height / 2)
|
y = self._cy + math.sin(angle) * r - (height / 2)
|
||||||
|
|
||||||
matrix = cairo.Matrix(1, 0, 0, 1, 0, 0)
|
box.move(child, int(x), int(y))
|
||||||
matrix.translate(x, y)
|
|
||||||
child.set_transform(matrix)
|
|
||||||
|
|
||||||
def get_size(self):
|
def get_size(self, box):
|
||||||
max_child_size = 0
|
max_child_size = 0
|
||||||
for child in self._children:
|
for child in box.get_children():
|
||||||
[width, height] = child.get_size_request()
|
[width, height] = child.get_allocation()
|
||||||
max_child_size = max (max_child_size, width)
|
max_child_size = max (max_child_size, width)
|
||||||
max_child_size = max (max_child_size, height)
|
max_child_size = max (max_child_size, height)
|
||||||
|
|
||||||
return self._r * 2 + max_child_size + \
|
return self._r * 2 + max_child_size + \
|
||||||
SnowflakeLayout._FLAKE_DISTANCE * 2
|
SnowflakeLayout._FLAKE_DISTANCE * 2
|
||||||
|
|
||||||
def _layout(self):
|
def layout(self, box):
|
||||||
self._r = SnowflakeLayout._BASE_RADIUS + \
|
self._r = SnowflakeLayout._BASE_RADIUS + \
|
||||||
SnowflakeLayout._CHILDREN_FACTOR * len(self._children)
|
SnowflakeLayout._CHILDREN_FACTOR * len(box.get_children())
|
||||||
|
|
||||||
size = self.get_size()
|
size = self.get_size(box)
|
||||||
self._cx = size / 2
|
self._cx = size / 2
|
||||||
self._cy = size / 2
|
self._cy = size / 2
|
||||||
|
|
||||||
self._layout_root()
|
self._layout_root(box)
|
||||||
|
|
||||||
index = 0
|
index = 0
|
||||||
for child in self._children:
|
for child in box.get_children():
|
||||||
self._layout_child(child, index)
|
self._layout_child(box, child, index)
|
||||||
index += 1
|
index += 1
|
||||||
|
Loading…
Reference in New Issue
Block a user