* 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>
|
2005-08-30 Martin Hawlisch <Martin.Hawlisch@gmx.de>
|
||||||
* src/plugins/NavWebPage.py: Encode using 'xmlcharrefreplace'
|
* src/plugins/NavWebPage.py: Encode using 'xmlcharrefreplace'
|
||||||
* src/plugins/WriteGeneWeb.py: Remove empty families before running
|
* src/plugins/WriteGeneWeb.py: Remove empty families before running
|
||||||
|
@ -291,7 +291,8 @@ class Gallery(ImageSelect):
|
|||||||
if const.dnd_images:
|
if const.dnd_images:
|
||||||
handle = self.sel_obj.get_reference_handle()
|
handle = self.sel_obj.get_reference_handle()
|
||||||
media_obj = self.db.get_object_from_handle(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)
|
context.set_icon_pixbuf(pix,0,0)
|
||||||
|
|
||||||
def item_event(self, widget, event=None):
|
def item_event(self, widget, event=None):
|
||||||
|
@ -103,24 +103,28 @@ def _build_thumb_path(path):
|
|||||||
m = md5.md5(path)
|
m = md5.md5(path)
|
||||||
return os.path.join(base,m.hexdigest()+'.png')
|
return os.path.join(base,m.hexdigest()+'.png')
|
||||||
|
|
||||||
def run_thumbnailer(cmd, frm, to):
|
def run_thumbnailer(mtype, frm, to, size=const.thumbScale):
|
||||||
sublist = {
|
sublist = {
|
||||||
'%s' : "%dx%d" % (int(const.thumbScale),int(const.thumbScale)),
|
'%s' : "%dx%d" % (int(size),int(size)),
|
||||||
'%u' : frm,
|
'%u' : frm,
|
||||||
'%o' : to,
|
'%o' : to,
|
||||||
}
|
}
|
||||||
cmdlist = map(lambda x: sublist.get(x,x),cmd.split())
|
|
||||||
if os.fork() == 0:
|
base = '/desktop/gnome/thumbnailers/%s' % mtype.replace('/','@')
|
||||||
os.execvp(cmdlist[0],cmdlist)
|
cmd = GrampsKeys.client.get_string(base + '/command')
|
||||||
os.wait()
|
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):
|
def set_thumbnail_image(path,mtype=None):
|
||||||
if mtype and not mtype.startswith('image/'):
|
if mtype and not mtype.startswith('image/'):
|
||||||
base = '/desktop/gnome/thumbnailers/%s' % mtype.replace('/','@')
|
run_thumbnailer(mtype,path,_build_thumb_path(path))
|
||||||
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))
|
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
pixbuf = gtk.gdk.pixbuf_new_from_file(path)
|
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 = pixbuf.scale_simple(pw,ph,gtk.gdk.INTERP_BILINEAR)
|
||||||
pixbuf.save(_build_thumb_path(path),"png")
|
pixbuf.save(_build_thumb_path(path),"png")
|
||||||
except:
|
except:
|
||||||
print "Could not create thumbnail for",path,mtype
|
pass
|
||||||
|
|
||||||
def get_thumbnail_image(path,mtype=None):
|
def get_thumbnail_image(path,mtype=None):
|
||||||
filename = _build_thumb_path(path)
|
filename = _build_thumb_path(path)
|
||||||
@ -151,5 +155,6 @@ def get_thumbnail_image(path,mtype=None):
|
|||||||
def get_thumbnail_path(path,mtype=None):
|
def get_thumbnail_path(path,mtype=None):
|
||||||
filename = _build_thumb_path(path)
|
filename = _build_thumb_path(path)
|
||||||
if not os.path.isfile(filename):
|
if not os.path.isfile(filename):
|
||||||
|
print "setting",filename
|
||||||
set_thumbnail_image(path,mtype)
|
set_thumbnail_image(path,mtype)
|
||||||
return filename
|
return filename
|
||||||
|
@ -117,7 +117,7 @@ class SelectObject:
|
|||||||
path = obj.get_path()
|
path = obj.get_path()
|
||||||
|
|
||||||
if the_type and the_type[0:5] == "image":
|
if the_type and the_type[0:5] == "image":
|
||||||
image = ImgManip.get_thumbnail_image(path)
|
image = ImgManip.get_thumbnail_image(path,the_type)
|
||||||
else:
|
else:
|
||||||
image = Utils.find_mime_type_pixbuf(the_type)
|
image = Utils.find_mime_type_pixbuf(the_type)
|
||||||
self.preview.set_from_pixbuf(image)
|
self.preview.set_from_pixbuf(image)
|
||||||
|
@ -140,7 +140,11 @@ class BasePage:
|
|||||||
archive.add_file(to_path,time.time(),imagefile)
|
archive.add_file(to_path,time.time(),imagefile)
|
||||||
imagefile.close()
|
imagefile.close()
|
||||||
else:
|
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):
|
def copy_media(self,photo,store_ref=True):
|
||||||
|
|
||||||
@ -732,55 +736,18 @@ class MediaPage(BasePage):
|
|||||||
BasePage.__init__(self, title, options, archive, media_list,
|
BasePage.__init__(self, title, options, archive, media_list,
|
||||||
photo.gramps_id)
|
photo.gramps_id)
|
||||||
of = self.create_link_file(handle,"img")
|
of = self.create_link_file(handle,"img")
|
||||||
|
|
||||||
ext = os.path.splitext(photo.get_path())[1]
|
mime_type = photo.get_mime_type()
|
||||||
to_dir = self.build_path(handle,'images')
|
note_only = mime_type == None
|
||||||
newpath = os.path.join(to_dir,handle+ext)
|
|
||||||
target_exists = True
|
|
||||||
note_only = photo.get_path() == None or photo.get_path() == ''
|
|
||||||
|
|
||||||
if not note_only:
|
if not note_only:
|
||||||
try:
|
newpath = self.copy_source_file(handle, photo)
|
||||||
if self.archive:
|
target_exists = newpath != None
|
||||||
imagefile = open(photo.get_path(),"r")
|
else:
|
||||||
self.archive.add_file(newpath,time.time(),imagefile)
|
target_exists = False
|
||||||
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"
|
|
||||||
|
|
||||||
|
self.copy_thumbnail(handle, photo)
|
||||||
|
|
||||||
self.page_title = photo.get_description()
|
self.page_title = photo.get_description()
|
||||||
self.display_header(of,db, "%s - %s" % (_('Gallery'), title),
|
self.display_header(of,db, "%s - %s" % (_('Gallery'), title),
|
||||||
get_researcher().get_name(),up=True)
|
get_researcher().get_name(),up=True)
|
||||||
@ -800,30 +767,43 @@ class MediaPage(BasePage):
|
|||||||
|
|
||||||
of.write('</div>\n')
|
of.write('</div>\n')
|
||||||
|
|
||||||
if mime_type and mime_type.startswith("image"):
|
if mime_type:
|
||||||
of.write('<div class="centered">\n')
|
if mime_type.startswith("image/"):
|
||||||
if target_exists:
|
of.write('<div class="centered">\n')
|
||||||
of.write('<img ')
|
if target_exists:
|
||||||
of.write('src="../../../%s" alt="%s" />\n' % (newpath, self.page_title))
|
of.write('<img ')
|
||||||
elif not note_only:
|
of.write('src="../../../%s" alt="%s" />\n' % (newpath, self.page_title))
|
||||||
of.write('<br /><span>(%s)</span>' % _("The file has been moved or deleted"))
|
else:
|
||||||
of.write('</div>\n')
|
of.write('<br /><span>(%s)</span>' % _("The file has been moved or deleted"))
|
||||||
else:
|
of.write('</div>\n')
|
||||||
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)
|
|
||||||
else:
|
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')
|
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('<img ')
|
||||||
of.write('src="../../../%s" alt="%s" />\n' % (path, self.page_title))
|
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('</div>\n')
|
||||||
|
|
||||||
of.write('<table class="infolist">\n')
|
of.write('<table class="infolist">\n')
|
||||||
@ -845,6 +825,62 @@ class MediaPage(BasePage):
|
|||||||
self.display_footer(of,db)
|
self.display_footer(of,db)
|
||||||
self.close_file(of)
|
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
|
return
|
||||||
self.options_dict['imgid'] = the_object.get_gramps_id()
|
self.options_dict['imgid'] = the_object.get_gramps_id()
|
||||||
self.obj_title.set_text(the_object.get_description())
|
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.preview.set_from_pixbuf(icon_image)
|
||||||
self.remove_obj_button.set_sensitive(True)
|
self.remove_obj_button.set_sensitive(True)
|
||||||
self.size.set_sensitive(True)
|
self.size.set_sensitive(True)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user