diff options
Diffstat (limited to 'src/jarabe/desktop/meshbox.py')
-rw-r--r-- | src/jarabe/desktop/meshbox.py | 132 |
1 files changed, 97 insertions, 35 deletions
diff --git a/src/jarabe/desktop/meshbox.py b/src/jarabe/desktop/meshbox.py index 3d1e52a..6323cc4 100644 --- a/src/jarabe/desktop/meshbox.py +++ b/src/jarabe/desktop/meshbox.py @@ -21,7 +21,6 @@ from gettext import gettext as _ import logging import dbus -import hippo import glib import gobject import gtk @@ -36,8 +35,7 @@ from sugar.graphics.menuitem import MenuItem from jarabe.model import neighborhood from jarabe.model.buddy import get_owner_instance from jarabe.view.buddyicon import BuddyIcon -from jarabe.desktop.snowflakelayout import SnowflakeLayout -from jarabe.desktop.spreadlayout import SpreadLayout +from jarabe.desktop.grid import Grid from jarabe.desktop.networkviews import WirelessNetworkView from jarabe.desktop.networkviews import OlpcMeshView from jarabe.desktop.networkviews import SugarAdhocView @@ -62,10 +60,11 @@ _OLPC_MESH_ICON_NAME = 'network-mesh' _AUTOSEARCH_TIMEOUT = 1000 - -class ActivityView(hippo.CanvasBox): +# TODO(rgs): use a gtk.Container and emulate the Snowflake +# layouting algorithm of activities around a buddy. +class ActivityView(gtk.VBox): def __init__(self, model): - hippo.CanvasBox.__init__(self) + gtk.VBox.__init__(self) self._model = model self._model.connect('current-buddy-added', self.__buddy_added_cb) @@ -74,11 +73,8 @@ class ActivityView(hippo.CanvasBox): self._icons = {} self._palette = None - self._layout = SnowflakeLayout() - self.set_layout(self._layout) - self._icon = self._create_icon() - self._layout.add(self._icon, center=True) + self.add(self._icon) self._palette = self._create_palette() self._icon.set_palette(self._palette) @@ -127,7 +123,6 @@ class ActivityView(hippo.CanvasBox): def _add_buddy(self, buddy): icon = BuddyIcon(buddy, style.STANDARD_ICON_SIZE) self._icons[buddy.props.key] = icon - self._layout.add(icon) def __buddy_removed_cb(self, activity, buddy): icon = self._icons[buddy.props.key] @@ -396,6 +391,82 @@ class NetworkManagerObserver(object): if self._have_adhoc_networks: self._box.add_adhoc_networks(device) +_CELL_SIZE = 4.0 + +class MeshContainer(gtk.Container): + __gtype_name__ = 'SugarMeshContainer' + + def __init__(self): + gtk.Container.__init__(self) + + 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) + + 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 move(self, child, x, y): + self._grid.move(child, x / _CELL_SIZE, y / _CELL_SIZE, locked=True) + + def add(self, icon): + width, height = self._get_child_grid_size(icon) + self._grid.add(icon, width, height) + if icon.flags() & gtk.REALIZED: + icon.set_parent_window(self.window) + icon.set_parent(self) + + def remove(self, icon): + self._grid.remove(icon) + 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 + + 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) + + def _grid_child_changed_cb(self, grid, child): + child.emit_request_changed() class MeshBox(gtk.VBox): __gtype_name__ = 'SugarMeshBox' @@ -403,7 +474,7 @@ class MeshBox(gtk.VBox): def __init__(self): logging.debug('STARTUP: Loading the mesh view') - gobject.GObject.__init__(self) + gtk.VBox.__init__(self) self.wireless_networks = {} self._adhoc_manager = None @@ -423,16 +494,9 @@ class MeshBox(gtk.VBox): self.pack_start(self._toolbar, expand=False) self._toolbar.show() - canvas = hippo.Canvas() - self.add(canvas) - canvas.show() - - self._layout_box = hippo.CanvasBox( \ - background_color=style.COLOR_WHITE.get_int()) - canvas.set_root(self._layout_box) - - self._layout = SpreadLayout() - self._layout_box.set_layout(self._layout) + self._mesh_container = MeshContainer() + self.add(self._mesh_container) + self._mesh_container.show() for buddy_model in self._model.get_buddies(): self._add_buddy(buddy_model) @@ -457,9 +521,10 @@ class MeshBox(gtk.VBox): min_h_, icon_height = self._owner_icon.get_height_request(icon_width) x = (width - icon_width) / 2 y = (height - icon_height) / 2 - style.GRID_CELL_SIZE - self._layout.move(self._owner_icon, x, y) + self._mesh_container.move(self._owner_icon, x, y) gtk.VBox.do_size_allocate(self, allocation) + self._mesh_container.do_size_allocate(allocation) def _buddy_added_cb(self, model, buddy_model): self._add_buddy(buddy_model) @@ -481,7 +546,7 @@ class MeshBox(gtk.VBox): icon = BuddyIcon(buddy_model) if buddy_model.is_owner(): self._owner_icon = icon - self._layout.add(icon) + self._mesh_container.add(icon) if hasattr(icon, 'set_filter'): icon.set_filter(self._query) @@ -491,9 +556,8 @@ class MeshBox(gtk.VBox): def _remove_buddy(self, buddy_model): logging.debug('MeshBox._remove_buddy') icon = self._buddies[buddy_model.props.key] - self._layout.remove(icon) + self._mesh_container.remove(icon) del self._buddies[buddy_model.props.key] - icon.destroy() def __buddy_notify_current_activity_cb(self, buddy_model, pspec): logging.debug('MeshBox.__buddy_notify_current_activity_cb %s', @@ -506,7 +570,7 @@ class MeshBox(gtk.VBox): def _add_activity(self, activity_model): icon = ActivityView(activity_model) - self._layout.add(icon) + self._mesh_container.add(icon) if hasattr(icon, 'set_filter'): icon.set_filter(self._query) @@ -515,9 +579,8 @@ class MeshBox(gtk.VBox): def _remove_activity(self, activity_model): icon = self._activities[activity_model.activity_id] - self._layout.remove(icon) + self._mesh_container.remove(icon) del self._activities[activity_model.activity_id] - icon.destroy() # add AP to its corresponding network icon on the desktop, # creating one if it doesn't already exist @@ -529,7 +592,7 @@ class MeshBox(gtk.VBox): # this is a new network icon = WirelessNetworkView(ap) self.wireless_networks[hash_value] = icon - self._layout.add(icon) + self._mesh_container.add(icon) if hasattr(icon, 'set_filter'): icon.set_filter(self._query) @@ -621,12 +684,12 @@ class MeshBox(gtk.VBox): def _add_adhoc_network_icon(self, channel): icon = SugarAdhocView(channel) - self._layout.add(icon) + self._mesh_container.add(icon) self._adhoc_networks.append(icon) def _add_olpc_mesh_icon(self, mesh_mgr, channel): icon = OlpcMeshView(mesh_mgr, channel) - self._layout.add(icon) + self._mesh_container.add(icon) self._mesh.append(icon) def enable_olpc_mesh(self, mesh_device): @@ -644,13 +707,12 @@ class MeshBox(gtk.VBox): logging.debug('removing OLPC mesh IBSS') net.remove_all_aps() net.disconnect() - self._layout.remove(net) - del self.wireless_networks[hash_value] + self._mesh_container.remove(net) def disable_olpc_mesh(self, mesh_device): for icon in self._mesh: icon.disconnect() - self._layout.remove(icon) + self._mesh_container.remove(icon) self._mesh = [] def suspend(self): |