[Syncropated-commits] r166 - trunk/src

zimmerle at garage.maemo.org zimmerle at garage.maemo.org
Tue Jan 30 02:12:37 EET 2007


Author: zimmerle
Date: 2007-01-30 02:12:37 +0200 (Tue, 30 Jan 2007)
New Revision: 166

Added:
   trunk/src/LocalPhotoManager.py
Log:
LocalPhotoManager first import

Added: trunk/src/LocalPhotoManager.py
===================================================================
--- trunk/src/LocalPhotoManager.py	2007-01-30 00:07:32 UTC (rev 165)
+++ trunk/src/LocalPhotoManager.py	2007-01-30 00:12:37 UTC (rev 166)
@@ -0,0 +1,179 @@
+#!/usr/bin/python
+
+# LocalPhotoManager
+#
+#  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 ElementPhoto import ElementPhoto
+
+log = Logger()
+config = Configuration()
+icons = Icons()
+utils = Utils()
+
+class LocalPhotoManager(gobject.GObject):
+	"""
+	Manager all photo files
+
+	"""
+
+	TYPE = 'photo'
+
+	__total_loaded_files = 0
+	__model = None
+
+	def __init__(self):
+		gobject.GObject.__init__(self)
+		log.debug('LocalPhotoManager :: attach_icon_view :: ' + 
+			'Starting local photo manager....')
+		self.__total_loaded_files = 0
+		self.__model = None
+		self.__bigger_icon = 0
+
+	def attach_icon_view(self, icon_view):
+		log.debug('LocalPhotoManager :: attach_icon_view :: ' +
+			'Attaching the icon view...')
+		log.debug('LocalPhotoManager :: attach_icon_view :: ' + 
+			'attaching: ' + str(icon_view))
+
+		self.__model = gtk.ListStore(str, gtk.gdk.Pixbuf,
+			gobject.TYPE_PYOBJECT)
+		self.__model_filter = self.__model.filter_new()
+
+
+		icon_view.set_model(self.__model_filter)
+
+
+		icon_view.set_text_column(0)
+		icon_view.set_pixbuf_column(1)
+		icon_view.set_orientation(gtk.ORIENTATION_VERTICAL)
+		icon_view.set_selection_mode(gtk.SELECTION_SINGLE)
+
+		icon_view.set_item_width(120)
+		icon_view.set_columns(0)
+
+		col = gtk.TreeViewColumn()
+		renderer = gtk.CellRendererPixbuf()
+		col.pack_start(renderer, False)
+		col.set_attributes(renderer, pixbuf=0)
+		col.set_alignment(0)
+
+		self.__icon_view = icon_view
+
+		icon_view.connect('selection-changed', 
+			self.cb_icon_view_item_activaded)
+
+
+	def content_verify_func(self, uri):
+		## FIXME: its should check if the file is a image or not.
+		return True
+
+	def del_registrys(self, uri, obj):
+		"""
+		Used to remove registers from the ImageView
+
+		"""
+		self.__model.remove(obj)
+		
+
+	def add_registry(self, uri, gtks):
+		"""
+		Used to add registers from the ImageView
+
+		"""
+		log.debug('LocalPhotoManager :: attach_icon_view :: Add registry...')
+		if gtks != None:
+			file = gtks[0]
+			files_loaded_label = gtks[1]
+			progress_bar = gtks[2]
+			lenght = gtks[3]
+
+			file_label = os.path.split(uri)[1]
+			file_label = utils.unicodify(file_label)
+			file_label = utils.resize_string(file_label, 40)
+			file.set_text(file_label)
+
+			files_loaded_label.set_text(str(self.__total_loaded_files) +
+					' files loaded.')
+
+			log.debug('LocalPhotoManager :: progress_bar : ' + 
+					'Total of loaded files: ' + str(self.__total_loaded_files))
+			log.debug('LocalPhotoManager :: progress_bar : ' +
+					'Total of files: ' + str(lenght))
+
+			progress_bar.set_fraction(float(float(self.__total_loaded_files)/float(lenght-2)))
+
+		if not os.path.isfile(uri):
+		 	return
+
+		photo = ElementPhoto(uri)
+		photo.connect('photo-update', self.update_photo)
+
+		new_iter = self.__model.append([photo.get_filename(), photo.get_pixbuf(), photo])
+		photo.set_iter(new_iter)
+
+		self.__total_loaded_files += 1
+
+		return new_iter
+
+
+	def get_attached_tree_view(self):
+		"""
+		Return the attached treeview/ImageView
+
+		"""
+		return self.__icon_view
+
+
+	def update_photo(self, photo):
+		"""
+		Used to update some photo.
+
+		"""
+		self.__model.set_value(photo.get_iter(), 1, photo.get_pixbuf())
+
+
+	def cb_icon_view_item_activaded(self, iconview):
+		"""
+		When the user selected one photo
+
+		"""
+		log.debug('LocalPhotoManager :: Icon view element activeded: ' +
+			str(iconview.get_selected_items()))
+		for i in iconview.get_selected_items():
+			log.debug('LocalPhotoManager :: Icon view element activeded: ' +
+				str(i))
+			iter = self.__model.get_iter(i)
+			log.debug('LocalPhotoManager :: Icon view element activeded: ' +
+				str(iter))
+			log.debug('LocalPhotoManager :: Icon view element activeded: ' +
+				str(self.__model.get_value(iter, 2).get_file_path()))
+
+	



More information about the Syncropated-commits mailing list