remove convert dependency

svn: r6217
This commit is contained in:
Don Allingham 2006-03-29 03:21:29 +00:00
parent 4761c816c5
commit e2100245d4
3 changed files with 60 additions and 69 deletions

View File

@ -10,6 +10,9 @@
* src/plugins/FamilyGroup.py: use new functions * src/plugins/FamilyGroup.py: use new functions
2006-03-28 Don Allingham <don@gramps-project.org> 2006-03-28 Don Allingham <don@gramps-project.org>
* src/const.py.in: use_thumbnail tag
* src/ImgManip.py: use pygtk instead of Imagick for image
conversions
* src/Mime/_GnomeMime.py: find the default application instead of * src/Mime/_GnomeMime.py: find the default application instead of
using the first returned by mime_get_app_short_list using the first returned by mime_get_app_short_list

View File

@ -28,6 +28,7 @@
import os import os
import signal import signal
import md5 import md5
import tempfile
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -53,63 +54,46 @@ import Utils
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class ImgManip: class ImgManip:
def __init__(self,source): def __init__(self, source):
self.src = source self.src = source
def size(self):
try: try:
img = gtk.gdk.pixbuf_new_from_file(self.src) self.img = gtk.gdk.pixbuf_new_from_file(self.src)
self.width = self.img.get_width()
self.height = self.img.get_height()
except gobject.GError: except gobject.GError:
return (0,0) return (0,0)
return (img.get_width(),img.get_height())
def size(self):
return (self.width, self.height)
def fmt_thumbnail(self,dest,width,height,cnv): def fmt_thumbnail(self,dest,width,height,cnv):
w = int(width) w = int(width)
h = int(height) h = int(height)
cmd = "%s -geometry %dx%d '%s' '%s:%s'" % (const.convert,
w,h,self.src,cnv,dest)
os.system(cmd)
def fmt_convert(self,dest,cnv): scaled = self.img.scale_simple(width, height, gtk.gdk.INTERP_BILINEAR)
cmd = "%s '%s' '%s:%s'" % (const.convert,self.src,cnv,dest) scaled.save(dest,cnv)
os.system(cmd)
def fmt_data(self,cnv): def fmt_data(self, cnv):
import popen2 fd, dest = tempfile.mkstemp()
self.img.save(dest,cnv)
fh = open(dest)
data = fh.read()
fh.close()
os.unlink(dest)
return data
cmd = "%s '%s' '%s:-'" % (const.convert,self.src,cnv) def fmt_scale_data(self, x, y, cnv):
r,w = popen2.popen2(cmd) fd, dest = tempfile.mkstemp()
buf = r.read() scaled = self.img.scale_simple(width, height, gtk.gdk.INTERP_BILINEAR)
r.close() self.img.save(dest,cnv)
w.close() fh = open(dest)
return buf data = fh.read()
fh.close()
os.unlink(dest)
return data
def fmt_scale_data(self,x,y,cnv): def jpg_thumbnail(self, dest, width, height):
import popen2 self.fmt_thumbnail(dest, width, height, "jpeg")
cmd = "%s -geometry %dx%d '%s' '%s:-'" % (const.convert,
x,y,self.src,cnv)
signal.signal (signal.SIGCHLD, signal.SIG_DFL)
r,w = popen2.popen2(cmd)
buf = r.read()
r.close()
w.close()
return buf
def jpg_thumbnail(self,dest,width,height):
self.fmt_thumbnail(dest,width,height,"jpeg")
def png_thumbnail(self,dest,width,height):
self.fmt_thumbnail(dest,width,height,"png")
def jpg_convert(self,dest):
self.fmt_convert(dest,"jpeg")
def png_convert(self,dest):
self.fmt_convert(dest,"png")
def eps_convert(self,dest):
self.fmt_convert(dest,"eps")
def jpg_data(self): def jpg_data(self):
return self.fmt_data("jpeg") return self.fmt_data("jpeg")
@ -117,39 +101,41 @@ class ImgManip:
def png_data(self): def png_data(self):
return self.fmt_data("png") return self.fmt_data("png")
def jpg_scale_data(self,x,y): def jpg_scale_data(self, x, y):
return self.fmt_scale_data(x,y,"jpeg") return self.fmt_scale_data(x, y, "jpeg")
def png_scale_data(self,x,y): def png_scale_data(self,x,y):
return self.fmt_scale_data(x,y,"png") return self.fmt_scale_data(x, y, "png")
def _build_thumb_path(path): def _build_thumb_path(path):
base = os.path.expanduser('~/.gramps/thumb')
m = md5.md5(path) m = md5.md5(path)
return os.path.join(base,m.hexdigest()+'.png') return os.path.join(const.thumb_dir, m.hexdigest()+'.png')
def run_thumbnailer(mtype, frm, to, size=const.thumbScale): def run_thumbnailer(mtype, frm, to, size=const.thumbScale):
sublist = { if const.use_thumbnailer:
'%s' : "%dx%d" % (int(size),int(size)), sublist = {
'%u' : frm, '%s' : "%dx%d" % (int(size),int(size)),
'%o' : to, '%u' : frm,
} '%o' : to,
}
base = '/desktop/gnome/thumbnailers/%s' % mtype.replace('/','@') base = '/desktop/gnome/thumbnailers/%s' % mtype.replace('/','@')
cmd = Config.get_string(base + '/command') cmd = Config.get_string(base + '/command')
enable = Config.get_bool(base + '/enable') enable = Config.get_bool(base + '/enable')
if cmd and enable: if cmd and enable:
cmdlist = map(lambda x: sublist.get(x,x),cmd.split()) cmdlist = map(lambda x: sublist.get(x,x),cmd.split())
if os.fork() == 0: if os.fork() == 0:
os.execvp(cmdlist[0],cmdlist) os.execvp(cmdlist[0],cmdlist)
os.wait() os.wait()
return True return True
else:
return False
return False 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/'):
run_thumbnailer(mtype,path,_build_thumb_path(path)) run_thumbnailer(mtype,path,_build_thumb_path(path))
else: else:
@ -167,7 +153,7 @@ def set_thumbnail_image(path,mtype=None):
except: except:
pass 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)
try: try:
@ -184,7 +170,7 @@ def get_thumbnail_image(path,mtype=None):
return gtk.gdk.pixbuf_new_from_file(os.path.join( return gtk.gdk.pixbuf_new_from_file(os.path.join(
const.image_dir,"document.png")) const.image_dir,"document.png"))
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):
set_thumbnail_image(path,mtype) set_thumbnail_image(path,mtype)
@ -192,7 +178,7 @@ def get_thumbnail_path(path,mtype=None):
def get_thumb_from_obj(obj): def get_thumb_from_obj(obj):
mtype = obj.get_mime_type() mtype = obj.get_mime_type()
if mtype[0:5] == "image": if mtype.startswith("image/"):
image = get_thumbnail_image(obj.get_path()) image = get_thumbnail_image(obj.get_path())
else: else:
image = Mime.find_mime_type_pixbuf(mtype) image = Mime.find_mime_type_pixbuf(mtype)

View File

@ -95,6 +95,7 @@ image_dir = os.path.join(root_dir,"images")
custom_filters = os.path.join(home_dir,"custom_filters.xml") custom_filters = os.path.join(home_dir,"custom_filters.xml")
report_options = os.path.join(home_dir,"report_options.xml") report_options = os.path.join(home_dir,"report_options.xml")
tool_options = os.path.join(home_dir,"tool_options.xml") tool_options = os.path.join(home_dir,"tool_options.xml")
thumb_dir = os.path.join(home_dir,"thumb")
bsddbenv_dir = os.path.join(home_dir,"bsddbenv") bsddbenv_dir = os.path.join(home_dir,"bsddbenv")
icon = os.path.join(root_dir,"images","gramps.png") icon = os.path.join(root_dir,"images","gramps.png")
@ -127,6 +128,7 @@ papersize = "file:%s/papersize.xml" % data_dir
startup = 1 startup = 1
dnd_images = 1 dnd_images = 1
use_tips = False use_tips = False
use_thumbnailer= True
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #