diff --git a/ChangeLog b/ChangeLog index 6322f5908..d365cd932 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2005-01-03 Don Allingham + * src/GrampsDbBase.py: move all thumbnail creation here to have + a common thumbnail scheme. + * src/GrampsInMemDB.py: remove thumbnail handling, use base class + 2005-01-02 Alex Roitman * src/Report.py: Add support for a semi-common 'dispf'. * src/ReportOptions.py: Add support for a semi-common 'dispf'. diff --git a/src/GrampsDbBase.py b/src/GrampsDbBase.py index 03259b328..e18969073 100644 --- a/src/GrampsDbBase.py +++ b/src/GrampsDbBase.py @@ -37,6 +37,9 @@ import time import locale import re from gettext import gettext as _ +import os +import md5 +import gtk import GrampsGconfKeys import Utils @@ -1217,13 +1220,35 @@ class GrampsDbBase: else: return cols + def _build_thumb_path(self,path): + base = os.path.expanduser('~/.gramps/thumb') + m = md5.md5(path) + return os.path.join(base,m.hexdigest()+'.jpg') + def get_thumbnail_image(self,handle): data = self.media_map.get(handle) if data: - import ImgManip - return ImgManip.get_thumbnail_image(data[2]) + filename = self._build_thumb_path(data[2]) + if not os.path.isfile(filename): + self.set_thumbnail_image(handle,data[2]) + return gtk.gdk.pixbuf_new_from_file(filename) else: return None + + def set_thumbnail_image(self,handle,path): + try: + pixbuf = gtk.gdk.pixbuf_new_from_file(path) + w = pixbuf.get_width() + h = pixbuf.get_height() + scale = 96.0 / (float(max(w,h))) + + pw = int(w*scale) + ph = int(h*scale) + + pixbuf = pixbuf.scale_simple(pw,ph,gtk.gdk.INTERP_BILINEAR) + pixbuf.save(self._build_thumb_path(path),"jpeg") + except: + print "Could not create thumbnail for",path class Transaction: """ diff --git a/src/GrampsInMemDB.py b/src/GrampsInMemDB.py index c68cddf1f..77347b989 100644 --- a/src/GrampsInMemDB.py +++ b/src/GrampsInMemDB.py @@ -28,10 +28,6 @@ must hold all of their data in memory. from RelLib import * from GrampsDbBase import * -import os -import md5 -import gtk - class GrampsInMemCursor(GrampsCursor): """ Cursor class for in-memory database classes. Since the in-memory @@ -222,32 +218,3 @@ class GrampsInMemDB(GrampsDbBase): else: return None - def _build_thumb_path(self,path): - base = os.path.expanduser('~/.gramps/thumb') - m = md5.md5(path) - return os.path.join(base,m.hexdigest()+'.jpg') - - def get_thumbnail_image(self,handle): - data = self.media_map.get(handle) - if data: - filename = self._build_thumb_path(data[2]) - if not os.path.isfile(filename): - self.set_thumbnail_image(handle,filename) - return gtk.gdk.pixbuf_new_from_file(filename) - else: - return None - - def set_thumbnail_image(self,handle,path): - try: - pixbuf = gtk.gdk.pixbuf_new_from_file(path) - w = pixbuf.get_width() - h = pixbuf.get_height() - scale = const.thumbScale / (float(max(w,h))) - - pw = int(w*scale) - ph = int(h*scale) - - pixbuf = pixbuf.scale_simple(pw,ph,gtk.gdk.INTERP_BILINEAR) - pixbuf.save(self._build_thumb_path(path),"jpeg") - except: - print "Could not create thumbnail for",path