* src/ImageSelect.py: specify mime type to get_thumbnail_image
* src/ImgManip.py: make thumbnailing routine more generic * src/SelectObject.py: specify mime type to get_thumbnail_image * src/plugins/NavWebpage.py: produce larger preview images for media pages if a thumbnailer exists * src/plugins/SimpleBookTitle.py: specify mime type to get_thumbnail_image svn: r5148
This commit is contained in:
parent
5a2cb0273e
commit
c6d2319c09
@ -1,3 +1,11 @@
|
||||
2005-08-30 Don Allingham <don@gramps-project.org>
|
||||
* src/ImageSelect.py: specify mime type to get_thumbnail_image
|
||||
* src/ImgManip.py: make thumbnailing routine more generic
|
||||
* src/SelectObject.py: specify mime type to get_thumbnail_image
|
||||
* src/plugins/NavWebpage.py: produce larger preview images for media
|
||||
pages if a thumbnailer exists
|
||||
* src/plugins/SimpleBookTitle.py: specify mime type to get_thumbnail_image
|
||||
|
||||
2005-08-30 Martin Hawlisch <Martin.Hawlisch@gmx.de>
|
||||
* src/plugins/NavWebPage.py: Encode using 'xmlcharrefreplace'
|
||||
* src/plugins/WriteGeneWeb.py: Remove empty families before running
|
||||
|
@ -291,7 +291,8 @@ class Gallery(ImageSelect):
|
||||
if const.dnd_images:
|
||||
handle = self.sel_obj.get_reference_handle()
|
||||
media_obj = self.db.get_object_from_handle(handle)
|
||||
pix = ImgManip.get_thumbnail_image(media_obj.get_path())
|
||||
pix = ImgManip.get_thumbnail_image(media_obj.get_path(),
|
||||
media_obj.get_mime_type())
|
||||
context.set_icon_pixbuf(pix,0,0)
|
||||
|
||||
def item_event(self, widget, event=None):
|
||||
|
@ -103,24 +103,28 @@ def _build_thumb_path(path):
|
||||
m = md5.md5(path)
|
||||
return os.path.join(base,m.hexdigest()+'.png')
|
||||
|
||||
def run_thumbnailer(cmd, frm, to):
|
||||
def run_thumbnailer(mtype, frm, to, size=const.thumbScale):
|
||||
sublist = {
|
||||
'%s' : "%dx%d" % (int(const.thumbScale),int(const.thumbScale)),
|
||||
'%s' : "%dx%d" % (int(size),int(size)),
|
||||
'%u' : frm,
|
||||
'%o' : to,
|
||||
}
|
||||
cmdlist = map(lambda x: sublist.get(x,x),cmd.split())
|
||||
if os.fork() == 0:
|
||||
os.execvp(cmdlist[0],cmdlist)
|
||||
os.wait()
|
||||
|
||||
base = '/desktop/gnome/thumbnailers/%s' % mtype.replace('/','@')
|
||||
cmd = GrampsKeys.client.get_string(base + '/command')
|
||||
enable = GrampsKeys.client.get_bool(base + '/enable')
|
||||
|
||||
if cmd and enable:
|
||||
cmdlist = map(lambda x: sublist.get(x,x),cmd.split())
|
||||
if os.fork() == 0:
|
||||
os.execvp(cmdlist[0],cmdlist)
|
||||
os.wait()
|
||||
return True
|
||||
return False
|
||||
|
||||
def set_thumbnail_image(path,mtype=None):
|
||||
if mtype and not mtype.startswith('image/'):
|
||||
base = '/desktop/gnome/thumbnailers/%s' % mtype.replace('/','@')
|
||||
thumbnailer = GrampsKeys.client.get_string(base + '/command')
|
||||
enable = GrampsKeys.client.get_bool(base + '/enable')
|
||||
if thumbnailer and enable:
|
||||
run_thumbnailer(thumbnailer,path,_build_thumb_path(path))
|
||||
run_thumbnailer(mtype,path,_build_thumb_path(path))
|
||||
else:
|
||||
try:
|
||||
pixbuf = gtk.gdk.pixbuf_new_from_file(path)
|
||||
@ -134,7 +138,7 @@ def set_thumbnail_image(path,mtype=None):
|
||||
pixbuf = pixbuf.scale_simple(pw,ph,gtk.gdk.INTERP_BILINEAR)
|
||||
pixbuf.save(_build_thumb_path(path),"png")
|
||||
except:
|
||||
print "Could not create thumbnail for",path,mtype
|
||||
pass
|
||||
|
||||
def get_thumbnail_image(path,mtype=None):
|
||||
filename = _build_thumb_path(path)
|
||||
@ -151,5 +155,6 @@ def get_thumbnail_image(path,mtype=None):
|
||||
def get_thumbnail_path(path,mtype=None):
|
||||
filename = _build_thumb_path(path)
|
||||
if not os.path.isfile(filename):
|
||||
print "setting",filename
|
||||
set_thumbnail_image(path,mtype)
|
||||
return filename
|
||||
|
@ -117,7 +117,7 @@ class SelectObject:
|
||||
path = obj.get_path()
|
||||
|
||||
if the_type and the_type[0:5] == "image":
|
||||
image = ImgManip.get_thumbnail_image(path)
|
||||
image = ImgManip.get_thumbnail_image(path,the_type)
|
||||
else:
|
||||
image = Utils.find_mime_type_pixbuf(the_type)
|
||||
self.preview.set_from_pixbuf(image)
|
||||
|
@ -140,7 +140,11 @@ class BasePage:
|
||||
archive.add_file(to_path,time.time(),imagefile)
|
||||
imagefile.close()
|
||||
else:
|
||||
shutil.copyfile(from_path,os.path.join(html_dir,to_path))
|
||||
dest = os.path.join(html_dir,to_path)
|
||||
dirname = os.path.dirname(dest)
|
||||
if not os.path.isdir(dirname):
|
||||
os.makedirs(dirname)
|
||||
shutil.copyfile(from_path,dest)
|
||||
|
||||
def copy_media(self,photo,store_ref=True):
|
||||
|
||||
@ -732,55 +736,18 @@ class MediaPage(BasePage):
|
||||
BasePage.__init__(self, title, options, archive, media_list,
|
||||
photo.gramps_id)
|
||||
of = self.create_link_file(handle,"img")
|
||||
|
||||
ext = os.path.splitext(photo.get_path())[1]
|
||||
to_dir = self.build_path(handle,'images')
|
||||
newpath = os.path.join(to_dir,handle+ext)
|
||||
target_exists = True
|
||||
note_only = photo.get_path() == None or photo.get_path() == ''
|
||||
|
||||
mime_type = photo.get_mime_type()
|
||||
note_only = mime_type == None
|
||||
|
||||
if not note_only:
|
||||
try:
|
||||
if self.archive:
|
||||
imagefile = open(photo.get_path(),"r")
|
||||
self.archive.add_file(newpath,time.time(),imagefile)
|
||||
imagefile.close()
|
||||
else:
|
||||
to_dir = os.path.join(self.html_dir,to_dir)
|
||||
if not os.path.isdir(to_dir):
|
||||
os.makedirs(to_dir)
|
||||
shutil.copyfile(photo.get_path(),
|
||||
os.path.join(self.html_dir,newpath))
|
||||
except (IOError,OSError),msg:
|
||||
WarningDialog(_("Missing media object"),str(msg))
|
||||
target_exists = False
|
||||
|
||||
mime_type = photo.get_mime_type()
|
||||
if mime_type:
|
||||
ext = os.path.splitext(photo.get_path())[1]
|
||||
to_dir = self.build_path(handle,'thumb')
|
||||
to_path = os.path.join(to_dir,handle+".png")
|
||||
if not note_only:
|
||||
from_path = ImgManip.get_thumbnail_path(photo.get_path(),mime_type)
|
||||
if not os.path.isfile(from_path):
|
||||
from_path = os.path.join(const.dataDir,"document.png")
|
||||
else:
|
||||
from_path = os.path.join(const.dataDir,"document.png")
|
||||
|
||||
if self.archive:
|
||||
imagefile = open(from_path,"r")
|
||||
self.archive.add_file(to_path,time.time(),imagefile)
|
||||
imagefile.close()
|
||||
else:
|
||||
to_dir = os.path.join(self.html_dir,to_dir)
|
||||
dest = os.path.join(self.html_dir,to_path)
|
||||
if not os.path.isdir(to_dir):
|
||||
os.makedirs(to_dir)
|
||||
try:
|
||||
shutil.copyfile(from_path,dest)
|
||||
except IOError:
|
||||
print "Could not copy file"
|
||||
newpath = self.copy_source_file(handle, photo)
|
||||
target_exists = newpath != None
|
||||
else:
|
||||
target_exists = False
|
||||
|
||||
self.copy_thumbnail(handle, photo)
|
||||
|
||||
self.page_title = photo.get_description()
|
||||
self.display_header(of,db, "%s - %s" % (_('Gallery'), title),
|
||||
get_researcher().get_name(),up=True)
|
||||
@ -800,30 +767,43 @@ class MediaPage(BasePage):
|
||||
|
||||
of.write('</div>\n')
|
||||
|
||||
if mime_type and mime_type.startswith("image"):
|
||||
of.write('<div class="centered">\n')
|
||||
if target_exists:
|
||||
of.write('<img ')
|
||||
of.write('src="../../../%s" alt="%s" />\n' % (newpath, self.page_title))
|
||||
elif not note_only:
|
||||
of.write('<br /><span>(%s)</span>' % _("The file has been moved or deleted"))
|
||||
of.write('</div>\n')
|
||||
else:
|
||||
if not note_only:
|
||||
thmb_path = ImgManip.get_thumbnail_path(photo.get_path(),photo.get_mime_type())
|
||||
if not note_only and os.path.isfile(thmb_path):
|
||||
path = "%s/%s.png" % (self.build_path(photo.handle,"images"),photo.handle)
|
||||
if mime_type:
|
||||
if mime_type.startswith("image/"):
|
||||
of.write('<div class="centered">\n')
|
||||
if target_exists:
|
||||
of.write('<img ')
|
||||
of.write('src="../../../%s" alt="%s" />\n' % (newpath, self.page_title))
|
||||
else:
|
||||
of.write('<br /><span>(%s)</span>' % _("The file has been moved or deleted"))
|
||||
of.write('</div>\n')
|
||||
else:
|
||||
path = os.path.join('images','document.png')
|
||||
import tempfile
|
||||
|
||||
dirname = tempfile.mkdtemp()
|
||||
thmb_path = os.path.join(dirname,"temp.png")
|
||||
if ImgManip.run_thumbnailer(mime_type, photo.get_path(), thmb_path, 320):
|
||||
path = "%s/%s.png" % (self.build_path(photo.handle,"preview"),photo.handle)
|
||||
self.store_file(archive, self.html_dir, thmb_path, path)
|
||||
os.unlink(thmb_path)
|
||||
else:
|
||||
path = os.path.join('images','document.png')
|
||||
os.rmdir(dirname)
|
||||
|
||||
of.write('<div class="centered">\n')
|
||||
if target_exists:
|
||||
of.write('<a href="../../../%s" alt="%s" />\n' % (newpath, self.page_title))
|
||||
of.write('<img ')
|
||||
of.write('src="../../../%s" alt="%s" />\n' % (path, self.page_title))
|
||||
if target_exists:
|
||||
of.write('</a>\n')
|
||||
else:
|
||||
of.write('<br /><span>(%s)</span>' % _("The file has been moved or deleted"))
|
||||
of.write('</div>\n')
|
||||
else:
|
||||
path = os.path.join('images','document.png')
|
||||
of.write('<div class="centered">\n')
|
||||
if target_exists and not note_only:
|
||||
of.write('<a href="../../../%s" alt="%s" />\n' % (newpath, self.page_title))
|
||||
of.write('<img ')
|
||||
of.write('src="../../../%s" alt="%s" />\n' % (path, self.page_title))
|
||||
if target_exists and not note_only:
|
||||
of.write('</a>\n')
|
||||
elif not note_only:
|
||||
of.write('<br /><span>(%s)</span>' % _("The file has been moved or deleted"))
|
||||
of.write('</div>\n')
|
||||
|
||||
of.write('<table class="infolist">\n')
|
||||
@ -845,6 +825,62 @@ class MediaPage(BasePage):
|
||||
self.display_footer(of,db)
|
||||
self.close_file(of)
|
||||
|
||||
def copy_source_file(self,handle,photo):
|
||||
ext = os.path.splitext(photo.get_path())[1]
|
||||
to_dir = self.build_path(handle,'images')
|
||||
newpath = os.path.join(to_dir,handle+ext)
|
||||
|
||||
try:
|
||||
if self.archive:
|
||||
imagefile = open(photo.get_path(),"r")
|
||||
self.archive.add_file(newpath,time.time(),imagefile)
|
||||
imagefile.close()
|
||||
else:
|
||||
to_dir = os.path.join(self.html_dir,to_dir)
|
||||
if not os.path.isdir(to_dir):
|
||||
os.makedirs(to_dir)
|
||||
shutil.copyfile(photo.get_path(),
|
||||
os.path.join(self.html_dir,newpath))
|
||||
return newpath
|
||||
except (IOError,OSError),msg:
|
||||
WarningDialog(_("Missing media object"),str(msg))
|
||||
return None
|
||||
|
||||
def copy_thumbnail(self,handle,photo):
|
||||
ext = os.path.splitext(photo.get_path())[1]
|
||||
to_dir = self.build_path(handle,'thumb')
|
||||
to_path = os.path.join(to_dir,handle+".png")
|
||||
if photo.get_mime_type():
|
||||
from_path = ImgManip.get_thumbnail_path(photo.get_path(),photo.get_mime_type())
|
||||
if not os.path.isfile(from_path):
|
||||
from_path = os.path.join(const.dataDir,"document.png")
|
||||
else:
|
||||
from_path = os.path.join(const.dataDir,"document.png")
|
||||
|
||||
if self.archive:
|
||||
imagefile = open(from_path,"r")
|
||||
self.archive.add_file(to_path,time.time(),imagefile)
|
||||
imagefile.close()
|
||||
else:
|
||||
to_dir = os.path.join(self.html_dir,to_dir)
|
||||
dest = os.path.join(self.html_dir,to_path)
|
||||
if not os.path.isdir(to_dir):
|
||||
os.makedirs(to_dir)
|
||||
try:
|
||||
shutil.copyfile(from_path,dest)
|
||||
except IOError:
|
||||
print "Could not copy file"
|
||||
|
||||
def copy_preview_image(handle,photo):
|
||||
base = '/desktop/gnome/thumbnailers/%s' % mtype.replace('/','@')
|
||||
thumbnailer = GrampsKeys.client.get_string(base + '/command')
|
||||
enable = GrampsKeys.client.get_bool(base + '/enable')
|
||||
if thumbnailer and enable:
|
||||
run_thumbnailer(thumbnailer,path,_build_thumb_path(path),320)
|
||||
return path
|
||||
else:
|
||||
return None
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
#
|
||||
|
@ -249,7 +249,8 @@ class SimpleBookTitleOptions(ReportOptions.ReportOptions):
|
||||
return
|
||||
self.options_dict['imgid'] = the_object.get_gramps_id()
|
||||
self.obj_title.set_text(the_object.get_description())
|
||||
icon_image = ImgManip.get_thumbnail_image(the_object.get_path())
|
||||
icon_image = ImgManip.get_thumbnail_image(the_object.get_path(),
|
||||
the_object.get_mime_type())
|
||||
self.preview.set_from_pixbuf(icon_image)
|
||||
self.remove_obj_button.set_sensitive(True)
|
||||
self.size.set_sensitive(True)
|
||||
|
Loading…
x
Reference in New Issue
Block a user