[Syncropated-commits] r164 - trunk/src
zimmerle at garage.maemo.org
zimmerle at garage.maemo.org
Tue Jan 30 02:04:22 EET 2007
Author: zimmerle
Date: 2007-01-30 02:04:22 +0200 (Tue, 30 Jan 2007)
New Revision: 164
Added:
trunk/src/ElementPhoto.py
Log:
ElementPhoto first import
Added: trunk/src/ElementPhoto.py
===================================================================
--- trunk/src/ElementPhoto.py 2007-01-29 23:51:56 UTC (rev 163)
+++ trunk/src/ElementPhoto.py 2007-01-30 00:04:22 UTC (rev 164)
@@ -0,0 +1,240 @@
+#!/usr/bin/python
+
+# ElementPhoto
+#
+# Copyright (c) 2006 INdT (Instituto Nokia de Technologia)
+#
+# Author: Felipe Zimmerle <felipe at zimmerle.org>
+# Kenneth Rohde Christiansen <kenneth.christiansen at gmail.com>
+#
+# 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+# USA
+
+
+import gobject
+import gtk
+import os
+
+from Logger import Logger
+from Configuration import Configuration
+from Icons import Icons
+from Utils import Utils
+from Exif import Exif
+
+log = Logger()
+config = Configuration()
+icons = Icons()
+utils = Utils()
+
+
+class ElementPhoto(gobject.GObject):
+ """
+ Handler photo files
+
+ """
+
+
+ __file_path = None
+ __iter = iter
+
+ __gsignals__ = {
+ 'photo-update' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ())
+ }
+
+
+ def __init__(self, filepath=None):
+ gobject.GObject.__init__(self)
+ self.__pixbuf = None
+ self.set_file_path(filepath)
+ self.pixbuf_loaded = False
+ self.pixbuf = None
+ config.connect('configuration_changed',
+ self.cb_configuration_changed)
+ self.pixbuf_orig = None
+
+ def set_file_path(self, filepath):
+ """
+ Set file path
+
+ """
+ self.__file_path = filepath
+
+
+ def get_file_path(self):
+ """
+ Return the file path
+
+ """
+ return self.__file_path
+
+ def get_filename(self):
+ """
+ Return the file name
+
+ """
+ return os.path.split(self.__file_path)[1]
+
+ def get_pixbuf(self):
+ """
+ Return the pixbuf, if image is not loaded yet, its return a loading img.
+
+ """
+ if self.pixbuf == None:
+ self.pixbuf = icons.load_icon('tux-loading', 64)
+ self.pixbuf = self.pixbuf.scale_simple( int(config.getValue('iconview_thumbnail_width')),
+ int(config.getValue('iconview_thumbnail_height')),
+ gtk.gdk.INTERP_TILES)
+
+ if self.pixbuf_loaded == False:
+ imageLoader = ImageLoader()
+ log.debug('ImageLoader :: Asking for image: ' + str(self.get_file_path()) + ' loading... ' + str(self))
+ gobject.idle_add(imageLoader.load_image, self.get_file_path(), self._photo_loaded)
+ self.pixbuf_loaded = True
+
+ return self.pixbuf
+
+ def _photo_loaded(self, data=None):
+ """
+ Callback called when the photo is complete loaded.
+
+ """
+ if self.pixbuf_orig is None and data is not None:
+ self.pixbuf_orig = data.scale_simple(int(200),
+ int(200),
+ gtk.gdk.INTERP_TILES)
+
+ self.pixbuf = self.pixbuf_orig.scale_simple(int(config.getValue('iconview_thumbnail_width')),
+ int(config.getValue('iconview_thumbnail_height')),
+ gtk.gdk.INTERP_TILES)
+
+ self.emit('photo-update')
+
+
+ def set_iter(self, iter):
+ """
+ Use the set this photo iterator at the ImageView. Used by the photo
+ to update it self.
+
+ """
+ log.debug('ElementPhoto :: ' + str(iter))
+ self.__iter = iter
+
+ def get_iter(self):
+ """
+ Get this element iterator at the ImageView (look set_iter)
+
+ """
+ return self.__iter
+
+
+ def get_size(self):
+ """
+ Return the picture size, should be used once :P
+
+ """
+ return "800x600"
+
+ def get_exif_date(self):
+ """
+ Should return some exif important data.
+ """
+ return "data"
+
+
+ def cb_configuration_changed(self, emitent, key, value):
+ """
+ Capture the configuration changed events.
+
+ """
+ if key == 'iconview_thumbnail_width' or key == 'iconview_thumbnail_height':
+ log.debug('ElementPhoto :: Configuration changed: new '
+ 'dimensions: ' + config.getValue('iconview_thumbnail_width')
+ + "x"
+ + config.getValue('iconview_thumbnail_height'))
+
+ self._photo_loaded(self.pixbuf)
+
+
+
+
+class ImageLoader(gobject.GObject):
+ """
+ Just a indepndent SERIAL image loader....
+
+ """
+
+ queue = None
+ __instance = None
+
+ def __new__(self):
+
+ if self.__instance == None:
+ self.__instance = super(ImageLoader, self).__new__(self)
+ self.running_loader = False
+ self.queue = []
+
+ return self.__instance
+
+ def __init__(self):
+ """
+ Constructor
+
+ Start the self watch job, to check for new files
+ in queue...
+
+ """
+ gobject.timeout_add(100, self.check_queue)
+
+
+ def load_image(self, file_path, return_method):
+ """
+ This is the guy who really read the images.
+
+ """
+ log.debug('ImageLoader :: New photo added to loader schema: ' +
+ str(file_path))
+ self.queue.append((file_path, return_method))
+ log.debug('ImageLoader :: : [' +
+ str(len(self.queue)) + '] ')
+
+ return False
+
+ def check_queue(self):
+ if not self.running_loader and len(self.queue) > 0:
+ self.running_loader = True
+ (file_path, self.return_method) = self.queue[0]
+ del(self.queue[0])
+ self.debug_file_path = file_path
+ try:
+ while gtk.events_pending():
+ gtk.main_iteration(False)
+
+ log.debug('ImageLoader :: ' +
+ ': Starting...! [' + str(file_path) + ']')
+ self.pixbuf = gtk.gdk.pixbuf_new_from_file(file_path)
+ self.return_method(self.pixbuf)
+ except:
+ log.debug('ImageLoader :: ' +
+ ' : Fail!')
+ pass
+
+ log.debug('ImageLoader :: ' +
+ ' : Done!')
+
+ self.running_loader = False
+ return True
+
+
+
More information about the Syncropated-commits
mailing list