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:
Rob G. Healey 2011-07-01 05:25:11 +00:00
parent 29e5f4a326
commit 0f735d1941

View File

@ -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,6 +455,7 @@ 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:
@ -484,7 +485,6 @@ class EditExifMetadata(Gramplet):
mediadatatags = _get_exif_keypairs(self.plugin_image) mediadatatags = _get_exif_keypairs(self.plugin_image)
if mediadatatags: if mediadatatags:
self.display_metadata(mediadatatags) self.display_metadata(mediadatatags)
else: else:
# set Message Area to None... # set Message Area to None...
self.exif_widgets["MessageArea"].set_text(_("No Exif metadata for this image...")) self.exif_widgets["MessageArea"].set_text(_("No Exif metadata for this image..."))
@ -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_file) _("Convert and Delete"), self.__convert_delete, _("Convert"), self.__convert_only)
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,39 +819,41 @@ 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)
src_meta.readMetadata()
else:
src_meta = pyexiv2.ImageMetadata(full_path)
src_meta.read()
# Copy the image metadata... # check to see if source image file has any Exif metadata?
if _get_exif_keypairs(src_meta):
if LesserVersion:
# Identify the destination image file...
dest_meta = pyexiv2.Image(dest_file) dest_meta = pyexiv2.Image(dest_file)
dest_meta.readMetadata() dest_meta.readMetadata()
src_meta.readMetadata()
# copy source metadata to destination file...
src_meta.copy(dest_meta, comment =False) src_meta.copy(dest_meta, comment =False)
dest_meta.writeMetadata() dest_meta.writeMetadata()
else: # pyexiv2-0.2.0 and above... else: # pyexiv2-0.2.0 and above...
src_meta = pyexiv2.ImageMetadata(full_path) # Identify the destination image file...
# Copy the image metadata...
dest_meta = pyexiv2.ImageMetadata(dest_file) dest_meta = pyexiv2.ImageMetadata(dest_file)
src_meta.read()
dest_meta.read() dest_meta.read()
# copy source metadata to destination file...
src_meta.copy(dest_meta, comment =False) src_meta.copy(dest_meta, comment =False)
dest_meta.write() dest_meta.write()
@ -858,26 +863,62 @@ 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): except (IOError, OSError):
delete_results = False delete_results = False
if delete_results: if delete_results:
# update media object path... # check for new destination and if source image file is removed?
if (newfilepath is not False and os.path.isfile(newfilepath) ): if (os.path.isfile(newfilepath) and not os.path.isfile(full_path) ):
self.update_media_path(newfilepath)
else:
self.exif_widgets["MessageArea"].set_text(_("There has been an error, "
"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:
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... # 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:
@ -888,11 +929,10 @@ class EditExifMetadata(Gramplet):
db.enable_signals() db.enable_signals()
db.request_rebuild() db.request_rebuild()
else:
# notify user about the convert, delete, and new filepath... self.exif_widgets["MessageArea"].set_text(_("There has been an "
self.exif_widgets["MessageArea"].set_text(_("Your image has been " "error in updating the image file path."))
"converted and the original file has been deleted, and " return
"the full path has been updated!"))
def __help_page(self, object): def __help_page(self, object):
""" """