* 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:
parent
08fa7fec29
commit
337b7f170b
@ -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>
|
||||
* 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>
|
||||
* src/GrampsCfg.py: eliminate unused options
|
||||
* src/gramps.glade: eliminate unused options
|
||||
|
@ -23,6 +23,7 @@
|
||||
import os
|
||||
import time
|
||||
import locale
|
||||
import gtk
|
||||
|
||||
from RelLib import *
|
||||
from GrampsDbBase import *
|
||||
@ -55,6 +56,7 @@ class GrampsBSDDB(GrampsDbBase):
|
||||
|
||||
def dbopen(self,name,dbname):
|
||||
dbmap = dbshelve.DBShelf(self.env)
|
||||
dbmap.db.set_pagesize(16384)
|
||||
dbmap.open(name, dbname, db.DB_HASH, db.DB_CREATE, 0666)
|
||||
return dbmap
|
||||
|
||||
@ -78,6 +80,7 @@ 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)
|
||||
@ -151,6 +154,7 @@ 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()
|
||||
|
||||
@ -284,3 +288,36 @@ 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
|
||||
|
||||
|
@ -139,6 +139,7 @@ def loadConfig():
|
||||
make_path(os.path.expanduser("~/.gramps/filters"))
|
||||
make_path(os.path.expanduser("~/.gramps/plugins"))
|
||||
make_path(os.path.expanduser("~/.gramps/templates"))
|
||||
make_path(os.path.expanduser("~/.gramps/thumb"))
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
|
@ -1105,6 +1105,12 @@ class GrampsDbBase:
|
||||
else:
|
||||
return cols
|
||||
|
||||
def get_thumbnail_image(self,handle):
|
||||
return None
|
||||
|
||||
def set_thumbnail_image(self,handle,path):
|
||||
pass
|
||||
|
||||
class Transaction:
|
||||
"""
|
||||
Defines a group of database commits that define a single logical
|
||||
|
@ -23,6 +23,10 @@
|
||||
from RelLib import *
|
||||
from GrampsDbBase import *
|
||||
|
||||
import os
|
||||
import md5
|
||||
import gtk
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# GrampsInMemDB
|
||||
@ -173,3 +177,33 @@ class GrampsInMemDB(GrampsDbBase):
|
||||
return self.media_map[handle]
|
||||
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
|
||||
|
@ -176,9 +176,6 @@ class ImageSelect:
|
||||
already_imported = o
|
||||
break
|
||||
|
||||
# fix referenes here
|
||||
# dna
|
||||
|
||||
if (already_imported):
|
||||
oref = RelLib.MediaRef()
|
||||
oref.set_reference_handle(already_imported.get_handle())
|
||||
@ -191,8 +188,8 @@ class ImageSelect:
|
||||
description = os.path.basename(filename)
|
||||
mobj.set_description(description)
|
||||
mobj.set_mime_type(mtype)
|
||||
self.savephoto(mobj)
|
||||
mobj.set_path(filename)
|
||||
self.savephoto(mobj)
|
||||
self.db.commit_media_object(mobj,trans)
|
||||
|
||||
self.db.transaction_commit(trans,'Edit Media Objects')
|
||||
@ -270,9 +267,7 @@ class Gallery(ImageSelect):
|
||||
def on_drag_begin(self,obj,context):
|
||||
if const.dnd_images:
|
||||
handle = self.sel_obj.get_reference_handle()
|
||||
obj = self.db.get_object_from_handle(handle)
|
||||
name = Utils.thumb_path(self.db.get_save_path(),obj)
|
||||
pix = gtk.gdk.pixbuf_new_from_file(name)
|
||||
pix = self.db.get_thumbnail_image(handle)
|
||||
context.set_icon_pixbuf(pix,0,0)
|
||||
|
||||
def item_event(self, widget, event=None):
|
||||
@ -355,9 +350,12 @@ class Gallery(ImageSelect):
|
||||
|
||||
def savephoto(self, photo):
|
||||
"""Save the photo in the dataobj object. (Required function)"""
|
||||
print "In save photo"
|
||||
self.db.add_object(photo,None)
|
||||
oref = RelLib.MediaRef()
|
||||
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)
|
||||
|
||||
def add_thumbnail(self, photo):
|
||||
@ -371,19 +369,18 @@ class Gallery(ImageSelect):
|
||||
else:
|
||||
import gobject
|
||||
|
||||
name = Utils.thumb_path(self.db.get_save_path(),obj)
|
||||
|
||||
description = obj.get_description()
|
||||
if len(description) > 20:
|
||||
description = "%s..." % description[0:20]
|
||||
|
||||
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:
|
||||
ErrorDialog(str(msg))
|
||||
image = gtk.gdk.pixbuf_new_from_file(const.icon)
|
||||
except:
|
||||
ErrorDialog(_("Thumbnail %s could not be found") % name)
|
||||
image = gtk.gdk.pixbuf_new_from_file(const.icon)
|
||||
|
||||
x = image.get_width()
|
||||
@ -473,7 +470,8 @@ class Gallery(ImageSelect):
|
||||
photo.set_description(root)
|
||||
self.savephoto(photo)
|
||||
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)
|
||||
self.parent.lists_changed = 1
|
||||
if GrampsGconfKeys.get_media_global():
|
||||
@ -499,7 +497,7 @@ class Gallery(ImageSelect):
|
||||
self.dataobj.add_media_reference(oref)
|
||||
try:
|
||||
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)
|
||||
except:
|
||||
photo.set_path(tfile)
|
||||
@ -629,9 +627,7 @@ class Gallery(ImageSelect):
|
||||
leaving it as an external data object."""
|
||||
photo = obj.get_data('o')
|
||||
obj = self.db.get_object_from_handle(photo.get_reference_handle())
|
||||
name = RelImage.import_media_object(obj.get_path(),self.path,
|
||||
obj.get_handle())
|
||||
obj.set_path(name)
|
||||
self.db.set_thumbnail_image(obj.get_handle(),obj.get_path())
|
||||
|
||||
def popup_change_description(self, obj):
|
||||
"""Bring up a window allowing the user to edit the description
|
||||
@ -706,9 +702,7 @@ class LocalMediaProperties:
|
||||
descr_window.set_text(self.obj.get_description())
|
||||
mtype = self.obj.get_mime_type()
|
||||
|
||||
thumb = Utils.thumb_path(path,self.obj)
|
||||
if os.path.isfile(thumb):
|
||||
self.pix = gtk.gdk.pixbuf_new_from_file(thumb)
|
||||
self.pix = self.db.get_thumbnail_image(self.obj.get_handle())
|
||||
self.pixmap.set_from_pixbuf(self.pix)
|
||||
|
||||
self.change_dialog.get_widget("private").set_active(photo.get_privacy())
|
||||
@ -938,7 +932,7 @@ class GlobalMediaProperties:
|
||||
|
||||
self.descr_window.set_text(self.obj.get_description())
|
||||
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.change_dialog.get_widget("gid").set_text(self.obj.get_gramps_id())
|
||||
|
@ -113,11 +113,6 @@ class MediaView:
|
||||
self.list.connect('button-press-event',self.on_button_press_event)
|
||||
self.list.connect('key-press-event',self.key_press)
|
||||
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.build_columns()
|
||||
self.build_tree()
|
||||
@ -169,11 +164,9 @@ class MediaView:
|
||||
mobj = self.db.get_object_from_handle(handle)
|
||||
mtype = mobj.get_mime_type()
|
||||
type_name = Utils.get_mime_description(mtype)
|
||||
path = mobj.get_path()
|
||||
thumb_path = Utils.thumb_path(self.db.get_save_path(),mobj)
|
||||
pexists = os.path.exists(path)
|
||||
if pexists and os.path.exists(thumb_path):
|
||||
self.preview.set_from_pixbuf(gtk.gdk.pixbuf_new_from_file(thumb_path))
|
||||
image = self.db.get_thumbnail_image(mobj.get_handle())
|
||||
if image != None:
|
||||
self.preview.set_from_pixbuf(image)
|
||||
else:
|
||||
icon_image = gtk.gdk.pixbuf_new_from_file(Utils.find_icon(mtype))
|
||||
self.preview.set_from_pixbuf(icon_image)
|
||||
@ -256,7 +249,7 @@ class MediaView:
|
||||
def popup_convert_to_private(self, obj):
|
||||
path = self.db.get_save_path()
|
||||
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:
|
||||
self.obj.set_path(name)
|
||||
|
||||
@ -346,9 +339,8 @@ class MediaView:
|
||||
return
|
||||
if (const.dnd_images):
|
||||
obj = self.db.get_object_from_handle(store.get_value(node,1))
|
||||
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)
|
||||
image = self.db.get_thumbnail_image(obj.get_handle())
|
||||
context.set_icon_pixbuf(image,0,0)
|
||||
|
||||
def on_drag_data_get(self,w, context, selection_data, info, time):
|
||||
if info == 1:
|
||||
@ -376,11 +368,7 @@ class MediaView:
|
||||
trans = self.db.transaction_begin()
|
||||
self.db.add_object(photo,trans)
|
||||
if GrampsGconfKeys.get_media_reference() == 0:
|
||||
name = RelImage.import_media_object(name,
|
||||
self.db.get_save_path(),
|
||||
photo.get_handle())
|
||||
if name:
|
||||
photo.set_path(name)
|
||||
self.db.set_thumbnail_image(photo.get_handle(),name)
|
||||
|
||||
self.db.commit_media_object(photo,trans)
|
||||
self.db.transaction_commit(trans,_("Add Media Object"))
|
||||
@ -409,9 +397,7 @@ class MediaView:
|
||||
try:
|
||||
handle = photo.get_handle()
|
||||
path = self.db.get_save_path()
|
||||
name = RelImage.import_media_object(tfile,path,handle)
|
||||
if name:
|
||||
photo.set_path(name)
|
||||
self.db.set_thumbnail_image(handle,path)
|
||||
except:
|
||||
photo.set_path(tfile)
|
||||
return
|
||||
|
@ -184,7 +184,6 @@ def import2(database, filename, cb, codeset, use_trans):
|
||||
|
||||
try:
|
||||
close = g.parse_gedcom_file(use_trans)
|
||||
g.resolve_refns()
|
||||
except IOError,msg:
|
||||
Utils.destroy_passed_object(statusWindow)
|
||||
errmsg = _("%s could not be opened\n") % filename
|
||||
@ -205,11 +204,14 @@ def import2(database, filename, cb, codeset, use_trans):
|
||||
if close:
|
||||
statusWindow.destroy()
|
||||
|
||||
print database.person_map.stat()
|
||||
|
||||
if cb:
|
||||
statusWindow.destroy()
|
||||
cb(1)
|
||||
elif callback:
|
||||
callback()
|
||||
print "callback done"
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
@ -314,7 +316,7 @@ class GedcomParser:
|
||||
f = open("/proc/mounts","r")
|
||||
|
||||
for line in f.xreadlines():
|
||||
paths = string.split(line)
|
||||
paths = line.split()
|
||||
ftype = paths[2].upper()
|
||||
if ftype in file_systems.keys():
|
||||
mypaths.append((paths[1],file_systems[ftype]))
|
||||
@ -355,7 +357,7 @@ class GedcomParser:
|
||||
|
||||
def find_file(self,fullname,altpath):
|
||||
tries = []
|
||||
fullname = string.replace(fullname,'\\','/')
|
||||
fullname = fullname.replace('\\','/')
|
||||
tries.append(fullname)
|
||||
|
||||
if os.path.isfile(fullname):
|
||||
@ -395,7 +397,7 @@ class GedcomParser:
|
||||
self.text = string.translate(self.text,self.transtable2)
|
||||
|
||||
self.index += 1
|
||||
l = string.split(self.text, None, 2)
|
||||
l = self.text.split(None, 2)
|
||||
ln = len(l)
|
||||
try:
|
||||
if ln == 2:
|
||||
@ -508,12 +510,12 @@ class GedcomParser:
|
||||
return
|
||||
elif matches[1] == "TITL":
|
||||
title = matches[2] + self.parse_continue_data(level+1)
|
||||
title = string.replace(title,'\n',' ')
|
||||
title = title.replace('\n',' ')
|
||||
self.source.set_title(title)
|
||||
elif matches[1] == "TAXT" or matches[1] == "PERI": # EasyTree Sierra On-Line
|
||||
if self.source.get_title() == "":
|
||||
title = matches[2] + self.parse_continue_data(level+1)
|
||||
title = string.replace(title,'\n',' ')
|
||||
title = title.replace('\n',' ')
|
||||
self.source.set_title(title)
|
||||
elif matches[1] == "AUTH":
|
||||
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):
|
||||
intid = self.gid2id.get(gramps_id)
|
||||
if not intid:
|
||||
intid = Utils.create_id()
|
||||
intid = create_id()
|
||||
self.gid2id[gramps_id] = intid
|
||||
return intid
|
||||
|
||||
@ -646,7 +648,7 @@ class GedcomParser:
|
||||
def find_family_handle(self,gramps_id):
|
||||
intid = self.fid2id.get(gramps_id)
|
||||
if not intid:
|
||||
intid = Utils.create_id()
|
||||
intid = create_id()
|
||||
self.fid2id[gramps_id] = intid
|
||||
return intid
|
||||
|
||||
@ -656,7 +658,7 @@ class GedcomParser:
|
||||
if self.db.source_map.has_key(intid):
|
||||
source.unserialize(self.db.source_map.get(intid))
|
||||
else:
|
||||
intid = Utils.create_id()
|
||||
intid = create_id()
|
||||
source.set_handle(intid)
|
||||
source.set_gramps_id(gramps_id)
|
||||
self.db.add_source(source,self.trans)
|
||||
@ -669,7 +671,7 @@ class GedcomParser:
|
||||
if self.db.place_map.has_key(intid):
|
||||
place.unserialize(self.db.place_map.get(intid))
|
||||
else:
|
||||
intid = Utils.create_id()
|
||||
intid = create_id()
|
||||
place.set_handle(intid)
|
||||
place.set_title(gramps_id)
|
||||
place.set_gramps_id(self.db.find_next_place_gramps_id())
|
||||
@ -712,11 +714,11 @@ class GedcomParser:
|
||||
return (mrel,frel)
|
||||
# FTW
|
||||
elif matches[1] == "_FREL":
|
||||
if string.lower(matches[2]) != "natural":
|
||||
frel = string.capitalize(matches[2])
|
||||
if matches[2].lower() != "natural":
|
||||
frel = matches[2].capitalize()
|
||||
# FTW
|
||||
elif matches[1] == "_MREL":
|
||||
if string.lower(matches[2]) != "natural":
|
||||
if matches[2].lower() != "natural":
|
||||
mrel = matches[2]
|
||||
elif matches[1] == "ADOP":
|
||||
mrel = "Adopted"
|
||||
@ -789,7 +791,7 @@ class GedcomParser:
|
||||
else:
|
||||
self.parse_family_object(2)
|
||||
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.ignore_sub_junk(2)
|
||||
elif matches[1] == "NOTE":
|
||||
@ -974,7 +976,7 @@ class GedcomParser:
|
||||
if matches[2]:
|
||||
event.set_description(matches[2])
|
||||
self.parse_person_event(event,2)
|
||||
n = string.strip(event.get_name())
|
||||
n = event.get_name().strip()
|
||||
if n in self.attrs:
|
||||
attr = RelLib.Attribute()
|
||||
attr.set_type(self.gedattr[n])
|
||||
@ -1001,7 +1003,7 @@ class GedcomParser:
|
||||
self.ignore_sub_junk(2)
|
||||
else:
|
||||
event = RelLib.Event()
|
||||
n = string.strip(matches[1])
|
||||
n = matches[1].strip()
|
||||
if ged2gramps.has_key(n):
|
||||
event.set_name(ged2gramps[n])
|
||||
elif self.gedattr.has_key(n):
|
||||
@ -1033,7 +1035,7 @@ class GedcomParser:
|
||||
self.backup()
|
||||
return 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)
|
||||
self.parse_note_data(level+1)
|
||||
else:
|
||||
@ -1050,7 +1052,7 @@ class GedcomParser:
|
||||
|
||||
if int(matches[0]) < level:
|
||||
self.backup()
|
||||
return (string.capitalize(ftype),note)
|
||||
return (ftype.capitalize(),note)
|
||||
elif matches[1] == "PEDI":
|
||||
ftype = matches[2]
|
||||
elif matches[1] == "SOUR":
|
||||
@ -1059,7 +1061,7 @@ class GedcomParser:
|
||||
elif matches[1] == "_PRIMARY":
|
||||
pass #type = matches[1]
|
||||
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)
|
||||
self.parse_note_data(level+1)
|
||||
else:
|
||||
@ -1949,6 +1951,15 @@ _filter = gtk.FileFilter()
|
||||
_filter.set_name(_('GEDCOM files'))
|
||||
_filter.add_mime_type(_mime_type)
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
#
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
def create_id():
|
||||
return Utils.create_id()
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
#
|
||||
|
@ -76,7 +76,7 @@ def importData(database, filename, callback=None,cl=0,use_trans=True):
|
||||
database.fmap = {}
|
||||
|
||||
change = os.path.getmtime(filename)
|
||||
parser = GrampsParser(database,callback,basefile,change)
|
||||
parser = GrampsParser(database,callback,basefile,change,filename)
|
||||
|
||||
if gzip_ok:
|
||||
use_gzip = 1
|
||||
@ -273,7 +273,8 @@ def fix_spaces(text_list):
|
||||
#-------------------------------------------------------------------------
|
||||
class GrampsParser:
|
||||
|
||||
def __init__(self,database,callback,base,change):
|
||||
def __init__(self,database,callback,base,change,filename):
|
||||
self.filename = filename
|
||||
self.stext_list = []
|
||||
self.scomments_list = []
|
||||
self.note_list = []
|
||||
@ -913,7 +914,11 @@ class GrampsParser:
|
||||
self.object.set_description(attrs['description'])
|
||||
src = attrs["src"]
|
||||
if src:
|
||||
if src[0] != '/':
|
||||
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
|
||||
|
@ -40,10 +40,6 @@ from QuestionDialog import ErrorDialog, WarningDialog
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import const
|
||||
import Utils
|
||||
import ImgManip
|
||||
import GrampsMime
|
||||
|
||||
from gettext import gettext as _
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
@ -59,51 +55,7 @@ def import_media_object(filename,path,base):
|
||||
_("The file has been moved or deleted"))
|
||||
return ""
|
||||
|
||||
ext = os.path.splitext(filename)[1]
|
||||
|
||||
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
|
||||
return filename
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
@ -124,75 +76,12 @@ def scale_image(path,size):
|
||||
|
||||
scale = size / float(max(width,height))
|
||||
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:
|
||||
WarningDialog(_("Cannot display %s") % path,
|
||||
_('GRAMPS is not able to display the image file. '
|
||||
'This may be caused by a corrupt file.'))
|
||||
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')
|
||||
|
||||
|
@ -117,10 +117,9 @@ class SelectObject:
|
||||
the_type = Utils.get_mime_description(obj.get_mime_type())
|
||||
path = obj.get_path()
|
||||
|
||||
thumb_path = Utils.thumb_path(self.db.get_save_path(),obj)
|
||||
pexists = os.path.exists(path)
|
||||
if pexists and os.path.exists(thumb_path):
|
||||
self.preview.set_from_pixbuf(gtk.gdk.pixbuf_new_from_file(thumb_path))
|
||||
image = self.db.get_thumbnail_image(obj.get_handle())
|
||||
if image:
|
||||
self.preview.set_from_pixbuf(image)
|
||||
else:
|
||||
icon_image = gtk.gdk.pixbuf_new_from_file(Utils.find_icon(the_type))
|
||||
self.preview.set_from_pixbuf(icon_image)
|
||||
|
@ -332,27 +332,6 @@ def get_mime_description(mime_type):
|
||||
except:
|
||||
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)
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
#
|
||||
|
@ -1124,9 +1124,9 @@ class Gramps:
|
||||
if response == gtk.RESPONSE_OK:
|
||||
name = choose.get_filename()
|
||||
if os.path.isfile(name):
|
||||
RelImage.import_media_object(name,filename,base)
|
||||
obj = self.db.get_object_from_handle(ObjectId)
|
||||
obj.set_path(name)
|
||||
self.db.set_thumbnail_image(ObjectId,name)
|
||||
choose.destroy()
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user