* 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
This commit is contained in:
parent
9a278d058e
commit
aaf8c75c46
@ -1,4 +1,10 @@
|
||||
2004-11-24 Don Allingham <dallingham@users.sourceforge.net>
|
||||
* 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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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:
|
||||
"""
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user