Skip to content

Commit

Permalink
Views: Replace the hippo based layout with one using GTK+ containers
Browse files Browse the repository at this point in the history
The requirement was to be able to position and size the widgets with
different layouts in the Views. We need to be able to have fixed
positions (e.g. the owner icon and current activity icon) and we need
to be able to change the position (e.g. BuddyIcon in the Neighborhood
View) and move the widget by drag and drop (e.g. RandomLayout).

The implementation uses a gtk.Container (SugarViewContainer) without
an associated GdkWindow to hold the widgets since we do not want to do
drawing in this container. The desired layout and the owner icon and
optional activity icon are passed at initialization time.

A ViewLayout is responsible to calculate the positions and sizes for
the SugarViewContainer. To keep track of the positions it uses a grid
that is initialized on the first allocation. The owner icon
(activity icon) will be added to the grid to make sure it keeps the
fixed position.

The SpreadLayout derives now from the ViewLayout. The SpreadLayout
which is used in the GroupBox and in the MeshContainer does
add all it's children to the grid in order to use the collision
detection from the grid to not place icons over each other.

The RandomLayout does place all it's children in the grid as well
for collision detection purposes.

The Journal has been made hippo-free as well. We set white background
in the ExpandedEntry of the Detail View. For that we change the
ExpandedEntry class to subclass gtk.EventBox because the
gtk.VBox doesn't have a gtk.gdk.Window associated and the background
can't be set otherwise.

This patch is based on the work from Walter Bender,
Daniel Drake and Raul Gutierrez Segales.

Signed-off-by: Simon Schampijer <[email protected]>
Signed-off-by: Manuel Quiñones <[email protected]>
Signed-off-by: Daniel Narvaez <[email protected]>
  • Loading branch information
erikos committed Aug 13, 2012
1 parent 5ad6ae0 commit d9fbf9d
Show file tree
Hide file tree
Showing 20 changed files with 917 additions and 1,008 deletions.
4 changes: 2 additions & 2 deletions src/jarabe/desktop/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ sugar_PYTHON = \
networkviews.py \
schoolserver.py \
snowflakelayout.py \
spreadlayout.py \
transitionbox.py
transitionbox.py \
viewcontainer.py
390 changes: 203 additions & 187 deletions src/jarabe/desktop/favoriteslayout.py

Large diffs are not rendered by default.

404 changes: 193 additions & 211 deletions src/jarabe/desktop/favoritesview.py

Large diffs are not rendered by default.

31 changes: 17 additions & 14 deletions src/jarabe/desktop/friendview.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,30 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

import hippo
import gtk

from sugar.graphics.icon import CanvasIcon
from sugar.graphics import style

from jarabe.view.buddyicon import BuddyIcon
from jarabe.view.eventicon import EventIcon
from jarabe.model import bundleregistry


class FriendView(hippo.CanvasBox):
class FriendView(gtk.VBox):
def __init__(self, buddy, **kwargs):
hippo.CanvasBox.__init__(self, **kwargs)
gtk.VBox.__init__(self)

# round icon sizes to an even number so that it can be accurately
# centered in a larger bounding box also of even dimensions
size = style.LARGE_ICON_SIZE & ~1

self._buddy = buddy
self._buddy_icon = BuddyIcon(buddy)
self._buddy_icon.props.size = style.LARGE_ICON_SIZE
self.append(self._buddy_icon)

self._activity_icon = CanvasIcon(size=style.LARGE_ICON_SIZE)
self._activity_icon_visible = False
self._buddy_icon.props.pixel_size = size
self.add(self._buddy_icon)
self._buddy_icon.show()

self._activity_icon = EventIcon(pixel_size=size)
self._update_activity()

self._buddy.connect('notify::current-activity',
Expand All @@ -51,9 +54,9 @@ def _get_new_icon_name(self, ps_activity):
return None

def _remove_activity_icon(self):
if self._activity_icon_visible:
if self._activity_icon.get_visible():
self._activity_icon.hide()
self.remove(self._activity_icon)
self._activity_icon_visible = False

def __buddy_notify_current_activity_cb(self, buddy, pspec):
self._update_activity()
Expand All @@ -70,9 +73,9 @@ def _update_activity(self):
if name:
self._activity_icon.props.file_name = name
self._activity_icon.props.xo_color = self._buddy.props.color
if not self._activity_icon_visible:
self.append(self._activity_icon, hippo.PACK_EXPAND)
self._activity_icon_visible = True
if not self._activity_icon.get_visible():
self.add(self._activity_icon)
self._activity_icon.show()
else:
self._remove_activity_icon()

Expand Down
3 changes: 3 additions & 0 deletions src/jarabe/desktop/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ def add(self, child, width, height, x=None, y=None, locked=False):
if weight > 0:
self._detect_collisions(child)

def is_in_grid(self, child):
return child in self._children

def remove(self, child):
self._children.remove(child)
self.remove_weight(self._child_rects[child])
Expand Down
51 changes: 16 additions & 35 deletions src/jarabe/desktop/groupbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,47 +16,40 @@

import logging

import gobject
import hippo
import gconf

from sugar.graphics import style
from sugar.graphics.icon import CanvasIcon
from sugar.graphics.xocolor import XoColor

from jarabe.view.buddymenu import BuddyMenu
from jarabe.view.eventicon import EventIcon
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.viewcontainer import ViewContainer
from jarabe.desktop.favoriteslayout import SpreadLayout


class GroupBox(hippo.Canvas):
class GroupBox(ViewContainer):
__gtype_name__ = 'SugarGroupBox'

def __init__(self):
logging.debug('STARTUP: Loading the group view')

gobject.GObject.__init__(self)

self._box = hippo.CanvasBox()
self._box.props.background_color = style.COLOR_WHITE.get_int()
self.set_root(self._box)

self._friends = {}

self._layout = SpreadLayout()
self._box.set_layout(self._layout)
layout = SpreadLayout()

client = gconf.client_get_default()
color = XoColor(client.get_string('/desktop/sugar/user/color'))
owner_icon = EventIcon(icon_name='computer-xo', cache=True,
xo_color=color)
# Round off icon size to an even number to ensure that the icon
# is placed evenly in the grid
owner_icon.props.pixel_size = style.LARGE_ICON_SIZE & ~1
owner_icon.set_palette(BuddyMenu(get_owner_instance()))

self._owner_icon = CanvasIcon(icon_name='computer-xo', cache=True,
xo_color=color)
self._owner_icon.props.size = style.LARGE_ICON_SIZE
ViewContainer.__init__(self, layout, owner_icon)

self._owner_icon.set_palette(BuddyMenu(get_owner_instance()))
self._layout.add(self._owner_icon)
self._friends = {}

friends_model = friends.get_model()

Expand All @@ -68,27 +61,15 @@ def __init__(self):

def add_friend(self, buddy_info):
icon = FriendView(buddy_info)
self._layout.add(icon)

self.add(icon)
self._friends[buddy_info.get_key()] = icon
icon.show()

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.remove(icon)
del self._friends[key]
icon.destroy()

def do_size_allocate(self, allocation):
width = allocation.width
height = allocation.height

min_w_, icon_width = self._owner_icon.get_width_request()
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)

hippo.Canvas.do_size_allocate(self, allocation)
22 changes: 11 additions & 11 deletions src/jarabe/desktop/homebox.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __init__(self):

gobject.GObject.__init__(self)

self._favorites_view = favoritesview.FavoritesView()
self._favorites_box = favoritesview.FavoritesBox()
self._list_view = ActivitiesList()

self._toolbar = HomeToolbar()
Expand Down Expand Up @@ -78,14 +78,14 @@ def show_software_updates_alert(self):
if self._list_view in self.get_children():
self._list_view.add_alert(alert)
else:
self._favorites_view.add_alert(alert)
self._favorites_box.add_alert(alert)
alert.connect('response', self.__software_update_response_cb)

def __software_update_response_cb(self, alert, response_id):
if self._list_view in self.get_children():
self._list_view.remove_alert()
else:
self._favorites_view.remove_alert()
self._favorites_box.remove_alert()

if response_id != gtk.RESPONSE_REJECT:
update_trigger_file = os.path.expanduser('~/.sugar-update')
Expand All @@ -106,7 +106,7 @@ def __software_update_response_cb(self, alert, response_id):
def __toolbar_query_changed_cb(self, toolbar, query):
self._query = query.lower()
self._list_view.set_filter(self._query)
self._favorites_view.set_filter(self._query)
self._favorites_box.set_filter(self._query)

def __toolbar_view_changed_cb(self, toolbar, view):
self._set_view(view)
Expand All @@ -116,12 +116,12 @@ def _set_view(self, view):
if self._list_view in self.get_children():
self.remove(self._list_view)

if self._favorites_view not in self.get_children():
self.add(self._favorites_view)
self._favorites_view.show()
if self._favorites_box not in self.get_children():
self.add(self._favorites_box)
self._favorites_box.show()
elif view == _LIST_VIEW:
if self._favorites_view in self.get_children():
self.remove(self._favorites_view)
if self._favorites_box in self.get_children():
self.remove(self._favorites_box)

if self._list_view not in self.get_children():
self.add(self._list_view)
Expand All @@ -146,10 +146,10 @@ def focus_search_entry(self):
self._toolbar.search_entry.grab_focus()

def set_resume_mode(self, resume_mode):
self._favorites_view.set_resume_mode(resume_mode)
self._favorites_box.set_resume_mode(resume_mode)
if resume_mode and self._query != '':
self._list_view.set_filter(self._query)
self._favorites_view.set_filter(self._query)
self._favorites_box.set_filter(self._query)


class HomeToolbar(gtk.Toolbar):
Expand Down
2 changes: 2 additions & 0 deletions src/jarabe/desktop/homewindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ def __init__(self):

self.realize()
self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DESKTOP)
self.modify_bg(gtk.STATE_NORMAL,
style.COLOR_WHITE.get_gdk_color())

self.add_events(gtk.gdk.VISIBILITY_NOTIFY_MASK)
self.connect('visibility-notify-event',
Expand Down
Loading

0 comments on commit d9fbf9d

Please sign in to comment.