Fixed problems in converting files. Fixed problem when a user would convert an image and then double same image after it was converted. Adjusted sizes of the event boxes of Thumbnail, ImageType, and Convert Buttons.
svn: r17878
This commit is contained in:
parent
29e5f4a326
commit
0f735d1941
@ -293,14 +293,14 @@ class EditExifMetadata(Gramplet):
|
|||||||
# Separator line before the buttons...
|
# Separator line before the buttons...
|
||||||
main_vbox.pack_start(gtk.HSeparator(), expand =False, fill =False, padding =2)
|
main_vbox.pack_start(gtk.HSeparator(), expand =False, fill =False, padding =2)
|
||||||
|
|
||||||
# Thumbnail, ImageType, and Convert horizontal box...
|
# Thumbnail, ImageType, and Convert buttons...
|
||||||
new_hbox = gtk.HBox()
|
new_hbox = gtk.HBox()
|
||||||
main_vbox.pack_start(new_hbox, expand =False, fill =False, padding =0)
|
main_vbox.pack_start(new_hbox, expand =False, fill =False, padding =0)
|
||||||
new_hbox.show()
|
new_hbox.show()
|
||||||
|
|
||||||
# Thumbnail button...
|
# Thumbnail button...
|
||||||
event_box = gtk.EventBox()
|
event_box = gtk.EventBox()
|
||||||
event_box.set_size_request(90, 35)
|
event_box.set_size_request(90, 30)
|
||||||
new_hbox.pack_start(event_box, expand =False, fill =False, padding =0)
|
new_hbox.pack_start(event_box, expand =False, fill =False, padding =0)
|
||||||
event_box.show()
|
event_box.show()
|
||||||
|
|
||||||
@ -311,7 +311,7 @@ class EditExifMetadata(Gramplet):
|
|||||||
|
|
||||||
# Image Type...
|
# Image Type...
|
||||||
event_box = gtk.EventBox()
|
event_box = gtk.EventBox()
|
||||||
event_box.set_size_request(165, 35)
|
event_box.set_size_request(160, 30)
|
||||||
new_hbox.pack_start(event_box, expand =False, fill =False, padding =0)
|
new_hbox.pack_start(event_box, expand =False, fill =False, padding =0)
|
||||||
self.exif_widgets["ImageTypeBox"] = event_box
|
self.exif_widgets["ImageTypeBox"] = event_box
|
||||||
event_box.show()
|
event_box.show()
|
||||||
@ -325,7 +325,7 @@ class EditExifMetadata(Gramplet):
|
|||||||
|
|
||||||
# Convert button...
|
# Convert button...
|
||||||
event_box = gtk.EventBox()
|
event_box = gtk.EventBox()
|
||||||
event_box.set_size_request(100, 35)
|
event_box.set_size_request(100, 30)
|
||||||
new_hbox.pack_start(event_box, expand =False, fill =False, padding =0)
|
new_hbox.pack_start(event_box, expand =False, fill =False, padding =0)
|
||||||
event_box.show()
|
event_box.show()
|
||||||
|
|
||||||
@ -455,39 +455,39 @@ class EditExifMetadata(Gramplet):
|
|||||||
|
|
||||||
# creates, and reads the plugin image instance...
|
# creates, and reads the plugin image instance...
|
||||||
self.plugin_image = self.setup_image(self.image_path)
|
self.plugin_image = self.setup_image(self.image_path)
|
||||||
|
if self.plugin_image:
|
||||||
|
|
||||||
if LesserVersion: # prior to pyexiv2-0.2.0
|
if LesserVersion: # prior to pyexiv2-0.2.0
|
||||||
try:
|
try:
|
||||||
ttype, tdata = self.plugin_image.getThumbnailData()
|
ttype, tdata = self.plugin_image.getThumbnailData()
|
||||||
width, height = tdata.dimensions
|
width, height = tdata.dimensions
|
||||||
thumbnail = True
|
thumbnail = True
|
||||||
except (IOError, OSError):
|
except (IOError, OSError):
|
||||||
thumbnail = False
|
|
||||||
|
|
||||||
else: # pyexiv2-0.2.0 and above
|
|
||||||
try:
|
|
||||||
previews = self.plugin_image.previews
|
|
||||||
thumbnail = True
|
|
||||||
if not previews:
|
|
||||||
thumbnail = False
|
thumbnail = False
|
||||||
except (IOError, OSError):
|
|
||||||
thumbnail = False
|
|
||||||
|
|
||||||
# if a thumbnail exists, then activate the buttton?
|
else: # pyexiv2-0.2.0 and above
|
||||||
if thumbnail:
|
try:
|
||||||
self.activate_buttons(["Thumbnail"])
|
previews = self.plugin_image.previews
|
||||||
|
thumbnail = True
|
||||||
|
if not previews:
|
||||||
|
thumbnail = False
|
||||||
|
except (IOError, OSError):
|
||||||
|
thumbnail = False
|
||||||
|
|
||||||
# Activate the Edit button...
|
# if a thumbnail exists, then activate the buttton?
|
||||||
self.activate_buttons(["Edit"])
|
if thumbnail:
|
||||||
|
self.activate_buttons(["Thumbnail"])
|
||||||
|
|
||||||
# display all exif metadata...
|
# Activate the Edit button...
|
||||||
mediadatatags = _get_exif_keypairs(self.plugin_image)
|
self.activate_buttons(["Edit"])
|
||||||
if mediadatatags:
|
|
||||||
self.display_metadata(mediadatatags)
|
|
||||||
|
|
||||||
else:
|
# display all exif metadata...
|
||||||
# set Message Area to None...
|
mediadatatags = _get_exif_keypairs(self.plugin_image)
|
||||||
self.exif_widgets["MessageArea"].set_text(_("No Exif metadata for this image..."))
|
if mediadatatags:
|
||||||
|
self.display_metadata(mediadatatags)
|
||||||
|
else:
|
||||||
|
# set Message Area to None...
|
||||||
|
self.exif_widgets["MessageArea"].set_text(_("No Exif metadata for this image..."))
|
||||||
|
|
||||||
# has mime, but not an image...
|
# has mime, but not an image...
|
||||||
else:
|
else:
|
||||||
@ -505,8 +505,12 @@ class EditExifMetadata(Gramplet):
|
|||||||
image extension is not an Exiv2- compatible image?
|
image extension is not an Exiv2- compatible image?
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if self.extension not in _VTYPEMAP.values():
|
# get convert image type and check it?
|
||||||
|
ext_value = self.exif_widgets["ImageType"].get_active()
|
||||||
|
if (self.extension not in _VTYPEMAP.values() and ext_value >= 1):
|
||||||
|
|
||||||
|
# if Convert button is not active, set it to active state
|
||||||
|
# so that the user may convert this image?
|
||||||
if not self.exif_widgets["Convert"].get_sensitive():
|
if not self.exif_widgets["Convert"].get_sensitive():
|
||||||
self.activate_buttons(["Convert"])
|
self.activate_buttons(["Convert"])
|
||||||
|
|
||||||
@ -797,13 +801,12 @@ class EditExifMetadata(Gramplet):
|
|||||||
Handles the Convert question Dialog...
|
Handles the Convert question Dialog...
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Convert and delete original file...
|
# Convert and delete original file or just convert...
|
||||||
if EXIV2_FOUND_:
|
OptionDialog(_("Edit Image Exif Metadata"), _("WARNING: You are about to convert this "
|
||||||
OptionDialog(_("Edit Image Exif Metadata"), _("WARNING: You are about to convert this "
|
"image into a .jpeg image. Are you sure that you want to do this?"),
|
||||||
"image into a .jpeg image. Are you sure that you want to do this?"),
|
_("Convert and Delete"), self.__convert_delete, _("Convert"), self.__convert_only)
|
||||||
_("Convert and Delete"), self.__convert_delete, _("Convert"), self.__convert_file)
|
|
||||||
|
|
||||||
def __convert_file(self, full_path =None):
|
def __convert_copy(self, full_path =None):
|
||||||
"""
|
"""
|
||||||
Will attempt to convert an image to jpeg if it is not?
|
Will attempt to convert an image to jpeg if it is not?
|
||||||
"""
|
"""
|
||||||
@ -816,41 +819,43 @@ 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()
|
||||||
print(ext_type, self._VCONVERTMAP)
|
|
||||||
if ext_type >= 1:
|
if ext_type >= 1:
|
||||||
basename += self._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 image file suffix...
|
# open source image file...
|
||||||
i = Image.open(full_path)
|
im = Image.open(full_path)
|
||||||
if i.mode == "RGB":
|
im.save(dest_file)
|
||||||
im = i.filter(ImageFilter.SHARPEN)
|
|
||||||
i1 = im.filter(ImageFilter.DETAIL)
|
|
||||||
i1.save(dest_file)
|
|
||||||
else:
|
|
||||||
i.save(dest_file)
|
|
||||||
|
|
||||||
|
# identify pyexiv2 source image 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)
|
||||||
|
|
||||||
# Copy the image metadata...
|
|
||||||
dest_meta = pyexiv2.Image(dest_file)
|
|
||||||
dest_meta.readMetadata()
|
|
||||||
src_meta.readMetadata()
|
src_meta.readMetadata()
|
||||||
src_meta.copy(dest_meta, comment =False)
|
else:
|
||||||
dest_meta.writeMetadata()
|
|
||||||
|
|
||||||
else: # pyexiv2-0.2.0 and above...
|
|
||||||
src_meta = pyexiv2.ImageMetadata(full_path)
|
src_meta = pyexiv2.ImageMetadata(full_path)
|
||||||
|
|
||||||
# Copy the image metadata...
|
|
||||||
dest_meta = pyexiv2.ImageMetadata(dest_file)
|
|
||||||
src_meta.read()
|
src_meta.read()
|
||||||
dest_meta.read()
|
|
||||||
src_meta.copy(dest_meta, comment =False)
|
# check to see if source image file has any Exif metadata?
|
||||||
dest_meta.write()
|
if _get_exif_keypairs(src_meta):
|
||||||
|
|
||||||
|
if LesserVersion:
|
||||||
|
# Identify the destination image file...
|
||||||
|
dest_meta = pyexiv2.Image(dest_file)
|
||||||
|
dest_meta.readMetadata()
|
||||||
|
|
||||||
|
# copy source metadata to destination file...
|
||||||
|
src_meta.copy(dest_meta, comment =False)
|
||||||
|
dest_meta.writeMetadata()
|
||||||
|
else: # pyexiv2-0.2.0 and above...
|
||||||
|
# Identify the destination image file...
|
||||||
|
dest_meta = pyexiv2.ImageMetadata(dest_file)
|
||||||
|
dest_meta.read()
|
||||||
|
|
||||||
|
# copy source metadata to destination file...
|
||||||
|
src_meta.copy(dest_meta, comment =False)
|
||||||
|
dest_meta.write()
|
||||||
|
|
||||||
return dest_file
|
return dest_file
|
||||||
|
|
||||||
@ -858,41 +863,76 @@ class EditExifMetadata(Gramplet):
|
|||||||
"""
|
"""
|
||||||
will convert an image file and delete original non-jpeg image.
|
will convert an image file and delete original non-jpeg image.
|
||||||
"""
|
"""
|
||||||
db = self.dbstate.db
|
|
||||||
|
|
||||||
if full_path is None:
|
if full_path is None:
|
||||||
full_path = self.image_path
|
full_path = self.image_path
|
||||||
|
|
||||||
# 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_copy(full_path)
|
||||||
|
if newfilepath:
|
||||||
|
|
||||||
# delete original file from this computer and set new filepath...
|
# 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):
|
||||||
|
delete_results = False
|
||||||
|
|
||||||
except (IOError, OSError):
|
if delete_results:
|
||||||
delete_results = False
|
|
||||||
|
|
||||||
if delete_results:
|
# check for new destination and if source image file is removed?
|
||||||
|
if (os.path.isfile(newfilepath) and not os.path.isfile(full_path) ):
|
||||||
# update media object path...
|
self.update_media_path(newfilepath)
|
||||||
if (newfilepath is not False and os.path.isfile(newfilepath) ):
|
else:
|
||||||
|
self.exif_widgets["MessageArea"].set_text(_("There has been an error, "
|
||||||
# begin database tranaction to save media object new path...
|
"Please check your source and destination file paths..."))
|
||||||
with DbTxn(_("Media Path Update"), db) as trans:
|
|
||||||
self.orig_image.set_path(newfilepath)
|
|
||||||
|
|
||||||
db.disable_signals()
|
|
||||||
db.commit_media_object(self.orig_image, trans)
|
|
||||||
|
|
||||||
db.enable_signals()
|
|
||||||
db.request_rebuild()
|
|
||||||
|
|
||||||
# notify user about the convert, delete, and new filepath...
|
# 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, and "
|
"converted and the original file has been deleted, and "
|
||||||
"the full path has been updated!"))
|
"the full path has been updated!"))
|
||||||
|
else:
|
||||||
|
self.exif_widgets["MessageArea"].set_text(_("There was an error in "
|
||||||
|
"deleting the original file. You will need to delete it yourself!"))
|
||||||
|
|
||||||
|
def __convert_only(self, object):
|
||||||
|
"""
|
||||||
|
This will only convert the file and update the media object path.
|
||||||
|
"""
|
||||||
|
|
||||||
|
newfilepath = self.__convert_copy(self.image_path)
|
||||||
|
|
||||||
|
# the convert was sucessful, then update media path?
|
||||||
|
if newfilepath:
|
||||||
|
|
||||||
|
# update the media object path...
|
||||||
|
self.update_media_path(newfilepath)
|
||||||
|
else:
|
||||||
|
self.exif_widgets["MessageArea"].set_text(_("There was an error "
|
||||||
|
"in converting your image file."))
|
||||||
|
return
|
||||||
|
|
||||||
|
def update_media_path(self, newfilepath):
|
||||||
|
"""
|
||||||
|
update the media object's media path.
|
||||||
|
"""
|
||||||
|
|
||||||
|
if newfilepath:
|
||||||
|
db = self.dbstate.db
|
||||||
|
|
||||||
|
# begin database tranaction to save media object new path...
|
||||||
|
with DbTxn(_("Media Path Update"), db) as trans:
|
||||||
|
self.orig_image.set_path(newfilepath)
|
||||||
|
|
||||||
|
db.disable_signals()
|
||||||
|
db.commit_media_object(self.orig_image, trans)
|
||||||
|
|
||||||
|
db.enable_signals()
|
||||||
|
db.request_rebuild()
|
||||||
|
else:
|
||||||
|
self.exif_widgets["MessageArea"].set_text(_("There has been an "
|
||||||
|
"error in updating the image file path."))
|
||||||
|
return
|
||||||
|
|
||||||
def __help_page(self, object):
|
def __help_page(self, object):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user