* src/GrampsDbBase.py: move all thumbnail creation here to have
a common thumbnail scheme. * src/GrampsInMemDB.py: remove thumbnail handling, use base class svn: r3862
This commit is contained in:
parent
da527e786e
commit
66d77d7700
@ -1,3 +1,8 @@
|
|||||||
|
2005-01-03 Don Allingham <dallingham@users.sourceforge.net>
|
||||||
|
* src/GrampsDbBase.py: move all thumbnail creation here to have
|
||||||
|
a common thumbnail scheme.
|
||||||
|
* src/GrampsInMemDB.py: remove thumbnail handling, use base class
|
||||||
|
|
||||||
2005-01-02 Alex Roitman <shura@alex.neuro.umn.edu>
|
2005-01-02 Alex Roitman <shura@alex.neuro.umn.edu>
|
||||||
* src/Report.py: Add support for a semi-common 'dispf'.
|
* src/Report.py: Add support for a semi-common 'dispf'.
|
||||||
* src/ReportOptions.py: Add support for a semi-common 'dispf'.
|
* src/ReportOptions.py: Add support for a semi-common 'dispf'.
|
||||||
|
@ -37,6 +37,9 @@ import time
|
|||||||
import locale
|
import locale
|
||||||
import re
|
import re
|
||||||
from gettext import gettext as _
|
from gettext import gettext as _
|
||||||
|
import os
|
||||||
|
import md5
|
||||||
|
import gtk
|
||||||
|
|
||||||
import GrampsGconfKeys
|
import GrampsGconfKeys
|
||||||
import Utils
|
import Utils
|
||||||
@ -1217,13 +1220,35 @@ class GrampsDbBase:
|
|||||||
else:
|
else:
|
||||||
return cols
|
return cols
|
||||||
|
|
||||||
|
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):
|
def get_thumbnail_image(self,handle):
|
||||||
data = self.media_map.get(handle)
|
data = self.media_map.get(handle)
|
||||||
if data:
|
if data:
|
||||||
import ImgManip
|
filename = self._build_thumb_path(data[2])
|
||||||
return ImgManip.get_thumbnail_image(data[2])
|
if not os.path.isfile(filename):
|
||||||
|
self.set_thumbnail_image(handle,data[2])
|
||||||
|
return gtk.gdk.pixbuf_new_from_file(filename)
|
||||||
else:
|
else:
|
||||||
return None
|
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 = 96.0 / (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
|
||||||
|
|
||||||
class Transaction:
|
class Transaction:
|
||||||
"""
|
"""
|
||||||
|
@ -28,10 +28,6 @@ must hold all of their data in memory.
|
|||||||
from RelLib import *
|
from RelLib import *
|
||||||
from GrampsDbBase import *
|
from GrampsDbBase import *
|
||||||
|
|
||||||
import os
|
|
||||||
import md5
|
|
||||||
import gtk
|
|
||||||
|
|
||||||
class GrampsInMemCursor(GrampsCursor):
|
class GrampsInMemCursor(GrampsCursor):
|
||||||
"""
|
"""
|
||||||
Cursor class for in-memory database classes. Since the in-memory
|
Cursor class for in-memory database classes. Since the in-memory
|
||||||
@ -222,32 +218,3 @@ class GrampsInMemDB(GrampsDbBase):
|
|||||||
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
|
|
||||||
|
Loading…
Reference in New Issue
Block a user