Fixed an error in convert_file().

svn: r17869
This commit is contained in:
Rob G. Healey 2011-06-30 02:16:47 +00:00
parent 191790e1bd
commit ab8c2d8693

View File

@ -413,10 +413,11 @@ class EditExifMetadata(Gramplet):
# remove the extension out of the list of convertible image types... # remove the extension out of the list of convertible image types...
# What would make sense to be able to convert to your current image type? # What would make sense to be able to convert to your current image type?
PILConvert = _validconvert PILConvert = _validconvert
PILConvert.remove(self.extension) if self.extension in PILConvert:
PILConvert.remove(self.extension)
PILConvert.sort() PILConvert.sort()
_VCONVERTMAP = dict( (index, imgtype_) for index, imgtype_ in enumerate(PILConvert) ) self._VCONVERTMAP = dict( (index, imgtype_) for index, imgtype_ in enumerate(PILConvert) )
for imgtype_ in _VCONVERTMAP.values(): for imgtype_ in self._VCONVERTMAP.values():
self.exif_widgets["ImageType"].append_text(imgtype_) self.exif_widgets["ImageType"].append_text(imgtype_)
self.exif_widgets["ImageType"].set_active(0) self.exif_widgets["ImageType"].set_active(0)
@ -815,16 +816,19 @@ class EditExifMetadata(Gramplet):
# get extension selected for converting this image... # get extension selected for converting this image...
ext_type = self.exif_widgets["ImageType"].get_active() ext_type = self.exif_widgets["ImageType"].get_active()
if ext_type >= 1: if ext_type >= 1:
basename += _VCONVERTMAP[ext_type] basename += self._VCONVERTMAP[ext_type]
# new file name and dirpath... # new file name and dirpath...
dest_file = os.path.join(filepath, basename) dest_file = os.path.join(filepath, basename)
# Convert the file based upon file suffix # Convert the file based upon image file suffix...
i = Image.open(full_path) i = Image.open(full_path)
im = i.Filter(ImageFilter.SHARPEN) if i.mode == "RGB":
im.Filter(ImageFilter.DETAIL) im = i.filter(ImageFilter.SHARPEN)
im.save(dest_file) i1 = im.filter(ImageFilter.DETAIL)
i1.save(dest_file)
else:
i.save(dest_file)
if LesserVersion: # prior to pyexiv2-0.2.0... if LesserVersion: # prior to pyexiv2-0.2.0...
src_meta = pyexiv2.Image(full_path) src_meta = pyexiv2.Image(full_path)
@ -860,17 +864,18 @@ class EditExifMetadata(Gramplet):
# Convert image and copy over it's Exif metadata (if any?) # Convert image and copy over it's Exif metadata (if any?)
newfilepath = self.__convert_file(full_path) newfilepath = self.__convert_file(full_path)
# delete original file from this computer... # delete original file from this computer and set new filepath...
try: try:
os.remove(full_path) os.remove(full_path)
delete_results = True delete_results = True
except (IOError, OSError): except (IOError, OSError):
delete_results = False delete_results = False
if delete_results: if delete_results:
# update media object path... # update media object path...
if newfilepath is not False: if (newfilepath is not False and os.path.isfile(newfilepath) ):
# begin database tranaction to save media object new path... # begin database tranaction to save media object new path...
with DbTxn(_("Media Path Update"), db) as trans: with DbTxn(_("Media Path Update"), db) as trans:
@ -882,8 +887,10 @@ class EditExifMetadata(Gramplet):
db.enable_signals() db.enable_signals()
db.request_rebuild() db.request_rebuild()
# notify user about the convert, delete, and new filepath...
self.exif_widgets["MessageArea"].set_text(_("Your image has been " self.exif_widgets["MessageArea"].set_text(_("Your image has been "
"converted and the original file has been deleted...")) "converted and the original file has been deleted, and "
"the full path has been updated!"))
def __help_page(self, object): def __help_page(self, object):
""" """