From aaf8c75c46467696985497eefea17bfd65d28c70 Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Thu, 25 Nov 2004 02:06:05 +0000 Subject: [PATCH] * src/GrampsDbBase.py: always use external thumbnails * src/GrampsBSDDB.py: always use external thumbnails * src/ImgManip.py: centralize thumbnail handling * src/ReadXML.py: handle thumbnail changes * src/ReadGedcom.py: combine common files into the same media object svn: r3749 --- ChangeLog | 6 ++++++ example/gedcom/sample.ged | 3 +++ src/GrampsBSDDB.py | 35 ----------------------------------- src/GrampsDbBase.py | 10 ++++++---- src/ImgManip.py | 32 +++++++++++++++++++++++++------- src/ReadGedcom.py | 17 +++++++++++------ src/ReadXML.py | 1 - src/RelLib.py | 2 +- 8 files changed, 52 insertions(+), 54 deletions(-) diff --git a/ChangeLog b/ChangeLog index 37ab864ab..f24d14c5e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,10 @@ 2004-11-24 Don Allingham + * src/GrampsDbBase.py: always use external thumbnails + * src/GrampsBSDDB.py: always use external thumbnails + * src/ImgManip.py: centralize thumbnail handling + * src/ReadXML.py: handle thumbnail changes + * src/ReadGedcom.py: combine common files into the same + media object * src/EditSource.py: handle add/delete data item buttons. Make sure that data items with empty keys are not saved. * src/gramps.glade: added add/delete buttons for Source Editor diff --git a/example/gedcom/sample.ged b/example/gedcom/sample.ged index 25bb5f6b0..9f601b38c 100755 --- a/example/gedcom/sample.ged +++ b/example/gedcom/sample.ged @@ -87,6 +87,9 @@ 4 TEXT Alice Paula Perkins born 22 Nov 1933, Sparks, Washoe Co, Nevada daughter of Paul Perkins and Stella Mason. 2 SOUR @S1601@ 1 SEX F +1 OBJE +2 FROM jpeg +2 FILE foo/O0.jpg 1 BIRT 2 DATE 22 NOV 1933 2 PLAC Sparks, Washoe Co., NV diff --git a/src/GrampsBSDDB.py b/src/GrampsBSDDB.py index 68ec350ff..7f756cc27 100644 --- a/src/GrampsBSDDB.py +++ b/src/GrampsBSDDB.py @@ -80,7 +80,6 @@ class GrampsBSDDB(GrampsDbBase): self.event_map = self.dbopen(name, "events") self.metadata = self.dbopen(name, "meta") self.person_map = self.dbopen(name, "person") - self.thumb_db = self.dbopen(name, "thumb") self.surnames = db.DB(self.env) self.surnames.set_flags(db.DB_DUP) @@ -154,7 +153,6 @@ class GrampsBSDDB(GrampsDbBase): self.oid_trans.close() self.sid_trans.close() self.pid_trans.close() - self.thumb_db.close() self.env.close() self.undodb.close() @@ -288,36 +286,3 @@ class GrampsBSDDB(GrampsDbBase): return obj else: return None - - def get_thumbnail_image(self,handle): - data = self.thumb_db.get(handle) - if data: - val = gtk.gdk.pixbuf_new_from_data(data[0],gtk.gdk.COLORSPACE_RGB, - data[1],data[2],data[3],data[4], - data[5]) - return val - 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) - self.thumb_db[handle] = ( - pixbuf.get_pixels(), - pixbuf.get_has_alpha(), - pixbuf.get_bits_per_sample(), - pw, - ph, - pixbuf.get_rowstride() - ) - except: - self.thumb_db[handle] = None - diff --git a/src/GrampsDbBase.py b/src/GrampsDbBase.py index 370e40dc3..ca34ed838 100644 --- a/src/GrampsDbBase.py +++ b/src/GrampsDbBase.py @@ -1129,10 +1129,12 @@ class GrampsDbBase: return cols def get_thumbnail_image(self,handle): - return None - - def set_thumbnail_image(self,handle,path): - pass + data = self.media_map.get(handle) + if data: + import ImgManip + return ImgManip.get_thumbnail_image(data[2]) + else: + return None class Transaction: """ diff --git a/src/ImgManip.py b/src/ImgManip.py index 89445c775..f0e002af5 100644 --- a/src/ImgManip.py +++ b/src/ImgManip.py @@ -21,13 +21,7 @@ import os import const import signal - -#------------------------------------------------------------------------- -# -# Check for the python imaging library -# -#------------------------------------------------------------------------- - +import md5 import popen2 import gtk @@ -94,4 +88,28 @@ class ImgManip: return self.fmt_scale_data(x,y,"png") +def _build_thumb_path(path): + base = os.path.expanduser('~/.gramps/thumb') + m = md5.md5(path) + return os.path.join(base,m.hexdigest()+'.jpg') +def set_thumbnail_image(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(_build_thumb_path(path),"jpeg") + except: + print "Could not create thumbnail for",path + +def get_thumbnail_image(path): + filename = _build_thumb_path(path) + if not os.path.isfile(filename): + set_thumbnail_image(path) + return gtk.gdk.pixbuf_new_from_file(filename) diff --git a/src/ReadGedcom.py b/src/ReadGedcom.py index 8dd46cb9a..e4d3cf90b 100644 --- a/src/ReadGedcom.py +++ b/src/ReadGedcom.py @@ -235,6 +235,7 @@ class GedcomParser: self.dp = DateParser.DateParser() self.db = dbase self.person = None + self.media_map = {} self.fmap = {} self.smap = {} self.nmap = {} @@ -1108,12 +1109,16 @@ class GedcomParser: self.warn(string.join(path,"\n\t\t")) self.warn('\n') else: - photo = RelLib.MediaObject() - photo.set_path(path) - photo.set_description(title) - photo.set_mime_type(Utils.get_mime_type(path)) - self.db.add_object(photo, self.trans) - self.db.set_thumbnail_image(photo.get_handle(),path) + photo_handle = self.media_map.get(path) + if photo_handle == None: + photo = RelLib.MediaObject() + photo.set_path(path) + photo.set_description(title) + photo.set_mime_type(Utils.get_mime_type(path)) + self.db.add_object(photo, self.trans) + self.media_map[path] = photo.get_handle() + else: + photo = self.db.get_object_from_handle(photo_handle) oref = RelLib.MediaRef() oref.set_reference_handle(photo.get_handle()) self.person.add_media_reference(oref) diff --git a/src/ReadXML.py b/src/ReadXML.py index 2f4054699..531153455 100644 --- a/src/ReadXML.py +++ b/src/ReadXML.py @@ -922,7 +922,6 @@ class GrampsParser: fullpath = os.path.abspath(self.filename) src = os.path.dirname(fullpath) + '/' + src self.object.set_path(src) - self.db.set_thumbnail_image(self.object.get_handle(),src) def stop_people(self,*tag): pass diff --git a/src/RelLib.py b/src/RelLib.py index 214dee527..7fb3130c7 100644 --- a/src/RelLib.py +++ b/src/RelLib.py @@ -1197,7 +1197,7 @@ class Source(PrimaryObject): def serialize(self): return (self.handle, self.gramps_id, unicode(self.title), unicode(self.author), unicode(self.pubinfo), - unicode(self.note), self.media_list, unicode(self.abbrev), + self.note, self.media_list, unicode(self.abbrev), self.change,self.datamap) def unserialize(self,data):