Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWalter Bender <walter.bender@gmail.com>2013-03-31 20:45:12 (GMT)
committer Walter Bender <walter.bender@gmail.com>2013-03-31 20:45:12 (GMT)
commit6b14a4c4b35f737b3b60c6b8ce9a5055f68bbd44 (patch)
tree9bdc10fcce94434b5985ccc49e9a23b081a320db
parentf6088f536609d2d93357d9b27a6475dbbb6405c3 (diff)
Add controlpanel section for selecting background image
-rw-r--r--configure.ac1
-rw-r--r--extensions/cpsection/Makefile.am2
-rw-r--r--extensions/cpsection/background/Makefile.am6
-rw-r--r--extensions/cpsection/background/__init__.py21
-rw-r--r--extensions/cpsection/background/model.py70
-rw-r--r--extensions/cpsection/background/view.py137
6 files changed, 236 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac
index a4eb829..624e774 100644
--- a/configure.ac
+++ b/configure.ac
@@ -51,6 +51,7 @@ data/Makefile
data/sugar-emulator.desktop
extensions/cpsection/aboutcomputer/Makefile
extensions/cpsection/aboutme/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 a92b5dd..9434d45 100644
--- a/extensions/cpsection/Makefile.am
+++ b/extensions/cpsection/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = aboutme aboutcomputer datetime frame keyboard language \
+SUBDIRS = aboutme aboutcomputer background datetime frame keyboard language \
modemconfiguration network power updater
sugardir = $(pkgdatadir)/extensions/cpsection
diff --git a/extensions/cpsection/background/Makefile.am b/extensions/cpsection/background/Makefile.am
new file mode 100644
index 0000000..7c5da12
--- /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..dd80750
--- /dev/null
+++ b/extensions/cpsection/background/model.py
@@ -0,0 +1,70 @@
+# Copyright (C) 2012 Agustin Zubiaga <aguz@sugarlabs.org>
+#
+# 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 os
+import logging
+
+from gi.repository import GConf
+from gi.repository import GdkPixbuf
+
+from sugar3.graphics import style
+from jarabe.journal.model import get_documents_path
+
+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 os.path.exists(_dir) and _dir:
+ for bg in os.listdir(_dir):
+ path = os.path.join(_dir, 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 Exception as e:
+ logging.debug(
+ 'Unable to create pixbuf from file %s: %s' % \
+ (path, str(e)))
+ 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..c106fcb
--- /dev/null
+++ b/extensions/cpsection/background/view.py
@@ -0,0 +1,137 @@
+# Copyright (C) 2012 Agustin Zubiaga <aguz@sugarlabs.org>
+#
+# 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()