From 74a15fd36c1bd5dd833dfb9483acecd4885f8f63 Mon Sep 17 00:00:00 2001 From: Santiago Collazo Date: Sat, 23 Mar 2013 02:40:08 +0000 Subject: Merge remote-tracking branch 'ajay/0.97.7-as-base' into devel --- diff --git a/configure.ac b/configure.ac index 87cac82..c4dc438 100644 --- a/configure.ac +++ b/configure.ac @@ -52,6 +52,7 @@ data/sugar-emulator.desktop extensions/cpsection/aboutcomputer/Makefile extensions/cpsection/aboutme/Makefile extensions/cpsection/accessibility/Makefile +extensions/cpsection/background/Makefile extensions/cpsection/datetime/Makefile extensions/cpsection/frame/Makefile extensions/cpsection/keyboard/Makefile diff --git a/extensions/cpsection/Makefile.am b/extensions/cpsection/Makefile.am index 83cea29..5fb1a2d 100644 --- a/extensions/cpsection/Makefile.am +++ b/extensions/cpsection/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = aboutme aboutcomputer accessibility datetime frame keyboard language \ +SUBDIRS = aboutme aboutcomputer accessibility background datetime frame keyboard language \ modemconfiguration network power sugardir = $(pkgdatadir)/extensions/cpsection diff --git a/extensions/cpsection/background/Makefile.am b/extensions/cpsection/background/Makefile.am new file mode 100644 index 0000000..4984b6c --- /dev/null +++ b/extensions/cpsection/background/Makefile.am @@ -0,0 +1,6 @@ +sugardir = $(pkgdatadir)/extensions/cpsection/background + +sugar_PYTHON = \ + __init__.py \ + model.py \ + view.py diff --git a/extensions/cpsection/background/__init__.py b/extensions/cpsection/background/__init__.py new file mode 100644 index 0000000..8a97483 --- /dev/null +++ b/extensions/cpsection/background/__init__.py @@ -0,0 +1,21 @@ +# Copyright (C) 2008, OLPC +# +# 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 + +from gettext import gettext as _ + +CLASS = 'Background' +ICON = 'image-x-generic' +TITLE = _('Background') diff --git a/extensions/cpsection/background/model.py b/extensions/cpsection/background/model.py new file mode 100644 index 0000000..783781a --- /dev/null +++ b/extensions/cpsection/background/model.py @@ -0,0 +1,68 @@ +# 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 +# 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 +# + +from gi.repository import GConf +from gi.repository import GdkPixbuf + +from sugar3.graphics import style +from jarabe.journal.model import get_documents_path + +import os + +BACKGROUNDS_DIRS = [os.path.join('/usr', 'share', 'backgrounds'), + get_documents_path()] + + +def set_background(file_path): + client = GConf.Client.get_default() + if file_path is None: + client.set_string('/desktop/sugar/user/background', '') + else: + client.set_string('/desktop/sugar/user/background', str(file_path)) + return 1 + + +def get_background(): + client = GConf.Client.get_default() + return client.get_string('/desktop/sugar/user/background') + + +def fill_background_list(store): + paths_list = [] + + for _dir in BACKGROUNDS_DIRS: + if _dir and os.path.exists(_dir): + for root, dirs, files in os.walk(_dir): + for bg in files: + path = os.path.join(root, bg) + if os.path.isfile(path): + try: + pixbuf = \ + GdkPixbuf.Pixbuf.new_from_file_at_size(path, + style.XLARGE_ICON_SIZE, style.XLARGE_ICON_SIZE) + + store.append([pixbuf, path]) + paths_list.append(path) + except: + pass + return paths_list + +BACKGROUND_CHOOSED = get_background() + + +def undo(store): + set_background(BACKGROUND_CHOOSED) diff --git a/extensions/cpsection/background/view.py b/extensions/cpsection/background/view.py new file mode 100644 index 0000000..fe4fc2c --- /dev/null +++ b/extensions/cpsection/background/view.py @@ -0,0 +1,137 @@ +# 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 +# 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 + +from gi.repository import Gtk +from gi.repository import GdkPixbuf + +from sugar3.graphics import style +from sugar3.graphics.toolbutton import ToolButton +from jarabe.controlpanel.sectionview import SectionView +from jarabe.controlpanel.inlinealert import InlineAlert + +from gettext import gettext as _ + + +class Background(SectionView): + + def __init__(self, model, alerts): + SectionView.__init__(self) + + self._model = model + self._restart_alerts = alerts + + if 'background' in self._restart_alerts: + self._restart_alert.props.msg = self.restart_msg + self._restart_alert.show() + + self.set_border_width(style.DEFAULT_SPACING * 2) + self.set_spacing(style.DEFAULT_SPACING) + + label_box = Gtk.Box() + label_bg = Gtk.Label(label=_('Select a background:')) + label_bg.modify_fg(Gtk.StateType.NORMAL, + style.COLOR_SELECTION_GREY.get_gdk_color()) + label_box.pack_start(label_bg, False, True, 0) + self.pack_start(label_box, False, True, 1) + + clear_button = Gtk.Button() + clear_button.set_label(_('Clear background')) + clear_button.connect('clicked', self._clear_clicked_cb) + clear_button.show() + self.pack_end(clear_button, False, True, 0) + + sw = Gtk.ScrolledWindow() + sw.set_shadow_type(Gtk.ShadowType.ETCHED_IN) + sw.set_policy(Gtk.PolicyType.AUTOMATIC, + Gtk.PolicyType.AUTOMATIC) + + store = Gtk.ListStore(GdkPixbuf.Pixbuf, str) + + icon_view = Gtk.IconView.new_with_model(store) + icon_view.set_selection_mode(Gtk.SelectionMode.SINGLE) + icon_view.connect('selection-changed', self._background_selected, + store) + icon_view.set_pixbuf_column(0) + icon_view.grab_focus() + + pl = model.fill_background_list(store) + self._select_background(icon_view, pl) + sw.add(icon_view) + + self.pack_start(sw, True, True, 0) + + self._alert_box = Gtk.HBox(spacing=style.DEFAULT_SPACING) + self.pack_start(self._alert_box, False, False, 0) + self._alert_box.show() + + self._restart_alert = InlineAlert() + self._restart_alert.props.msg = self.restart_msg + self._alert_box.pack_start(self._restart_alert, True, True, 0) + + self.setup() + + def _get_selected_path(self, widget, store): + try: + iter_ = store.get_iter(widget.get_selected_items()[0]) + image_path = store.get(iter_, 1)[0] + + return image_path, iter_ + except: + return None + + def _background_selected(self, widget, store): + selected = self._get_selected_path(widget, store) + + if selected is None: + return + + image_path, _iter = selected + if image_path != self._model.BACKGROUND_CHOOSED: + iter_ = store.get_iter(widget.get_selected_items()[0]) + image_path = store.get(iter_, 1)[0] + self._model.set_background(image_path) + self._restart_alerts.append('background') + self.needs_restart = True + self._alert_box.show() + self._restart_alert.show() + else: + if 'background' in self.restart_alerts: + self._restart_alerts.remove('background') + self.needs_restart = False + self._restart_alert.hide() + + def _select_background(self, icon_view, paths_list): + background = self._model.get_background() + if background in paths_list: + _path = paths_list.index(background) + path = Gtk.TreePath.new_from_string('%s' % _path) + icon_view.select_path(path) + self.needs_restart = False + + def _clear_clicked_cb(self, widget, event=None): + self._model.set_background(None) + self._restart_alerts.append('background') + self.needs_restart = True + self._alert_box.show() + self._restart_alert.show() + + def setup(self): + self.needs_restart = False + self.show_all() + self._restart_alert.hide() + + def undo(self): + self._model.undo() diff --git a/src/jarabe/desktop/homebox.py b/src/jarabe/desktop/homebox.py index b87c345..aca203d 100644 --- a/src/jarabe/desktop/homebox.py +++ b/src/jarabe/desktop/homebox.py @@ -20,6 +20,9 @@ import os from gi.repository import GObject from gi.repository import Gtk +from gi.repository import GdkPixbuf +from gi.repository import GConf +from gi.repository import Gdk from sugar3.graphics import style from sugar3.graphics.alert import Alert @@ -33,6 +36,14 @@ _FAVORITES_VIEW = 0 _LIST_VIEW = 1 +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() + + class HomeBox(Gtk.VBox): __gtype_name__ = 'SugarHomeBox' @@ -41,7 +52,11 @@ class HomeBox(Gtk.VBox): Gtk.VBox.__init__(self) + self._favorites_eventbox = Gtk.EventBox() + self._favorites_eventbox.connect('draw', self._draw_background) self._favorites_box = favoritesview.FavoritesBox() + self._favorites_eventbox.add(self._favorites_box) + self._list_view = ActivitiesList() toolbar.connect('query-changed', self.__toolbar_query_changed_cb) @@ -53,6 +68,7 @@ class HomeBox(Gtk.VBox): self._set_view(_FAVORITES_VIEW) self._query = '' + self._update_background_image() def show_software_updates_alert(self): alert = Alert() @@ -127,13 +143,13 @@ class HomeBox(Gtk.VBox): if self._list_view in self.get_children(): self.remove(self._list_view) - if self._favorites_box not in self.get_children(): - self.add(self._favorites_box) - self._favorites_box.show() - self._favorites_box.grab_focus() + if self._favorites_eventbox not in self.get_children(): + self.add(self._favorites_eventbox) + self._favorites_eventbox.show_all() + self._favorites_eventbox.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 +176,32 @@ 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): + self._background_pixbuf = None + + if BACKGROUND_IMAGE_PATH is None: + return + + 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: + pass -- cgit v0.9.1