From 07cbe7f6f2c8468ab1f8c251b1da51163225b96b Mon Sep 17 00:00:00 2001 From: Raul Gutierrez Segales Date: Mon, 12 Sep 2011 13:19:25 +0000 Subject: Refactor common container code into ViewContainer --- diff --git a/src/jarabe/desktop/Makefile.am b/src/jarabe/desktop/Makefile.am index 25fb0b4..9e928e2 100644 --- a/src/jarabe/desktop/Makefile.am +++ b/src/jarabe/desktop/Makefile.am @@ -15,4 +15,5 @@ sugar_PYTHON = \ schoolserver.py \ snowflakelayout.py \ spreadlayout.py \ - transitionbox.py + transitionbox.py \ + viewcontainer.py diff --git a/src/jarabe/desktop/favoritesview.py b/src/jarabe/desktop/favoritesview.py index 2f974c2..a80c32a 100644 --- a/src/jarabe/desktop/favoritesview.py +++ b/src/jarabe/desktop/favoritesview.py @@ -46,7 +46,7 @@ from jarabe.journal import misc from jarabe.desktop import schoolserver from jarabe.desktop.schoolserver import RegisterError from jarabe.desktop import favoriteslayout - +from jarabe.desktop.viewcontainer import ViewContainer _logger = logging.getLogger('FavoritesView') @@ -64,46 +64,17 @@ about the layout can be accessed with fields of the class.""" _favorites_settings = None -class FavoritesContainer(gtk.Container): +class FavoritesContainer(ViewContainer): __gtype_name__ = 'SugarFavoritesContainer' def __init__(self, **kwargs): - gobject.GObject.__init__(self, **kwargs) + ViewContainer.__init__(self, **kwargs) self._my_icon = None self._current_activity = None self._activity_icons = [] self._layout = None - def get_height_request(self, for_width): - return 0, gtk.gdk.screen_height() - style.GRID_CELL_SIZE - - def get_width_request(self): - return 0, gtk.gdk.screen_width() - - 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_forall(self, include_internals, forall_cb, user_data): children = self._activity_icons[:] @@ -125,10 +96,6 @@ class FavoritesContainer(gtk.Container): self._layout.remove(child) self._activity_icons.remove(child) - def do_size_request(self, requisition): - requisition.height = gtk.gdk.screen_height() - style.GRID_CELL_SIZE - requisition.width = gtk.gdk.screen_width() - def do_size_allocate(self, allocation): if self.flags() & gtk.REALIZED: self.window.move_resize(*allocation) diff --git a/src/jarabe/desktop/groupbox.py b/src/jarabe/desktop/groupbox.py index 6c81b87..a186eb7 100644 --- a/src/jarabe/desktop/groupbox.py +++ b/src/jarabe/desktop/groupbox.py @@ -29,25 +29,23 @@ from jarabe.model.buddy import get_owner_instance from jarabe.model import friends from jarabe.desktop.friendview import FriendView from jarabe.desktop.grid import Grid +from jarabe.desktop.viewcontainer import ViewContainer _CELL_SIZE = 4.0 -class GroupBox(gtk.Container): +class GroupBox(ViewContainer): __gtype_name__ = 'SugarGroupBox' def __init__(self): logging.debug('STARTUP: Loading the group view') - gtk.Container.__init__(self) - - # TODO(rgs): how do you do this for a Container? - # self._box.props.background_color = style.COLOR_WHITE.get_int() + ViewContainer.__init__(self) self._friends = {} - min_width, width = self.do_get_width_request() - min_height, height = self.do_get_height_request(width) + min_width, width = self.get_width_request() + min_height, height = self.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) @@ -73,12 +71,6 @@ class GroupBox(gtk.Container): 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) width, height = self._get_child_grid_size(icon) @@ -102,30 +94,6 @@ class GroupBox(gtk.Container): 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_request(self, requisition): - requisition.height = gtk.gdk.screen_height() - requisition.width = gtk.gdk.screen_width() - def do_size_allocate(self, allocation): if self.flags() & gtk.REALIZED: self.window.move_resize(*allocation) diff --git a/src/jarabe/desktop/meshbox.py b/src/jarabe/desktop/meshbox.py index 21dc042..6470105 100644 --- a/src/jarabe/desktop/meshbox.py +++ b/src/jarabe/desktop/meshbox.py @@ -39,6 +39,7 @@ from jarabe.desktop.grid import Grid from jarabe.desktop.networkviews import WirelessNetworkView from jarabe.desktop.networkviews import OlpcMeshView from jarabe.desktop.networkviews import SugarAdhocView +from jarabe.desktop.viewcontainer import ViewContainer from jarabe.model import network from jarabe.model.network import AccessPoint from jarabe.model.olpcmesh import OlpcMeshManager @@ -403,23 +404,17 @@ class NetworkManagerObserver(object): _CELL_SIZE = 4.0 -class MeshContainer(gtk.Container): +class MeshContainer(ViewContainer): __gtype_name__ = 'SugarMeshContainer' def __init__(self): - gtk.Container.__init__(self) + ViewContainer.__init__(self) - min_width, width = self.do_get_width_request() - min_height, height = self.do_get_height_request(width) + min_width, width = self.get_width_request() + min_height, height = self.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) @@ -442,26 +437,6 @@ class MeshContainer(gtk.Container): 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) diff --git a/src/jarabe/desktop/viewcontainer.py b/src/jarabe/desktop/viewcontainer.py new file mode 100644 index 0000000..e540301 --- /dev/null +++ b/src/jarabe/desktop/viewcontainer.py @@ -0,0 +1,71 @@ +# Copyright (C) 2006-2007 Red Hat, Inc. +# Copyright (C) 2008 One Laptop Per Child +# Copyright (C) 2010 Tomeu Vizoso +# Copyright (C) 2011 Walter Bender +# Copyright (C) 2011 Raul Gutierrez Segales +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +import gobject +import gtk +from sugar.graphics import style + +class ViewContainer(gtk.Container): + __gtype_name__ = 'SugarViewContainer' + + def __init__(self, **kwargs): + gobject.GObject.__init__(self, **kwargs) + + def get_height_request(self, for_width): + return 0, gtk.gdk.screen_height() - style.GRID_CELL_SIZE + + def get_width_request(self): + return 0, gtk.gdk.screen_width() + + 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_request(self, requisition): + requisition.height = gtk.gdk.screen_height() - style.GRID_CELL_SIZE + requisition.width = gtk.gdk.screen_width() + + def do_forall(self, include_internals, forall_cb, user_data): + raise NotImplementedError, "This need to be implemented." + + def do_remove(self, child): + raise NotImplementedError, "This need to be implemented." + + def do_size_allocate(self, allocation): + raise NotImplementedError, "This need to be implemented." -- cgit v0.9.1