* src/GrampsBSDDB.py: thumbnail handing in the database

* src/GrampsDbBase.py: add set_thumbnail_image and
get_thumbnail_image in base class
* src/GrampsInMemDB.py: saving thumbnail image
* src/GrampsCfg.py: create thumbnail image directory
* src/ImageSelect.py: use new thumbnail scheme
* src/MediaView.py: use new thumbnail scheme
* src/ReadGedcom.py: use new thumbnail scheme
* src/ReadXML.py: use new thumbnail scheme
* src/SelectObject.py: use new thumbnail scheme
* src/gramps_main.py: use new thumbnail scheme
* src/Utils.py: remove unused tasks
* src/RelImage.py: remove unused tasks

* src/DateParser.py: fix dates of the format of JAN 2000


svn: r3662
This commit is contained in:
Don Allingham 2004-10-23 03:56:48 +00:00
parent 08fa7fec29
commit 337b7f170b
13 changed files with 164 additions and 205 deletions

View File

@ -1,6 +1,24 @@
2004-10-22 Don Allingham <dallingham@users.sourceforge.net>
* src/GrampsBSDDB.py: thumbnail handing in the database
* src/GrampsDbBase.py: add set_thumbnail_image and
get_thumbnail_image in base class
* src/GrampsInMemDB.py: saving thumbnail image
* src/GrampsCfg.py: create thumbnail image directory
* src/ImageSelect.py: use new thumbnail scheme
* src/MediaView.py: use new thumbnail scheme
* src/ReadGedcom.py: use new thumbnail scheme
* src/ReadXML.py: use new thumbnail scheme
* src/SelectObject.py: use new thumbnail scheme
* src/gramps_main.py: use new thumbnail scheme
* src/Utils.py: remove unused tasks
* src/RelImage.py: remove unused tasks
2004-10-22 Alex Roitman <shura@alex.neuro.umn.edu> 2004-10-22 Alex Roitman <shura@alex.neuro.umn.edu>
* src/plugins/TimeLine.py: Remove old Date.UNDEF usage. * src/plugins/TimeLine.py: Remove old Date.UNDEF usage.
2004-10-21 Don Allingham <dallingham@users.sourceforge.net>
* src/DateParser.py: fix dates of the format of JAN 2000
2004-10-19 Don Allingham <dallingham@users.sourceforge.net> 2004-10-19 Don Allingham <dallingham@users.sourceforge.net>
* src/GrampsCfg.py: eliminate unused options * src/GrampsCfg.py: eliminate unused options
* src/gramps.glade: eliminate unused options * src/gramps.glade: eliminate unused options

View File

@ -23,6 +23,7 @@
import os import os
import time import time
import locale import locale
import gtk
from RelLib import * from RelLib import *
from GrampsDbBase import * from GrampsDbBase import *
@ -55,6 +56,7 @@ class GrampsBSDDB(GrampsDbBase):
def dbopen(self,name,dbname): def dbopen(self,name,dbname):
dbmap = dbshelve.DBShelf(self.env) dbmap = dbshelve.DBShelf(self.env)
dbmap.db.set_pagesize(16384)
dbmap.open(name, dbname, db.DB_HASH, db.DB_CREATE, 0666) dbmap.open(name, dbname, db.DB_HASH, db.DB_CREATE, 0666)
return dbmap return dbmap
@ -78,6 +80,7 @@ class GrampsBSDDB(GrampsDbBase):
self.event_map = self.dbopen(name, "events") self.event_map = self.dbopen(name, "events")
self.metadata = self.dbopen(name, "meta") self.metadata = self.dbopen(name, "meta")
self.person_map = self.dbopen(name, "person") self.person_map = self.dbopen(name, "person")
self.thumb_db = self.dbopen(name, "thumb")
self.surnames = db.DB(self.env) self.surnames = db.DB(self.env)
self.surnames.set_flags(db.DB_DUP) self.surnames.set_flags(db.DB_DUP)
@ -151,6 +154,7 @@ class GrampsBSDDB(GrampsDbBase):
self.oid_trans.close() self.oid_trans.close()
self.sid_trans.close() self.sid_trans.close()
self.pid_trans.close() self.pid_trans.close()
self.thumb_db.close()
self.env.close() self.env.close()
self.undodb.close() self.undodb.close()
@ -284,3 +288,36 @@ class GrampsBSDDB(GrampsDbBase):
return obj return obj
else: else:
return None 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

View File

@ -139,6 +139,7 @@ def loadConfig():
make_path(os.path.expanduser("~/.gramps/filters")) make_path(os.path.expanduser("~/.gramps/filters"))
make_path(os.path.expanduser("~/.gramps/plugins")) make_path(os.path.expanduser("~/.gramps/plugins"))
make_path(os.path.expanduser("~/.gramps/templates")) make_path(os.path.expanduser("~/.gramps/templates"))
make_path(os.path.expanduser("~/.gramps/thumb"))
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #

View File

@ -1104,6 +1104,12 @@ class GrampsDbBase:
return cols + default[len(cols):] return cols + default[len(cols):]
else: else:
return cols return cols
def get_thumbnail_image(self,handle):
return None
def set_thumbnail_image(self,handle,path):
pass
class Transaction: class Transaction:
""" """

View File

@ -23,6 +23,10 @@
from RelLib import * from RelLib import *
from GrampsDbBase import * from GrampsDbBase import *
import os
import md5
import gtk
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# GrampsInMemDB # GrampsInMemDB
@ -173,3 +177,33 @@ class GrampsInMemDB(GrampsDbBase):
return self.media_map[handle] return self.media_map[handle]
else: else:
return None 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

View File

@ -155,7 +155,7 @@ class ImageSelect:
def on_savephoto_clicked(self): def on_savephoto_clicked(self):
"""Save the photo in the dataobj object. (Required function)""" """Save the photo in the dataobj object. (Required function)"""
global _last_path global _last_path
filename = self.fname.get_filename() filename = self.fname.get_filename()
_last_path = os.path.dirname(filename) _last_path = os.path.dirname(filename)
@ -176,9 +176,6 @@ class ImageSelect:
already_imported = o already_imported = o
break break
# fix referenes here
# dna
if (already_imported): if (already_imported):
oref = RelLib.MediaRef() oref = RelLib.MediaRef()
oref.set_reference_handle(already_imported.get_handle()) oref.set_reference_handle(already_imported.get_handle())
@ -191,8 +188,8 @@ class ImageSelect:
description = os.path.basename(filename) description = os.path.basename(filename)
mobj.set_description(description) mobj.set_description(description)
mobj.set_mime_type(mtype) mobj.set_mime_type(mtype)
self.savephoto(mobj)
mobj.set_path(filename) mobj.set_path(filename)
self.savephoto(mobj)
self.db.commit_media_object(mobj,trans) self.db.commit_media_object(mobj,trans)
self.db.transaction_commit(trans,'Edit Media Objects') self.db.transaction_commit(trans,'Edit Media Objects')
@ -270,9 +267,7 @@ class Gallery(ImageSelect):
def on_drag_begin(self,obj,context): def on_drag_begin(self,obj,context):
if const.dnd_images: if const.dnd_images:
handle = self.sel_obj.get_reference_handle() handle = self.sel_obj.get_reference_handle()
obj = self.db.get_object_from_handle(handle) pix = self.db.get_thumbnail_image(handle)
name = Utils.thumb_path(self.db.get_save_path(),obj)
pix = gtk.gdk.pixbuf_new_from_file(name)
context.set_icon_pixbuf(pix,0,0) context.set_icon_pixbuf(pix,0,0)
def item_event(self, widget, event=None): def item_event(self, widget, event=None):
@ -355,9 +350,12 @@ class Gallery(ImageSelect):
def savephoto(self, photo): def savephoto(self, photo):
"""Save the photo in the dataobj object. (Required function)""" """Save the photo in the dataobj object. (Required function)"""
print "In save photo"
self.db.add_object(photo,None) self.db.add_object(photo,None)
oref = RelLib.MediaRef() oref = RelLib.MediaRef()
oref.set_reference_handle(photo.get_handle()) oref.set_reference_handle(photo.get_handle())
print photo.get_handle(), photo.get_path()
self.db.set_thumbnail_image(photo.get_handle(),photo.get_path())
self.dataobj.add_media_reference(oref) self.dataobj.add_media_reference(oref)
def add_thumbnail(self, photo): def add_thumbnail(self, photo):
@ -371,19 +369,18 @@ class Gallery(ImageSelect):
else: else:
import gobject import gobject
name = Utils.thumb_path(self.db.get_save_path(),obj)
description = obj.get_description() description = obj.get_description()
if len(description) > 20: if len(description) > 20:
description = "%s..." % description[0:20] description = "%s..." % description[0:20]
try: try:
image = gtk.gdk.pixbuf_new_from_file(name) image = self.db.get_thumbnail_image(oid)
if not image:
image = gtk.gdk.pixbuf_new_from_file(const.icon)
except gobject.GError,msg: except gobject.GError,msg:
ErrorDialog(str(msg)) ErrorDialog(str(msg))
image = gtk.gdk.pixbuf_new_from_file(const.icon) image = gtk.gdk.pixbuf_new_from_file(const.icon)
except: except:
ErrorDialog(_("Thumbnail %s could not be found") % name)
image = gtk.gdk.pixbuf_new_from_file(const.icon) image = gtk.gdk.pixbuf_new_from_file(const.icon)
x = image.get_width() x = image.get_width()
@ -473,7 +470,8 @@ class Gallery(ImageSelect):
photo.set_description(root) photo.set_description(root)
self.savephoto(photo) self.savephoto(photo)
if GrampsGconfKeys.get_media_reference() == 0: if GrampsGconfKeys.get_media_reference() == 0:
name = RelImage.import_media_object(name,self.path,photo.get_handle()) self.db.set_thumbnail_image(photo.get_handle(),
self.path)
photo.set_path(name) photo.set_path(name)
self.parent.lists_changed = 1 self.parent.lists_changed = 1
if GrampsGconfKeys.get_media_global(): if GrampsGconfKeys.get_media_global():
@ -499,7 +497,7 @@ class Gallery(ImageSelect):
self.dataobj.add_media_reference(oref) self.dataobj.add_media_reference(oref)
try: try:
handle = photo.get_handle() handle = photo.get_handle()
name = RelImage.import_media_object(tfile,self.path,handle) self.db.set_thumbnail_image(handle,self.path)
photo.set_path(name) photo.set_path(name)
except: except:
photo.set_path(tfile) photo.set_path(tfile)
@ -629,9 +627,7 @@ class Gallery(ImageSelect):
leaving it as an external data object.""" leaving it as an external data object."""
photo = obj.get_data('o') photo = obj.get_data('o')
obj = self.db.get_object_from_handle(photo.get_reference_handle()) obj = self.db.get_object_from_handle(photo.get_reference_handle())
name = RelImage.import_media_object(obj.get_path(),self.path, self.db.set_thumbnail_image(obj.get_handle(),obj.get_path())
obj.get_handle())
obj.set_path(name)
def popup_change_description(self, obj): def popup_change_description(self, obj):
"""Bring up a window allowing the user to edit the description """Bring up a window allowing the user to edit the description
@ -706,10 +702,8 @@ class LocalMediaProperties:
descr_window.set_text(self.obj.get_description()) descr_window.set_text(self.obj.get_description())
mtype = self.obj.get_mime_type() mtype = self.obj.get_mime_type()
thumb = Utils.thumb_path(path,self.obj) self.pix = self.db.get_thumbnail_image(self.obj.get_handle())
if os.path.isfile(thumb): self.pixmap.set_from_pixbuf(self.pix)
self.pix = gtk.gdk.pixbuf_new_from_file(thumb)
self.pixmap.set_from_pixbuf(self.pix)
self.change_dialog.get_widget("private").set_active(photo.get_privacy()) self.change_dialog.get_widget("private").set_active(photo.get_privacy())
self.change_dialog.get_widget("gid").set_text(self.obj.get_gramps_id()) self.change_dialog.get_widget("gid").set_text(self.obj.get_gramps_id())
@ -938,7 +932,7 @@ class GlobalMediaProperties:
self.descr_window.set_text(self.obj.get_description()) self.descr_window.set_text(self.obj.get_description())
mtype = self.obj.get_mime_type() mtype = self.obj.get_mime_type()
pb = gtk.gdk.pixbuf_new_from_file(Utils.thumb_path(self.path,self.obj)) pb = self.db.get_thumbnail_image(self.obj.get_handle())
self.pixmap.set_from_pixbuf(pb) self.pixmap.set_from_pixbuf(pb)
self.change_dialog.get_widget("gid").set_text(self.obj.get_gramps_id()) self.change_dialog.get_widget("gid").set_text(self.obj.get_gramps_id())

View File

@ -113,11 +113,6 @@ class MediaView:
self.list.connect('button-press-event',self.on_button_press_event) self.list.connect('button-press-event',self.on_button_press_event)
self.list.connect('key-press-event',self.key_press) self.list.connect('key-press-event',self.key_press)
self.selection.connect('changed',self.on_select_row) self.selection.connect('changed',self.on_select_row)
if not RelImage.is_cnv():
WarningDialog(_("Thumbnails not available")
,_("There is no suitable tool to generate thumbnails for the images. "
"If you would like to enable this feature, "
"install ImageMagick, available at http://www.imagemagick.org/"))
self.columns = [] self.columns = []
self.build_columns() self.build_columns()
self.build_tree() self.build_tree()
@ -169,11 +164,9 @@ class MediaView:
mobj = self.db.get_object_from_handle(handle) mobj = self.db.get_object_from_handle(handle)
mtype = mobj.get_mime_type() mtype = mobj.get_mime_type()
type_name = Utils.get_mime_description(mtype) type_name = Utils.get_mime_description(mtype)
path = mobj.get_path() image = self.db.get_thumbnail_image(mobj.get_handle())
thumb_path = Utils.thumb_path(self.db.get_save_path(),mobj) if image != None:
pexists = os.path.exists(path) self.preview.set_from_pixbuf(image)
if pexists and os.path.exists(thumb_path):
self.preview.set_from_pixbuf(gtk.gdk.pixbuf_new_from_file(thumb_path))
else: else:
icon_image = gtk.gdk.pixbuf_new_from_file(Utils.find_icon(mtype)) icon_image = gtk.gdk.pixbuf_new_from_file(Utils.find_icon(mtype))
self.preview.set_from_pixbuf(icon_image) self.preview.set_from_pixbuf(icon_image)
@ -256,7 +249,7 @@ class MediaView:
def popup_convert_to_private(self, obj): def popup_convert_to_private(self, obj):
path = self.db.get_save_path() path = self.db.get_save_path()
handle = self.obj.get_handle() handle = self.obj.get_handle()
name = RelImage.import_media_object(self.obj.get_path(),path,handle) self.db.set_thumbnail_image(handle,path)
if name: if name:
self.obj.set_path(name) self.obj.set_path(name)
@ -346,9 +339,8 @@ class MediaView:
return return
if (const.dnd_images): if (const.dnd_images):
obj = self.db.get_object_from_handle(store.get_value(node,1)) obj = self.db.get_object_from_handle(store.get_value(node,1))
name = Utils.thumb_path(self.db.get_save_path(),obj) image = self.db.get_thumbnail_image(obj.get_handle())
pix = gtk.gdk.pixbuf_new_from_file(name) context.set_icon_pixbuf(image,0,0)
context.set_icon_pixbuf(pix,0,0)
def on_drag_data_get(self,w, context, selection_data, info, time): def on_drag_data_get(self,w, context, selection_data, info, time):
if info == 1: if info == 1:
@ -376,11 +368,7 @@ class MediaView:
trans = self.db.transaction_begin() trans = self.db.transaction_begin()
self.db.add_object(photo,trans) self.db.add_object(photo,trans)
if GrampsGconfKeys.get_media_reference() == 0: if GrampsGconfKeys.get_media_reference() == 0:
name = RelImage.import_media_object(name, self.db.set_thumbnail_image(photo.get_handle(),name)
self.db.get_save_path(),
photo.get_handle())
if name:
photo.set_path(name)
self.db.commit_media_object(photo,trans) self.db.commit_media_object(photo,trans)
self.db.transaction_commit(trans,_("Add Media Object")) self.db.transaction_commit(trans,_("Add Media Object"))
@ -409,9 +397,7 @@ class MediaView:
try: try:
handle = photo.get_handle() handle = photo.get_handle()
path = self.db.get_save_path() path = self.db.get_save_path()
name = RelImage.import_media_object(tfile,path,handle) self.db.set_thumbnail_image(handle,path)
if name:
photo.set_path(name)
except: except:
photo.set_path(tfile) photo.set_path(tfile)
return return

View File

@ -184,7 +184,6 @@ def import2(database, filename, cb, codeset, use_trans):
try: try:
close = g.parse_gedcom_file(use_trans) close = g.parse_gedcom_file(use_trans)
g.resolve_refns()
except IOError,msg: except IOError,msg:
Utils.destroy_passed_object(statusWindow) Utils.destroy_passed_object(statusWindow)
errmsg = _("%s could not be opened\n") % filename errmsg = _("%s could not be opened\n") % filename
@ -204,12 +203,15 @@ def import2(database, filename, cb, codeset, use_trans):
statusTop.get_widget("close").set_sensitive(1) statusTop.get_widget("close").set_sensitive(1)
if close: if close:
statusWindow.destroy() statusWindow.destroy()
print database.person_map.stat()
if cb: if cb:
statusWindow.destroy() statusWindow.destroy()
cb(1) cb(1)
elif callback: elif callback:
callback() callback()
print "callback done"
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -314,7 +316,7 @@ class GedcomParser:
f = open("/proc/mounts","r") f = open("/proc/mounts","r")
for line in f.xreadlines(): for line in f.xreadlines():
paths = string.split(line) paths = line.split()
ftype = paths[2].upper() ftype = paths[2].upper()
if ftype in file_systems.keys(): if ftype in file_systems.keys():
mypaths.append((paths[1],file_systems[ftype])) mypaths.append((paths[1],file_systems[ftype]))
@ -355,7 +357,7 @@ class GedcomParser:
def find_file(self,fullname,altpath): def find_file(self,fullname,altpath):
tries = [] tries = []
fullname = string.replace(fullname,'\\','/') fullname = fullname.replace('\\','/')
tries.append(fullname) tries.append(fullname)
if os.path.isfile(fullname): if os.path.isfile(fullname):
@ -395,7 +397,7 @@ class GedcomParser:
self.text = string.translate(self.text,self.transtable2) self.text = string.translate(self.text,self.transtable2)
self.index += 1 self.index += 1
l = string.split(self.text, None, 2) l = self.text.split(None, 2)
ln = len(l) ln = len(l)
try: try:
if ln == 2: if ln == 2:
@ -508,12 +510,12 @@ class GedcomParser:
return return
elif matches[1] == "TITL": elif matches[1] == "TITL":
title = matches[2] + self.parse_continue_data(level+1) title = matches[2] + self.parse_continue_data(level+1)
title = string.replace(title,'\n',' ') title = title.replace('\n',' ')
self.source.set_title(title) self.source.set_title(title)
elif matches[1] == "TAXT" or matches[1] == "PERI": # EasyTree Sierra On-Line elif matches[1] == "TAXT" or matches[1] == "PERI": # EasyTree Sierra On-Line
if self.source.get_title() == "": if self.source.get_title() == "":
title = matches[2] + self.parse_continue_data(level+1) title = matches[2] + self.parse_continue_data(level+1)
title = string.replace(title,'\n',' ') title = title.replace('\n',' ')
self.source.set_title(title) self.source.set_title(title)
elif matches[1] == "AUTH": elif matches[1] == "AUTH":
self.source.set_author(matches[2] + self.parse_continue_data(level+1)) self.source.set_author(matches[2] + self.parse_continue_data(level+1))
@ -628,7 +630,7 @@ class GedcomParser:
def find_person_handle(self,gramps_id): def find_person_handle(self,gramps_id):
intid = self.gid2id.get(gramps_id) intid = self.gid2id.get(gramps_id)
if not intid: if not intid:
intid = Utils.create_id() intid = create_id()
self.gid2id[gramps_id] = intid self.gid2id[gramps_id] = intid
return intid return intid
@ -646,7 +648,7 @@ class GedcomParser:
def find_family_handle(self,gramps_id): def find_family_handle(self,gramps_id):
intid = self.fid2id.get(gramps_id) intid = self.fid2id.get(gramps_id)
if not intid: if not intid:
intid = Utils.create_id() intid = create_id()
self.fid2id[gramps_id] = intid self.fid2id[gramps_id] = intid
return intid return intid
@ -656,7 +658,7 @@ class GedcomParser:
if self.db.source_map.has_key(intid): if self.db.source_map.has_key(intid):
source.unserialize(self.db.source_map.get(intid)) source.unserialize(self.db.source_map.get(intid))
else: else:
intid = Utils.create_id() intid = create_id()
source.set_handle(intid) source.set_handle(intid)
source.set_gramps_id(gramps_id) source.set_gramps_id(gramps_id)
self.db.add_source(source,self.trans) self.db.add_source(source,self.trans)
@ -669,7 +671,7 @@ class GedcomParser:
if self.db.place_map.has_key(intid): if self.db.place_map.has_key(intid):
place.unserialize(self.db.place_map.get(intid)) place.unserialize(self.db.place_map.get(intid))
else: else:
intid = Utils.create_id() intid = create_id()
place.set_handle(intid) place.set_handle(intid)
place.set_title(gramps_id) place.set_title(gramps_id)
place.set_gramps_id(self.db.find_next_place_gramps_id()) place.set_gramps_id(self.db.find_next_place_gramps_id())
@ -712,11 +714,11 @@ class GedcomParser:
return (mrel,frel) return (mrel,frel)
# FTW # FTW
elif matches[1] == "_FREL": elif matches[1] == "_FREL":
if string.lower(matches[2]) != "natural": if matches[2].lower() != "natural":
frel = string.capitalize(matches[2]) frel = matches[2].capitalize()
# FTW # FTW
elif matches[1] == "_MREL": elif matches[1] == "_MREL":
if string.lower(matches[2]) != "natural": if matches[2].lower() != "natural":
mrel = matches[2] mrel = matches[2]
elif matches[1] == "ADOP": elif matches[1] == "ADOP":
mrel = "Adopted" mrel = "Adopted"
@ -789,7 +791,7 @@ class GedcomParser:
else: else:
self.parse_family_object(2) self.parse_family_object(2)
elif matches[1] == "_COMM": elif matches[1] == "_COMM":
note = string.strip(matches[2]) + self.parse_continue_data(1) note = matches[2].strip() + self.parse_continue_data(1)
self.family.set_note(note) self.family.set_note(note)
self.ignore_sub_junk(2) self.ignore_sub_junk(2)
elif matches[1] == "NOTE": elif matches[1] == "NOTE":
@ -974,7 +976,7 @@ class GedcomParser:
if matches[2]: if matches[2]:
event.set_description(matches[2]) event.set_description(matches[2])
self.parse_person_event(event,2) self.parse_person_event(event,2)
n = string.strip(event.get_name()) n = event.get_name().strip()
if n in self.attrs: if n in self.attrs:
attr = RelLib.Attribute() attr = RelLib.Attribute()
attr.set_type(self.gedattr[n]) attr.set_type(self.gedattr[n])
@ -1001,7 +1003,7 @@ class GedcomParser:
self.ignore_sub_junk(2) self.ignore_sub_junk(2)
else: else:
event = RelLib.Event() event = RelLib.Event()
n = string.strip(matches[1]) n = matches[1].strip()
if ged2gramps.has_key(n): if ged2gramps.has_key(n):
event.set_name(ged2gramps[n]) event.set_name(ged2gramps[n])
elif self.gedattr.has_key(n): elif self.gedattr.has_key(n):
@ -1033,7 +1035,7 @@ class GedcomParser:
self.backup() self.backup()
return note return note
elif matches[1] == "NOTE": elif matches[1] == "NOTE":
if not string.strip(matches[2]) or matches[2] and matches[2][0] != "@": if not matches[2].strip() or matches[2] and matches[2][0] != "@":
note = matches[2] + self.parse_continue_data(level+1) note = matches[2] + self.parse_continue_data(level+1)
self.parse_note_data(level+1) self.parse_note_data(level+1)
else: else:
@ -1050,7 +1052,7 @@ class GedcomParser:
if int(matches[0]) < level: if int(matches[0]) < level:
self.backup() self.backup()
return (string.capitalize(ftype),note) return (ftype.capitalize(),note)
elif matches[1] == "PEDI": elif matches[1] == "PEDI":
ftype = matches[2] ftype = matches[2]
elif matches[1] == "SOUR": elif matches[1] == "SOUR":
@ -1059,7 +1061,7 @@ class GedcomParser:
elif matches[1] == "_PRIMARY": elif matches[1] == "_PRIMARY":
pass #type = matches[1] pass #type = matches[1]
elif matches[1] == "NOTE": elif matches[1] == "NOTE":
if not string.strip(matches[2]) or matches[2] and matches[2][0] != "@": if not matches[2].strip() or matches[2] and matches[2][0] != "@":
note = matches[2] + self.parse_continue_data(level+1) note = matches[2] + self.parse_continue_data(level+1)
self.parse_note_data(level+1) self.parse_note_data(level+1)
else: else:
@ -1949,6 +1951,15 @@ _filter = gtk.FileFilter()
_filter.set_name(_('GEDCOM files')) _filter.set_name(_('GEDCOM files'))
_filter.add_mime_type(_mime_type) _filter.add_mime_type(_mime_type)
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def create_id():
return Utils.create_id()
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# #

View File

@ -76,7 +76,7 @@ def importData(database, filename, callback=None,cl=0,use_trans=True):
database.fmap = {} database.fmap = {}
change = os.path.getmtime(filename) change = os.path.getmtime(filename)
parser = GrampsParser(database,callback,basefile,change) parser = GrampsParser(database,callback,basefile,change,filename)
if gzip_ok: if gzip_ok:
use_gzip = 1 use_gzip = 1
@ -273,7 +273,8 @@ def fix_spaces(text_list):
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class GrampsParser: class GrampsParser:
def __init__(self,database,callback,base,change): def __init__(self,database,callback,base,change,filename):
self.filename = filename
self.stext_list = [] self.stext_list = []
self.scomments_list = [] self.scomments_list = []
self.note_list = [] self.note_list = []
@ -913,7 +914,11 @@ class GrampsParser:
self.object.set_description(attrs['description']) self.object.set_description(attrs['description'])
src = attrs["src"] src = attrs["src"]
if src: if src:
if src[0] != '/':
fullpath = os.path.abspath(self.filename)
src = os.path.dirname(fullpath) + '/' + src
self.object.set_path(src) self.object.set_path(src)
self.db.set_thumbnail_image(self.object.get_handle(),src)
def stop_people(self,*tag): def stop_people(self,*tag):
pass pass

View File

@ -40,10 +40,6 @@ from QuestionDialog import ErrorDialog, WarningDialog
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import const import const
import Utils
import ImgManip
import GrampsMime
from gettext import gettext as _ from gettext import gettext as _
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@ -59,51 +55,7 @@ def import_media_object(filename,path,base):
_("The file has been moved or deleted")) _("The file has been moved or deleted"))
return "" return ""
ext = os.path.splitext(filename)[1] return filename
mtype = GrampsMime.get_type(filename)
if mtype[0:5] == "image":
name = "%s/%s%s" % (os.path.dirname(path),base,ext)
thumb = "%s/.thumb" % (os.path.dirname(path))
try:
if not os.path.exists(thumb):
os.mkdir(thumb)
except IOError,msg:
ErrorDialog(_("Could not create %s") % thumb,str(msg))
return ""
except:
ErrorDialog(_("Could not create %s") % thumb)
return ""
try:
path = "%s/%s.jpg" % (thumb,base)
mk_thumb(filename,path,const.thumbScale)
except:
ErrorDialog(_("Error creating the thumbnail: %s"))
return ""
try:
shutil.copyfile(filename,name)
try:
shutil.copystat(filename,name)
except:
pass
except IOError,msg:
ErrorDialog(_("Error copying %s") % filename,str(msg))
return ""
else:
bname = os.path.basename(filename)
l = string.split(bname,'.')
name = "%s/%s.%s" % (path,base,l[-1])
shutil.copyfile(filename,name)
try:
shutil.copystat(filename,name)
except:
pass
return name
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -124,75 +76,12 @@ def scale_image(path,size):
scale = size / float(max(width,height)) scale = size / float(max(width,height))
try: try:
return image1.scale_simple(int(scale*width), int(scale*height), gtk.gdk.INTERP_BILINEAR) return image1.scale_simple(int(scale*width), int(scale*height),
gtk.gdk.INTERP_BILINEAR)
except: except:
WarningDialog(_("Cannot display %s") % path, WarningDialog(_("Cannot display %s") % path,
_('GRAMPS is not able to display the image file. ' _('GRAMPS is not able to display the image file. '
'This may be caused by a corrupt file.')) 'This may be caused by a corrupt file.'))
return gtk.gdk.pixbuf_new_from_file(const.icon) return gtk.gdk.pixbuf_new_from_file(const.icon)
#-------------------------------------------------------------------------
#
# scale_image
#
#-------------------------------------------------------------------------
def mk_thumb(source,dest,size):
directory = os.path.dirname(dest)
source = os.path.normpath(source)
dest = os.path.normpath(dest)
try:
if not os.path.exists(directory):
os.mkdir(directory)
except IOError,msg:
ErrorDialog(_("Could not create %s") % directory, str(msg))
return
except:
ErrorDialog(_("Could not create %s") % directory)
return
if os.path.exists(dest):
try:
os.remove(dest)
except IOError,msg:
errmsg = _("Could not replace %s") % directory
ErrorDialog(errmsg,msg)
return
if not os.path.exists(source):
ErrorDialog(_("Could not create a thumbnail for %s") % source,
_("The file has been moved or deleted."))
try:
img = ImgManip.ImgManip(source)
img.jpg_thumbnail(dest,size,size)
except:
import sys
ErrorDialog(_("Could not create a thumbnail for %s") % source,
"%s %s" % (sys.exc_type,sys.exc_value))
return
#-------------------------------------------------------------------------
#
# scale_image
#
#-------------------------------------------------------------------------
def check_thumb(source,dest,size):
if not os.path.isfile(source):
return 0
if not os.path.isfile(dest):
mk_thumb(source,dest,size)
elif os.path.getmtime(source) > os.path.getmtime(dest):
mk_thumb(source,dest,size)
return 1
#-------------------------------------------------------------------------
#
# Test if there's convert available
#
#-------------------------------------------------------------------------
def is_cnv():
return Utils.search_for('convert')

View File

@ -117,10 +117,9 @@ class SelectObject:
the_type = Utils.get_mime_description(obj.get_mime_type()) the_type = Utils.get_mime_description(obj.get_mime_type())
path = obj.get_path() path = obj.get_path()
thumb_path = Utils.thumb_path(self.db.get_save_path(),obj) image = self.db.get_thumbnail_image(obj.get_handle())
pexists = os.path.exists(path) if image:
if pexists and os.path.exists(thumb_path): self.preview.set_from_pixbuf(image)
self.preview.set_from_pixbuf(gtk.gdk.pixbuf_new_from_file(thumb_path))
else: else:
icon_image = gtk.gdk.pixbuf_new_from_file(Utils.find_icon(the_type)) icon_image = gtk.gdk.pixbuf_new_from_file(Utils.find_icon(the_type))
self.preview.set_from_pixbuf(icon_image) self.preview.set_from_pixbuf(icon_image)

View File

@ -331,27 +331,6 @@ def get_mime_description(mime_type):
return '' return ''
except: except:
return '' return ''
#-------------------------------------------------------------------------
#
#
#
#-------------------------------------------------------------------------
def thumb_path(dir,mobj):
mime_type = mobj.get_mime_type()
if mime_type[0:5] == "image":
thumb = "%s/.thumb/%s.jpg" % (os.path.dirname(dir),mobj.get_gramps_id())
try:
if RelImage.check_thumb(mobj.get_path(),thumb,const.thumbScale):
return thumb
else:
return find_icon(mime_type)
except:
return find_icon(mime_type)
else:
return find_icon(mime_type)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #

View File

@ -1124,9 +1124,9 @@ class Gramps:
if response == gtk.RESPONSE_OK: if response == gtk.RESPONSE_OK:
name = choose.get_filename() name = choose.get_filename()
if os.path.isfile(name): if os.path.isfile(name):
RelImage.import_media_object(name,filename,base)
obj = self.db.get_object_from_handle(ObjectId) obj = self.db.get_object_from_handle(ObjectId)
obj.set_path(name) obj.set_path(name)
self.db.set_thumbnail_image(ObjectId,name)
choose.destroy() choose.destroy()
#------------------------------------------------------------------------- #-------------------------------------------------------------------------