More robust error checking
svn: r692
This commit is contained in:
parent
9878aa0d34
commit
de4851f566
@ -126,16 +126,27 @@ class MediaView:
|
||||
obj.thaw()
|
||||
|
||||
def on_select_row(self,obj,row,b,c):
|
||||
fexists = 1
|
||||
|
||||
mobj = obj.get_row_data(row)
|
||||
type = mobj.getMimeType()
|
||||
type_name = utils.get_mime_description(type)
|
||||
path = mobj.getPath()
|
||||
self.preview.load_file(utils.thumb_path(self.db.getSavePath(),mobj))
|
||||
thumb_path = utils.thumb_path(self.db.getSavePath(),mobj)
|
||||
pexists = os.path.exists(path)
|
||||
if pexists and os.path.exists(thumb_path):
|
||||
self.preview.load_file(thumb_path)
|
||||
else:
|
||||
self.preview.load_file(utils.find_icon(type))
|
||||
if not pexists:
|
||||
fexists = 0
|
||||
|
||||
self.mid.set_text(mobj.getId())
|
||||
self.mtype.set_text(type_name)
|
||||
self.mdesc.set_text(mobj.getDescription())
|
||||
if path[0] == "/":
|
||||
if len(path) == 0 or fexists == 0:
|
||||
self.mpath.set_text(_("The file no longer exists"))
|
||||
elif path[0] == "/":
|
||||
self.mpath.set_text(path)
|
||||
else:
|
||||
self.mpath.set_text("<local>")
|
||||
@ -175,8 +186,9 @@ class MediaView:
|
||||
path = self.db.getSavePath()
|
||||
id = self.obj.getId()
|
||||
name = RelImage.import_media_object(self.obj.getPath(),path,id)
|
||||
self.obj.setPath(name)
|
||||
self.obj.setLocal(1)
|
||||
if name:
|
||||
self.obj.setPath(name)
|
||||
self.obj.setLocal(1)
|
||||
|
||||
def popup_change_description(self, obj):
|
||||
ImageSelect.GlobalMediaProperties(self.db,self.obj,self.load_media)
|
||||
@ -304,8 +316,9 @@ class MediaView:
|
||||
name = RelImage.import_media_object(name,
|
||||
self.db.getSavePath(),
|
||||
photo.getId())
|
||||
photo.setPath(name)
|
||||
photo.setLocal(1)
|
||||
if name:
|
||||
photo.setPath(name)
|
||||
photo.setLocal(1)
|
||||
utils.modified()
|
||||
if Config.globalprop:
|
||||
ImageSelect.GlobalMediaProperties(self.db,photo,self.load_media)
|
||||
@ -332,8 +345,9 @@ class MediaView:
|
||||
id = photo.getId()
|
||||
path = self.db.getSavePath()
|
||||
name = RelImage.import_media_object(tfile,path,id)
|
||||
photo.setLocal(1)
|
||||
photo.setPath(name)
|
||||
if name:
|
||||
photo.setLocal(1)
|
||||
photo.setPath(name)
|
||||
except:
|
||||
photo.setPath(tfile)
|
||||
w.drag_finish(context, 1, 0, time)
|
||||
|
@ -63,6 +63,10 @@ except:
|
||||
def import_media_object(filename,path,base):
|
||||
import shutil
|
||||
|
||||
if not os.path.exists(filename):
|
||||
GnomeErrorDialog(_("Could not import %s\nThe file has been moved or deleted") % filename)
|
||||
return ""
|
||||
|
||||
type = utils.get_mime_type(filename)
|
||||
if type[0:5] == "image":
|
||||
name = "%s/%s.jpg" % (path,base)
|
||||
@ -83,9 +87,16 @@ def import_media_object(filename,path,base):
|
||||
try:
|
||||
path = "%s/%s" % (thumb,base)
|
||||
mk_thumb(filename,path,const.thumbScale)
|
||||
shutil.copy(filename,name)
|
||||
except:
|
||||
GnomeErrorDialog(_("Error creating the thumbnail : %s") + "\n" + msg)
|
||||
return ""
|
||||
|
||||
try:
|
||||
shutil.copy(filename,name)
|
||||
except IOError,msg:
|
||||
GnomeErrorDialog(_("Error copying %s") + "\n" + msg)
|
||||
return ""
|
||||
|
||||
else:
|
||||
bname = os.path.basename(filename)
|
||||
l = string.split(bname,'.')
|
||||
@ -106,13 +117,18 @@ def scale_image(path,size):
|
||||
image1 = GdkImlib.Image(path)
|
||||
except:
|
||||
GnomeWarningDialog(_("Could not load image file %s") % path)
|
||||
return
|
||||
return GdkImlib.Image(const.icon)
|
||||
|
||||
width = image1.rgb_width
|
||||
height = image1.rgb_height
|
||||
|
||||
scale = size / float(max(width,height))
|
||||
image2 = image1.clone_scaled_image(int(scale*width), int(scale*height))
|
||||
try:
|
||||
image2 = image1.clone_scaled_image(int(scale*width), int(scale*height))
|
||||
except:
|
||||
GnomeWarningDialog(_("Could not load image file %s") % path)
|
||||
return GdkImlib.Image(const.icon)
|
||||
|
||||
return image2
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
@ -121,7 +137,6 @@ def scale_image(path,size):
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
def mk_thumb(source,dest,size):
|
||||
|
||||
dir = os.path.dirname(dest)
|
||||
try:
|
||||
if not os.path.exists(dir):
|
||||
@ -134,11 +149,18 @@ def mk_thumb(source,dest,size):
|
||||
return
|
||||
|
||||
if os.path.exists(dest):
|
||||
os.remove(dest)
|
||||
try:
|
||||
os.remove(dest)
|
||||
except IOError,msg:
|
||||
errmsg = _("Could not replace %s") % dir
|
||||
GnomeErrorDialog(errmsg + "\n" + msg)
|
||||
return
|
||||
|
||||
if not os.path.exists(source):
|
||||
GnomeErrorDialog(_("Could not create a thumbnail for %s\nThe file has been moved or deleted") % filename)
|
||||
|
||||
if no_pil:
|
||||
cmd = "%s -geometry %dx%d '%s' '%s'" % (const.convert,size,size,source,dest)
|
||||
print cmd
|
||||
os.system(cmd)
|
||||
else:
|
||||
try:
|
||||
@ -148,10 +170,9 @@ def mk_thumb(source,dest,size):
|
||||
im.draft('RGB',im.size)
|
||||
im = im.convert("RGB")
|
||||
im.save(dest,"JPEG")
|
||||
print "saving",dest
|
||||
except:
|
||||
print "save failed"
|
||||
pass
|
||||
GnomeErrorDialog(_("Could not create a thumbnail for %s") % source)
|
||||
return
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
@ -160,11 +181,11 @@ def mk_thumb(source,dest,size):
|
||||
#-------------------------------------------------------------------------
|
||||
def check_thumb(source,dest,size):
|
||||
if not os.path.isfile(source):
|
||||
return
|
||||
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
|
||||
|
||||
|
||||
|
@ -255,7 +255,7 @@ class AncestorChartDialog(DrawReportDialog):
|
||||
#------------------------------------------------------------------------
|
||||
def get_title(self):
|
||||
"""The window title for this dialog"""
|
||||
return _("Gramps - Ancestor Chart")
|
||||
return "%s - %s - GRAMPS" % (_("Ancestor Chart"),_("Graphical Reports"))
|
||||
|
||||
def get_header(self, name):
|
||||
"""The header line at the top of the dialog contents."""
|
||||
|
@ -235,7 +235,7 @@ class AncestorReportDialog(TextReportDialog):
|
||||
#------------------------------------------------------------------------
|
||||
def get_title(self):
|
||||
"""The window title for this dialog"""
|
||||
return _("Gramps - Ahnentafel Report")
|
||||
return "%s - %s - GRAMPS" % (_("Ahnentafel Report"),_("Text Reports"))
|
||||
|
||||
def get_header(self, name):
|
||||
"""The header line at the top of the dialog contents"""
|
||||
|
@ -310,7 +310,7 @@ class DescendantReportDialog(DrawReportDialog):
|
||||
DrawReportDialog.__init__(self,database,person)
|
||||
|
||||
def get_title(self):
|
||||
return _("Gramps - Descendant Graph")
|
||||
return "%s - %s - GRAMPS" % (_("Descendant Graph"),_("Graphical Reports"))
|
||||
|
||||
def get_header(self,name):
|
||||
return _("Descendant Graph for %s") % name
|
||||
|
@ -140,7 +140,7 @@ class DescendantReportDialog(TextReportDialog):
|
||||
#------------------------------------------------------------------------
|
||||
def get_title(self):
|
||||
"""The window title for this dialog"""
|
||||
return _("Gramps - Descendant Report")
|
||||
return "%s - %s - GRAMPS" % (_("Descendant Report"),_("Text Reports"))
|
||||
|
||||
def get_header(self, name):
|
||||
"""The header line at the top of the dialog contents"""
|
||||
|
@ -335,7 +335,7 @@ class FamilyGroupDialog(TextReportDialog):
|
||||
#------------------------------------------------------------------------
|
||||
def get_title(self):
|
||||
"""The window title for this dialog"""
|
||||
return _("Gramps - Family Group Report")
|
||||
return "%s - %s - GRAMPS" % (_("Family Group Report"),_("Text Reports"))
|
||||
|
||||
def get_header(self, name):
|
||||
"""The header line at the top of the dialog contents"""
|
||||
|
@ -126,7 +126,7 @@ class GraphVizDialog(ReportDialog):
|
||||
#------------------------------------------------------------------------
|
||||
def get_title(self):
|
||||
"""The window title for this dialog"""
|
||||
return _("Gramps - Generate Relationship Graphs")
|
||||
return "%s - %s - GRAMPS" % (_("Relationship Graph"),_("Graphical Reports"))
|
||||
|
||||
def get_target_browser_title(self):
|
||||
"""The title of the window created when the 'browse' button is
|
||||
@ -283,7 +283,7 @@ from Plugins import register_report
|
||||
|
||||
register_report(
|
||||
report,
|
||||
_("Relationship graph"),
|
||||
_("Relationship Graph"),
|
||||
status=(_("Beta")),
|
||||
category=_("Graphical Reports"),
|
||||
description=get_description()
|
||||
|
@ -327,7 +327,7 @@ class IndivSummaryDialog(TextReportDialog):
|
||||
#------------------------------------------------------------------------
|
||||
def get_title(self):
|
||||
"""The window title for this dialog"""
|
||||
return _("Gramps - Individual Summary")
|
||||
return "%s - %s - GRAMPS" %(_("Individual Summary"),_("Text Reports"))
|
||||
|
||||
def get_header(self, name):
|
||||
"""The header line at the top of the dialog contents"""
|
||||
|
@ -41,7 +41,6 @@ from gnome.ui import *
|
||||
from libglade import *
|
||||
from Report import *
|
||||
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
#
|
||||
@ -813,7 +812,7 @@ class WebReportDialog(ReportDialog):
|
||||
#------------------------------------------------------------------------
|
||||
def get_title(self):
|
||||
"""The window title for this dialog"""
|
||||
return _("Gramps - Generate HTML reports")
|
||||
return "%s - %s - GRAMPS" % (_("Generate Web Site"),_("Web Page"))
|
||||
|
||||
def get_target_browser_title(self):
|
||||
"""The title of the window created when the 'browse' button is
|
||||
|
@ -420,8 +420,10 @@ def thumb_path(dir,mobj):
|
||||
if type[0:5] == "image":
|
||||
thumb = "%s/.thumb/%s.jpg" % (dir,mobj.getId())
|
||||
try:
|
||||
RelImage.check_thumb(mobj.getPath(),thumb,const.thumbScale)
|
||||
return thumb
|
||||
if RelImage.check_thumb(mobj.getPath(),thumb,const.thumbScale):
|
||||
return thumb
|
||||
else:
|
||||
return find_icon(type)
|
||||
except:
|
||||
return find_icon(type)
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user