Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/jarabe/desktop/groupbox.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/jarabe/desktop/groupbox.py')
-rw-r--r--src/jarabe/desktop/groupbox.py83
1 files changed, 68 insertions, 15 deletions
diff --git a/src/jarabe/desktop/groupbox.py b/src/jarabe/desktop/groupbox.py
index ed8f8ae..d74ec9d 100644
--- a/src/jarabe/desktop/groupbox.py
+++ b/src/jarabe/desktop/groupbox.py
@@ -17,8 +17,8 @@
import logging
import gobject
-import hippo
import gconf
+import gtk
from sugar.graphics import style
from sugar.graphics.icon import CanvasIcon
@@ -28,25 +28,29 @@ from jarabe.view.buddymenu import BuddyMenu
from jarabe.model.buddy import get_owner_instance
from jarabe.model import friends
from jarabe.desktop.friendview import FriendView
-from jarabe.desktop.spreadlayout import SpreadLayout
+from jarabe.desktop.grid import Grid
+_CELL_SIZE = 4.0
-class GroupBox(hippo.Canvas):
+
+class GroupBox(gtk.Container):
__gtype_name__ = 'SugarGroupBox'
def __init__(self):
logging.debug('STARTUP: Loading the group view')
- gobject.GObject.__init__(self)
+ gtk.Container.__init__(self)
- self._box = hippo.CanvasBox()
- self._box.props.background_color = style.COLOR_WHITE.get_int()
- self.set_root(self._box)
+ # TODO(rgs): how do you do this for a Container?
+ # self._box.props.background_color = style.COLOR_WHITE.get_int()
self._friends = {}
- self._layout = SpreadLayout()
- self._box.set_layout(self._layout)
+ min_width, width = self.do_get_width_request()
+ min_height, height = self.do_get_height_request(width)
+
+ self._grid = Grid(int(width / _CELL_SIZE), int(height / _CELL_SIZE))
+ self._grid.connect('child-changed', self._grid_child_changed_cb)
client = gconf.client_get_default()
color = XoColor(client.get_string('/desktop/sugar/user/color'))
@@ -56,7 +60,9 @@ class GroupBox(hippo.Canvas):
self._owner_icon.props.size = style.LARGE_ICON_SIZE
self._owner_icon.set_palette(BuddyMenu(get_owner_instance()))
- self._layout.add(self._owner_icon)
+ width, height = self._get_child_grid_size(self._owner_icon)
+ self._grid.add(self._owner_icon, width, height)
+ self._owner_icon.set_parent(self)
friends_model = friends.get_model()
@@ -66,22 +72,58 @@ class GroupBox(hippo.Canvas):
friends_model.connect('friend-added', self._friend_added_cb)
friends_model.connect('friend-removed', self._friend_removed_cb)
+ def do_get_height_request(self, for_width):
+ return 0, gtk.gdk.screen_height() - style.GRID_CELL_SIZE
+
+ def do_get_width_request(self):
+ return 0, gtk.gdk.screen_width()
+
def add_friend(self, buddy_info):
icon = FriendView(buddy_info)
- self._layout.add(icon)
-
+ width, height = self._get_child_grid_size(icon)
+ self._grid.add(icon, width, height)
self._friends[buddy_info.get_key()] = icon
+ if icon.flags() & gtk.REALIZED:
+ icon.set_parent_window(self.window)
+ icon.set_parent(self)
def _friend_added_cb(self, data_model, buddy_info):
self.add_friend(buddy_info)
def _friend_removed_cb(self, data_model, key):
icon = self._friends[key]
- self._layout.remove(icon)
+ self._grid.remove(icon)
del self._friends[key]
icon.destroy()
+ def do_forall(self, include_internals, callback, data):
+ for widget in self._grid.get_children():
+ callback(widget, data)
+
+ def do_realize(self):
+ self.set_flags(self.flags() | gtk.REALIZED)
+ self.window = gtk.gdk.Window(
+ self.get_parent_window(),
+ width=self.allocation.width,
+ height=self.allocation.height,
+ window_type=gtk.gdk.WINDOW_CHILD,
+ wclass=gtk.gdk.INPUT_OUTPUT,
+ event_mask=self.get_events() | gtk.gdk.EXPOSURE_MASK
+ | gtk.gdk.BUTTON1_MOTION_MASK
+ | gtk.gdk.BUTTON_PRESS_MASK
+ | gtk.gdk.POINTER_MOTION_MASK
+ | gtk.gdk.POINTER_MOTION_HINT_MASK)
+ self.window.set_user_data(self)
+ self.style.attach(self.window)
+ self.style.set_background(self.window, gtk.STATE_NORMAL)
+ self.window.move_resize(*self.allocation)
+ self.gc = self.style.fg_gc[gtk.STATE_NORMAL]
+ self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse('white'))
+
def do_size_allocate(self, allocation):
+ if self.flags() & gtk.REALIZED:
+ self.window.move_resize(*allocation)
+
width = allocation.width
height = allocation.height
@@ -89,6 +131,17 @@ class GroupBox(hippo.Canvas):
min_h_, icon_height = self._owner_icon.get_height_request(icon_width)
x = (width - icon_width) / 2
y = (height - icon_height) / 2
- self._layout.move(self._owner_icon, x, y)
+ self._grid.move(self._owner_icon, x / _CELL_SIZE, y / _CELL_SIZE, locked=True)
+
+ for child in self._grid.get_children():
+ rect = self._grid.get_child_rect(child)
+ child.size_allocate(rect)
+
+ def _get_child_grid_size(self, child):
+ min_width, width = child.get_width_request()
+ min_height, height = child.get_height_request(width)
+
+ return int(width / _CELL_SIZE), int(height / _CELL_SIZE)
- hippo.Canvas.do_size_allocate(self, allocation)
+ def _grid_child_changed_cb(self, grid, child):
+ child.emit_request_changed()