From e2582f55996c91e7c686debc4db16db04c277106 Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Sun, 31 Mar 2013 21:06:37 +0000 Subject: Add background image to home view --- diff --git a/src/jarabe/desktop/homebox.py b/src/jarabe/desktop/homebox.py index b87c345..3b59348 100644 --- a/src/jarabe/desktop/homebox.py +++ b/src/jarabe/desktop/homebox.py @@ -1,4 +1,6 @@ # Copyright (C) 2008 One Laptop Per Child +# Copyright (C) 2008-2013 Sugar Labs +# Copyright (C) 2012 Agustin Zubiaga # # 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 @@ -19,7 +21,10 @@ import logging import os from gi.repository import GObject +from gi.repository import GdkPixbuf +from gi.repository import GConf from gi.repository import Gtk +from gi.repository import Gdk from sugar3.graphics import style from sugar3.graphics.alert import Alert @@ -29,6 +34,12 @@ from jarabe.desktop import favoritesview from jarabe.desktop.activitieslist import ActivitiesList from jarabe.util.normalize import normalize_string +def get_bg_image_path(): + client = GConf.Client.get_default() + return client.get_string('/desktop/sugar/user/background') + +_BACKGROUND_IMAGE_PATH = get_bg_image_path() + _FAVORITES_VIEW = 0 _LIST_VIEW = 1 @@ -41,7 +52,13 @@ class HomeBox(Gtk.VBox): Gtk.VBox.__init__(self) - self._favorites_box = favoritesview.FavoritesBox() + self._background_pixbuf = None + + self._favorites_eventbox = Gtk.EventBox() + self._favorites_eventbox.connect('draw', self._draw_background) + self._favorites_box = favoritesview.FavoritesBox(True) + self._favorites_eventbox.add(self._favorites_box) + self._list_view = ActivitiesList() toolbar.connect('query-changed', self.__toolbar_query_changed_cb) @@ -54,6 +71,8 @@ class HomeBox(Gtk.VBox): self._set_view(_FAVORITES_VIEW) self._query = '' + self._update_background_image() + def show_software_updates_alert(self): alert = Alert() updater_icon = Icon(icon_name='module-updater', @@ -128,12 +147,15 @@ class HomeBox(Gtk.VBox): self.remove(self._list_view) if self._favorites_box not in self.get_children(): - self.add(self._favorites_box) + self.add(self._favorites_eventbox) + self._favorites_eventbox.show_all() self._favorites_box.show() self._favorites_box.grab_focus() elif view == _LIST_VIEW: if self._favorites_box in self.get_children(): self.remove(self._favorites_box) + if self._favorites_eventbox in self.get_children(): + self.remove(self._favorites_eventbox) if self._list_view not in self.get_children(): self.add(self._list_view) @@ -160,3 +182,28 @@ class HomeBox(Gtk.VBox): if resume_mode and self._query != '': self._list_view.set_filter(self._query) self._favorites_box.set_filter(self._query) + + def _draw_background(self, widget, context): + if self._background_pixbuf is None: + return + + alloc = widget.get_allocation() + + if self._background_pixbuf.get_width() != alloc.width or \ + self._background_pixbuf.get_height() != alloc.height: + self._background_pixbuf = self._background_pixbuf.scale_simple( + alloc.width, + alloc.height, + GdkPixbuf.InterpType.TILES) + Gdk.cairo_set_source_pixbuf(context, self._background_pixbuf, 0, 0) + context.paint() + + def _update_background_image(self, *args): + if os.path.exists(_BACKGROUND_IMAGE_PATH): + try: + self._background_pixbuf = GdkPixbuf.Pixbuf.new_from_file( + _BACKGROUND_IMAGE_PATH) + self._favorites_eventbox.queue_draw() + except Exception as e: + logging.debug('Failed to update background image %s: %s' % \ + (_BACKGROUND_IMAGE_PATH, str(e))) -- cgit v0.9.1