From de4851f5660df1cf76dd6071818bd22e66363045 Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Wed, 9 Jan 2002 03:17:19 +0000 Subject: [PATCH] More robust error checking svn: r692 --- gramps/src/MediaView.py | 30 ++++++++++++++----- gramps/src/RelImage.py | 45 ++++++++++++++++++++-------- gramps/src/plugins/AncestorChart.py | 2 +- gramps/src/plugins/AncestorReport.py | 2 +- gramps/src/plugins/DesGraph.py | 2 +- gramps/src/plugins/DescendReport.py | 2 +- gramps/src/plugins/FamilyGroup.py | 2 +- gramps/src/plugins/GraphViz.py | 4 +-- gramps/src/plugins/IndivSummary.py | 2 +- gramps/src/plugins/WebPage.py | 3 +- gramps/src/utils.py | 6 ++-- 11 files changed, 68 insertions(+), 32 deletions(-) diff --git a/gramps/src/MediaView.py b/gramps/src/MediaView.py index ac866daa0..107f60861 100644 --- a/gramps/src/MediaView.py +++ b/gramps/src/MediaView.py @@ -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("") @@ -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) diff --git a/gramps/src/RelImage.py b/gramps/src/RelImage.py index 5eaa71008..fd7cc9bed 100644 --- a/gramps/src/RelImage.py +++ b/gramps/src/RelImage.py @@ -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 diff --git a/gramps/src/plugins/AncestorChart.py b/gramps/src/plugins/AncestorChart.py index a23522cbb..83821e546 100644 --- a/gramps/src/plugins/AncestorChart.py +++ b/gramps/src/plugins/AncestorChart.py @@ -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.""" diff --git a/gramps/src/plugins/AncestorReport.py b/gramps/src/plugins/AncestorReport.py index ccebdd181..671e2a907 100644 --- a/gramps/src/plugins/AncestorReport.py +++ b/gramps/src/plugins/AncestorReport.py @@ -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""" diff --git a/gramps/src/plugins/DesGraph.py b/gramps/src/plugins/DesGraph.py index 012ce19c3..e96e75113 100644 --- a/gramps/src/plugins/DesGraph.py +++ b/gramps/src/plugins/DesGraph.py @@ -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 diff --git a/gramps/src/plugins/DescendReport.py b/gramps/src/plugins/DescendReport.py index 53deab164..a0252befe 100644 --- a/gramps/src/plugins/DescendReport.py +++ b/gramps/src/plugins/DescendReport.py @@ -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""" diff --git a/gramps/src/plugins/FamilyGroup.py b/gramps/src/plugins/FamilyGroup.py index 365287c80..93a1147c2 100644 --- a/gramps/src/plugins/FamilyGroup.py +++ b/gramps/src/plugins/FamilyGroup.py @@ -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""" diff --git a/gramps/src/plugins/GraphViz.py b/gramps/src/plugins/GraphViz.py index 5b9844c9f..e10b2378f 100644 --- a/gramps/src/plugins/GraphViz.py +++ b/gramps/src/plugins/GraphViz.py @@ -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() diff --git a/gramps/src/plugins/IndivSummary.py b/gramps/src/plugins/IndivSummary.py index 2eebb0f7d..e19cf5881 100644 --- a/gramps/src/plugins/IndivSummary.py +++ b/gramps/src/plugins/IndivSummary.py @@ -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""" diff --git a/gramps/src/plugins/WebPage.py b/gramps/src/plugins/WebPage.py index 1e9ad998b..23c63849c 100644 --- a/gramps/src/plugins/WebPage.py +++ b/gramps/src/plugins/WebPage.py @@ -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 diff --git a/gramps/src/utils.py b/gramps/src/utils.py index 9c9c26371..fcdc11ada 100644 --- a/gramps/src/utils.py +++ b/gramps/src/utils.py @@ -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: