From 6bf19eae5239760be2c11fc39b56e11cd40c3efc Mon Sep 17 00:00:00 2001 From: Aleksey Lim Date: Mon, 02 Feb 2009 16:01:31 +0000 Subject: Add a bit of OOP to ground/sound --- (limited to 'ground.py') diff --git a/ground.py b/ground.py index 95e1b4b..99611d2 100644 --- a/ground.py +++ b/ground.py @@ -12,68 +12,82 @@ # 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 gtk +import cStringIO from gettext import gettext as _ from sugar.graphics.objectchooser import ObjectChooser import theme -from document import Document - -PREINSTALLED = 0 -CUSTOM = 1 -TEMPORARY = 2 def load(): - if not Document.ground_filename: - custom = Ground(Document.ground_name, None, TEMPORARY) - custom._pixbuf = Document.ground_orig - THEMES.insert(-1, custom) + from document import Document + + if Document.ground and Document.ground.custom(): + THEMES.insert(-1, Document.ground) class Ground: - def __init__(self, name, file, type): + def __init__(self, name, image, type): self.name = name - self._file = file - if file: self._pixbuf = theme.pixbuf(file) self._type = type self._thumb = None - def filename(self): - if self._type == PREINSTALLED: - return self._file + if type == theme.RESTORED: + tmpfile = os.path.join(theme.SESSION_PATH, '.tmp.png') + file(tmpfile, 'w').write(image) + self._orig = gtk.gdk.pixbuf_new_from_file(tmpfile) + os.unlink(tmpfile) + self._filename = 'ground.png' else: - return None + self._filename = image + self._orig = theme.pixbuf(image) + + def custom(self): + return self._type != theme.PREINSTALLED + + def read(self): + def push(data, buffer): + buffer.write(data) + + buffer = cStringIO.StringIO() + self._orig.save_to_callback(push, 'png', user_data=buffer) + return buffer.getvalue() + + def filename(self): + return self._filename def thumb(self): if not self._thumb: - self._thumb = theme.scale(self._pixbuf) + self._thumb = theme.scale(self._orig) return self._thumb def orig(self): - return self._pixbuf + return self._orig def change(self): - if self._type != CUSTOM: + if self._type != theme.CUSTOM: return self - return theme.choose(lambda title, file: Ground(title, file, TEMPORARY)) + return theme.choose( + lambda title, file: Ground(title, file, theme.JOURNAL)) THEMES = [ - Ground(_('Saturn'), 'images/backpics/bigbg01.gif', PREINSTALLED), - Ground(_('Snowflakes'), 'images/backpics/bigbg02.gif', PREINSTALLED), - Ground(_('Eye'), 'images/backpics/bigbg03.gif', PREINSTALLED), - Ground(_('Blobs'), 'images/backpics/bigbg04.gif', PREINSTALLED), - Ground(_('Star Night'), 'images/backpics/bigbg05.gif', PREINSTALLED), - Ground(_('Forest'), 'images/backpics/bigbg06.gif', PREINSTALLED), - Ground(_('Spiral'), 'images/backpics/bigbg07.gif', PREINSTALLED), - Ground(_('Beam'), 'images/backpics/bigbg08.gif', PREINSTALLED), - Ground(_('Cloth'), 'images/backpics/bigbg09.gif', PREINSTALLED), - Ground(_('Faces'), 'images/backpics/bigbg10.gif', PREINSTALLED), - Ground(_('Leaves'), 'images/backpics/bigbg11.gif', PREINSTALLED), - Ground(_('Vegetables'), 'images/backpics/bigbg12.gif', PREINSTALLED), - Ground(_('Spotlight'), 'images/backpics/bigbg13.gif', PREINSTALLED), - Ground(_('Strips'), 'images/backpics/bigbg14.gif', PREINSTALLED), - Ground(_('Scene'), 'images/backpics/bigbg15.gif', PREINSTALLED), - Ground(_('Rhombs'), 'images/backpics/bigbg16.gif', PREINSTALLED), - Ground(_('Milky Way'), 'images/backpics/bigbg17.gif', PREINSTALLED), + Ground(_('Saturn'), 'images/backpics/bigbg01.gif', theme.PREINSTALLED), + Ground(_('Snowflakes'), 'images/backpics/bigbg02.gif', theme.PREINSTALLED), + Ground(_('Eye'), 'images/backpics/bigbg03.gif', theme.PREINSTALLED), + Ground(_('Blobs'), 'images/backpics/bigbg04.gif', theme.PREINSTALLED), + Ground(_('Star Night'), 'images/backpics/bigbg05.gif', theme.PREINSTALLED), + Ground(_('Forest'), 'images/backpics/bigbg06.gif', theme.PREINSTALLED), + Ground(_('Spiral'), 'images/backpics/bigbg07.gif', theme.PREINSTALLED), + Ground(_('Beam'), 'images/backpics/bigbg08.gif', theme.PREINSTALLED), + Ground(_('Cloth'), 'images/backpics/bigbg09.gif', theme.PREINSTALLED), + Ground(_('Faces'), 'images/backpics/bigbg10.gif', theme.PREINSTALLED), + Ground(_('Leaves'), 'images/backpics/bigbg11.gif', theme.PREINSTALLED), + Ground(_('Vegetables'), 'images/backpics/bigbg12.gif', theme.PREINSTALLED), + Ground(_('Spotlight'), 'images/backpics/bigbg13.gif', theme.PREINSTALLED), + Ground(_('Strips'), 'images/backpics/bigbg14.gif', theme.PREINSTALLED), + Ground(_('Scene'), 'images/backpics/bigbg15.gif', theme.PREINSTALLED), + Ground(_('Rhombs'), 'images/backpics/bigbg16.gif', theme.PREINSTALLED), + Ground(_('Milky Way'), 'images/backpics/bigbg17.gif', theme.PREINSTALLED), None, - Ground(_('Custom'), 'images/backpics/custom.png', CUSTOM)] + Ground(_('Custom'), 'images/backpics/custom.png', theme.CUSTOM)] -- cgit v0.9.1