Rework home box layout to fix #2665.

master
Marco Pesenti Gritti 17 years ago
parent 0a53813064
commit 90bf68d0f3

@ -1,7 +1,7 @@
* #2665 Re-arrange device icons in a line at the bottom (marco)
* #3378 Support changes in activity scope (incomplete!) (smcv, marco)
* #3081, #3497, #3485 Fix palette sizing and widget placement (benzea)
* #2211 New XRestop interface style in Developer Console (edsiper)
* #3649 Human readable file names on USB. (marco)
Snapshot b8ce5083b7

@ -39,49 +39,30 @@ class HomeBox(hippo.CanvasBox, hippo.CanvasItem):
__gtype_name__ = 'SugarHomeBox'
def __init__(self, shell):
hippo.CanvasBox.__init__(self, background_color=0xe2e2e2ff, yalign=2)
hippo.CanvasBox.__init__(self, background_color=0xe2e2e2ff)
self._donut = ActivitiesDonut(shell, box_width=style.zoom(450),
box_height=style.zoom(450))
self.append(self._donut)
self._my_icon = HomeMyIcon(shell, style.XLARGE_ICON_SIZE)
self.append(self._my_icon, hippo.PACK_FIXED)
self._redraw_id = None
shell_model = shell.get_model()
shell_model.connect('notify::state',
self._shell_state_changed_cb)
self._device_icons = {}
devices_model = shell_model.get_devices()
for device in devices_model:
self._add_device(device)
devices_model.connect('device-appeared',
self._device_appeared_cb)
devices_model.connect('device-disappeared',
self._device_disappeared_cb)
self._redraw_id = None
top_box = hippo.CanvasBox(box_height=style.GRID_CELL_SIZE)
self.append(top_box, hippo.PACK_EXPAND)
def __del__(self):
self.suspend()
self._donut = ActivitiesDonut(shell)
self.append(self._donut)
def _add_device(self, device):
view = deviceview.create(device)
self.append(view, hippo.PACK_FIXED)
self._device_icons[device.get_id()] = view
bottom_box = hippo.CanvasBox(yalign=hippo.ALIGNMENT_END,
box_height=style.GRID_CELL_SIZE)
self.append(bottom_box, hippo.PACK_EXPAND)
def _remove_device(self, device):
self.remove(self._device_icons[device.get_id()])
del self._device_icons[device.get_id()]
self._my_icon = _MyIcon(shell, style.XLARGE_ICON_SIZE)
self.append(self._my_icon, hippo.PACK_FIXED)
def _device_appeared_cb(self, model, device):
self._add_device(device)
devices_box = _DevicesBox(shell_model.get_devices())
bottom_box.append(devices_box)
def _device_disappeared_cb(self, model, device):
self._remove_device(device)
shell_model.connect('notify::state',
self._shell_state_changed_cb)
def _shell_state_changed_cb(self, model, pspec):
# FIXME implement this
@ -94,19 +75,6 @@ class HomeBox(hippo.CanvasBox, hippo.CanvasItem):
[icon_width, icon_height] = self._my_icon.get_allocation()
self.set_position(self._my_icon, (width - icon_width) / 2,
(height - icon_height) / 2)
i = 0
for icon in self._device_icons.values():
angle = 2 * math.pi / len(self._device_icons) * i + math.pi / 2
radius = style.zoom(300)
[icon_width, icon_height] = icon.get_allocation()
x = int(radius * math.cos(angle)) - icon_width / 2
y = int(radius * math.sin(angle)) - icon_height / 2
self.set_position(icon, x + width / 2, y + height / 2)
i += 1
_REDRAW_TIMEOUT = 5 * 60 * 1000 # 5 minutes
@ -140,8 +108,38 @@ class HomeBox(hippo.CanvasBox, hippo.CanvasItem):
def release(self):
pass
class HomeMyIcon(MyIcon):
class _DevicesBox(hippo.CanvasBox):
def __init__(self, devices_model):
gobject.GObject.__init__(self,
orientation=hippo.ORIENTATION_HORIZONTAL,
xalign=hippo.ALIGNMENT_CENTER)
self._device_icons = {}
for device in devices_model:
self._add_device(device)
devices_model.connect('device-appeared',
self._device_appeared_cb)
devices_model.connect('device-disappeared',
self._device_disappeared_cb)
def _add_device(self, device):
view = deviceview.create(device)
self.append(view)
self._device_icons[device.get_id()] = view
def _remove_device(self, device):
self.remove(self._device_icons[device.get_id()])
del self._device_icons[device.get_id()]
def _device_appeared_cb(self, model, device):
self._add_device(device)
def _device_disappeared_cb(self, model, device):
self._remove_device(device)
class _MyIcon(MyIcon):
def __init__(self, shell, scale):
MyIcon.__init__(self, scale)

@ -32,6 +32,10 @@ from sugar.graphics import xocolor
from sugar import profile
import proc_smaps
_MAX_ACTIVITIES = 10
_MIN_WEDGE_SIZE = 1.0 / _MAX_ACTIVITIES
_DONUT_SIZE = style.zoom(450)
# TODO: rgb_to_html and html_to_rgb are useful elsewhere
# we should put this in a common module
def rgb_to_html(r, g, b):
@ -50,9 +54,6 @@ def html_to_rgb(html_color):
r, g, b = (r / 255.0, g / 255.0, b / 255.0)
return (r, g, b)
_MAX_ACTIVITIES = 10
_MIN_WEDGE_SIZE = 1.0 / _MAX_ACTIVITIES
class ActivityIcon(CanvasIcon):
_INTERVAL = 250
@ -188,6 +189,9 @@ class ActivitiesDonut(hippo.CanvasBox, hippo.CanvasItem):
self._angles = []
self._shell_mappings = proc_smaps.get_shared_mapping_names(os.getpid())
self._layout = _Layout()
self.set_layout(self._layout)
self._model = shell.get_model().get_home()
self._model.connect('activity-added', self._activity_added_cb)
self._model.connect('activity-removed', self._activity_removed_cb)
@ -495,4 +499,35 @@ class ActivitiesDonut(hippo.CanvasBox, hippo.CanvasItem):
x = int(radius * math.cos(angle)) - icon_width / 2
y = int(radius * math.sin(angle)) - icon_height / 2
self.set_position(icon, x + width / 2, y + height / 2)
class _Layout(gobject.GObject,hippo.CanvasLayout):
__gtype_name__ = 'SugarDonutLayout'
def __init__(self):
gobject.GObject.__init__(self)
def do_set_box(self, box):
self._box = box
def do_get_height_request(self, for_width):
return _DONUT_SIZE, _DONUT_SIZE
def do_get_width_request(self):
return _DONUT_SIZE, _DONUT_SIZE
def do_allocate(self, x, y, width, height,
req_width, req_height, origin_changed):
for child in self._box.get_layout_children():
min_width, child_width = child.get_width_request()
min_height, child_height = child.get_height_request(child_width)
[angle_start, angle_end] = self._box._get_angles(i)
angle = angle_start + (angle_end - angle_start) / 2
x = int(radius * math.cos(angle)) - icon_width / 2
y = int(radius * math.sin(angle)) - icon_height / 2
child.allocate(x + (width - child_width) / 2,
y + (height - child_height) / 2,
icon_width, icon_height, origin_changed)

Loading…
Cancel
Save