Modified valid PIL.Image file types to match file types in valid exiv2 types.
svn: r17909
This commit is contained in:
parent
cd6418d90c
commit
b09102b184
@ -41,7 +41,6 @@ from fractions import Fraction
|
|||||||
|
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
# GTK modules
|
# GTK modules
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
@ -73,6 +72,7 @@ from gen.db import DbTxn
|
|||||||
from ListModel import ListModel
|
from ListModel import ListModel
|
||||||
|
|
||||||
import pyexiv2
|
import pyexiv2
|
||||||
|
|
||||||
# v0.1 has a different API to v0.2 and above
|
# v0.1 has a different API to v0.2 and above
|
||||||
if hasattr(pyexiv2, 'version_info'):
|
if hasattr(pyexiv2, 'version_info'):
|
||||||
OLD_API = False
|
OLD_API = False
|
||||||
@ -81,7 +81,7 @@ else:
|
|||||||
OLD_API = True
|
OLD_API = True
|
||||||
|
|
||||||
#------------------------------------------------
|
#------------------------------------------------
|
||||||
# support helpers
|
# support functions
|
||||||
#------------------------------------------------
|
#------------------------------------------------
|
||||||
def _format_datetime(tag_value):
|
def _format_datetime(tag_value):
|
||||||
"""
|
"""
|
||||||
@ -156,14 +156,14 @@ def _parse_datetime(value):
|
|||||||
# Constants
|
# Constants
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
# available image types for exiv2 and pyexiv2
|
# available image types for exiv2 and pyexiv2
|
||||||
_vtypes = [".jpeg", ".jpg", ".jfif", ".exv", ".dng", ".bmp", ".nef", ".png", ".psd",
|
_vtypes = [".bmp", ".dng", ".exv", ".jp2", ".jpeg", ".jpg", ".nef", ".pef",
|
||||||
".jp2", ".pef", ".srw", ".pgf", ".tiff"]
|
".pgf", ".png", ".psd", ".srw", ".tiff"]
|
||||||
_vtypes.sort()
|
|
||||||
_VALIDIMAGEMAP = dict( (index, imgtype) for index, imgtype in enumerate(_vtypes) )
|
_VALIDIMAGEMAP = dict( (index, imgtype) for index, imgtype in enumerate(_vtypes) )
|
||||||
|
|
||||||
# valid converting types for PIL.Image...
|
# valid converting types for PIL.Image...
|
||||||
_validconvert = list( (".bmp", ".gif", ".jpg", ".msp", ".pcx", ".png", ".ppm", ".tiff", ".xbm") )
|
# there are more image formats that PIL.Image can convert to,
|
||||||
_validconvert.sort()
|
# but they are not usable in exiv2/ pyexiv2...
|
||||||
|
_validconvert = [_("<-- Image Types -->"), ".bmp", ".jpg", ".png", ".tiff"]
|
||||||
|
|
||||||
# Categories for Separating the nodes of Exif metadata tags...
|
# Categories for Separating the nodes of Exif metadata tags...
|
||||||
DESCRIPTION = _("Description")
|
DESCRIPTION = _("Description")
|
||||||
@ -308,7 +308,7 @@ _BUTTONTIPS = {
|
|||||||
"Thumbnail" : _("Will produce a Popup window showing a Thumbnail Viewing Area"),
|
"Thumbnail" : _("Will produce a Popup window showing a Thumbnail Viewing Area"),
|
||||||
|
|
||||||
# Image Type button...
|
# Image Type button...
|
||||||
"ImageType" : _("Select from a drop- down box the image file type that you "
|
"ImageTypes" : _("Select from a drop- down box the image file type that you "
|
||||||
"would like to convert your non- Exiv2 compatible media object to."),
|
"would like to convert your non- Exiv2 compatible media object to."),
|
||||||
|
|
||||||
# Convert to different image type...
|
# Convert to different image type...
|
||||||
@ -410,11 +410,11 @@ class EditExifMetadata(Gramplet):
|
|||||||
event_box.show()
|
event_box.show()
|
||||||
|
|
||||||
combo_box = gtk.combo_box_new_text()
|
combo_box = gtk.combo_box_new_text()
|
||||||
combo_box.append_text(_("--Image Types--"))
|
combo_box.append_text(_validconvert[0])
|
||||||
combo_box.set_active(0)
|
combo_box.set_active(0)
|
||||||
combo_box.set_sensitive(False)
|
combo_box.set_sensitive(False)
|
||||||
event_box.add(combo_box)
|
event_box.add(combo_box)
|
||||||
self.exif_widgets["ImageType"] = combo_box
|
self.exif_widgets["ImageTypes"] = combo_box
|
||||||
combo_box.show()
|
combo_box.show()
|
||||||
|
|
||||||
# Convert button...
|
# Convert button...
|
||||||
@ -428,7 +428,7 @@ class EditExifMetadata(Gramplet):
|
|||||||
button.show()
|
button.show()
|
||||||
|
|
||||||
# Connect the changed signal to ImageType...
|
# Connect the changed signal to ImageType...
|
||||||
self.exif_widgets["ImageType"].connect("changed", self.changed_cb)
|
self.exif_widgets["ImageTypes"].connect("changed", self.changed_cb)
|
||||||
|
|
||||||
# Help, Edit, and Delete horizontal box
|
# Help, Edit, and Delete horizontal box
|
||||||
hed_box = gtk.HButtonBox()
|
hed_box = gtk.HButtonBox()
|
||||||
@ -486,7 +486,7 @@ class EditExifMetadata(Gramplet):
|
|||||||
self.deactivate_buttons(["All"])
|
self.deactivate_buttons(["All"])
|
||||||
|
|
||||||
db = self.dbstate.db
|
db = self.dbstate.db
|
||||||
imagefntype_ = []
|
imgtype_format = []
|
||||||
|
|
||||||
# display all button tooltips only...
|
# display all button tooltips only...
|
||||||
# 1st argument is for Fields, 2nd argument is for Buttons...
|
# 1st argument is for Fields, 2nd argument is for Buttons...
|
||||||
@ -526,9 +526,6 @@ class EditExifMetadata(Gramplet):
|
|||||||
self.exif_widgets["MimeType"].set_text("%s, %s" % (
|
self.exif_widgets["MimeType"].set_text("%s, %s" % (
|
||||||
mime_type, gen.mime.get_description(mime_type) ) )
|
mime_type, gen.mime.get_description(mime_type) ) )
|
||||||
|
|
||||||
# get dirpath/ basename, and extension...
|
|
||||||
self._filepath_fname, self.extension = os.path.splitext(self.image_path)
|
|
||||||
|
|
||||||
# check image read privileges...
|
# check image read privileges...
|
||||||
_readable = os.access(self.image_path, os.R_OK)
|
_readable = os.access(self.image_path, os.R_OK)
|
||||||
if not _readable:
|
if not _readable:
|
||||||
@ -543,18 +540,20 @@ class EditExifMetadata(Gramplet):
|
|||||||
"You will NOT be able to save Exif metadata...."))
|
"You will NOT be able to save Exif metadata...."))
|
||||||
self.deactivate_buttons(["Edit"])
|
self.deactivate_buttons(["Edit"])
|
||||||
|
|
||||||
|
# get dirpath/ basename, and extension...
|
||||||
|
self.basename, self.extension = os.path.splitext(self.image_path)
|
||||||
|
|
||||||
# if image file type is not an Exiv2 acceptable image type, offer to convert it....
|
# if image file type is not an Exiv2 acceptable image type, offer to convert it....
|
||||||
if self.extension not in _VALIDIMAGEMAP.values():
|
if self.extension not in _VALIDIMAGEMAP.values():
|
||||||
self.activate_buttons(["ImageType"])
|
|
||||||
|
|
||||||
imagefntype_ = _validconvert
|
imgtype_format = _validconvert
|
||||||
if self.extension in imagefntype_:
|
self._VCONVERTMAP = dict( (index, imgtype) for index, imgtype in enumerate(imgtype_format) )
|
||||||
imagefntype_.remove(self.extension)
|
|
||||||
self._VCONVERTMAP = dict( (index, imgtype) for index, imgtype in enumerate(imagefntype_) )
|
|
||||||
|
|
||||||
for imgtype in self._VCONVERTMAP.values():
|
for index in xrange(1, len(imgtype_format) ):
|
||||||
self.exif_widgets["ImageType"].append_text(imgtype)
|
self.exif_widgets["ImageTypes"].append_text(imgtype_format[index] )
|
||||||
self.exif_widgets["ImageType"].set_active(0)
|
self.exif_widgets["ImageTypes"].set_active(0)
|
||||||
|
|
||||||
|
self.activate_buttons(["ImageTypes"])
|
||||||
else:
|
else:
|
||||||
self.activate_buttons(["Edit"])
|
self.activate_buttons(["Edit"])
|
||||||
|
|
||||||
@ -688,7 +687,7 @@ class EditExifMetadata(Gramplet):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# get convert image type and check it?
|
# get convert image type and check it?
|
||||||
ext_value = self.exif_widgets["ImageType"].get_active()
|
ext_value = self.exif_widgets["ImageTypes"].get_active()
|
||||||
if (self.extension not in _VALIDIMAGEMAP.values() and ext_value >= 1):
|
if (self.extension not in _VALIDIMAGEMAP.values() and ext_value >= 1):
|
||||||
|
|
||||||
# if Convert button is not active, set it to active state
|
# if Convert button is not active, set it to active state
|
||||||
@ -927,10 +926,10 @@ class EditExifMetadata(Gramplet):
|
|||||||
full_path = self.image_path
|
full_path = self.image_path
|
||||||
|
|
||||||
# get image filepath and its filename...
|
# get image filepath and its filename...
|
||||||
filepath, basename = os.path.split(self._filepath_fname)
|
filepath, basename = os.path.split(self.basename)
|
||||||
|
|
||||||
# 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["ImageTypes"].get_active()
|
||||||
if ext_type >= 1:
|
if ext_type >= 1:
|
||||||
basename += self._VCONVERTMAP[ext_type]
|
basename += self._VCONVERTMAP[ext_type]
|
||||||
|
|
||||||
@ -941,7 +940,7 @@ class EditExifMetadata(Gramplet):
|
|||||||
im = Image.open(full_path)
|
im = Image.open(full_path)
|
||||||
im.save(dest_file)
|
im.save(dest_file)
|
||||||
|
|
||||||
# identify pyexiv2 source image file...
|
# pyexiv2 source image file...
|
||||||
if OLD_API: # prior to pyexiv2-0.2.0...
|
if OLD_API: # prior to pyexiv2-0.2.0...
|
||||||
src_meta = pyexiv2.Image(full_path)
|
src_meta = pyexiv2.Image(full_path)
|
||||||
src_meta.readMetadata()
|
src_meta.readMetadata()
|
||||||
@ -952,7 +951,7 @@ class EditExifMetadata(Gramplet):
|
|||||||
# check to see if source image file has any Exif metadata?
|
# check to see if source image file has any Exif metadata?
|
||||||
if _get_exif_keypairs(src_meta):
|
if _get_exif_keypairs(src_meta):
|
||||||
|
|
||||||
if OLD_API:
|
if OLD_API: # prior to pyexiv2-0.2.0
|
||||||
# Identify the destination image file...
|
# Identify the destination image file...
|
||||||
dest_meta = pyexiv2.Image(dest_file)
|
dest_meta = pyexiv2.Image(dest_file)
|
||||||
dest_meta.readMetadata()
|
dest_meta.readMetadata()
|
||||||
@ -969,7 +968,9 @@ class EditExifMetadata(Gramplet):
|
|||||||
src_meta.copy(dest_meta, comment =False)
|
src_meta.copy(dest_meta, comment =False)
|
||||||
dest_meta.write()
|
dest_meta.write()
|
||||||
|
|
||||||
return dest_file
|
return dest_file
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
def __convert_delete(self, full_path =None):
|
def __convert_delete(self, full_path =None):
|
||||||
"""
|
"""
|
||||||
@ -989,20 +990,19 @@ class EditExifMetadata(Gramplet):
|
|||||||
delete_results = True
|
delete_results = True
|
||||||
except (IOError, OSError):
|
except (IOError, OSError):
|
||||||
delete_results = False
|
delete_results = False
|
||||||
|
|
||||||
if delete_results:
|
if delete_results:
|
||||||
|
|
||||||
# check for new destination and if source image file is removed?
|
# check for new destination and if source image file is removed?
|
||||||
if (os.path.isfile(newfilepath) and not os.path.isfile(full_path) ):
|
if (os.path.isfile(newfilepath) and not os.path.isfile(full_path) ):
|
||||||
self.__update_media_path(newfilepath)
|
self.__update_media_path(newfilepath)
|
||||||
|
|
||||||
|
# notify user about the convert, delete, and new filepath...
|
||||||
|
self.exif_widgets["MessageArea"].set_text(_("Your image has been "
|
||||||
|
"converted and the original file has been deleted, and "
|
||||||
|
"the full path has been updated!"))
|
||||||
else:
|
else:
|
||||||
self.exif_widgets["MessageArea"].set_text(_("There has been an error, "
|
self.exif_widgets["MessageArea"].set_text(_("There has been an error, "
|
||||||
"Please check your source and destination file paths..."))
|
"Please check your source and destination file paths..."))
|
||||||
|
|
||||||
# notify user about the convert, delete, and new filepath...
|
|
||||||
self.exif_widgets["MessageArea"].set_text(_("Your image has been "
|
|
||||||
"converted and the original file has been deleted, and "
|
|
||||||
"the full path has been updated!"))
|
|
||||||
else:
|
else:
|
||||||
self.exif_widgets["MessageArea"].set_text(_("There was an error in "
|
self.exif_widgets["MessageArea"].set_text(_("There was an error in "
|
||||||
"deleting the original file. You will need to delete it yourself!"))
|
"deleting the original file. You will need to delete it yourself!"))
|
||||||
|
Loading…
Reference in New Issue
Block a user