Fixed the 'changed' signal for data fields.

svn: r17494
This commit is contained in:
Rob G. Healey 2011-05-14 04:09:11 +00:00
parent c2ea9089e0
commit 9e43103fd5

View File

@ -277,7 +277,6 @@ class EditExifMetadata(Gramplet):
self.orig_image = False self.orig_image = False
self.image_path = False self.image_path = False
self.plugin_image = False self.plugin_image = False
self.MediaDataTags = False
vbox = self.build_gui() vbox = self.build_gui()
self.connect_signal("Media", self.update) self.connect_signal("Media", self.update)
@ -393,7 +392,7 @@ class EditExifMetadata(Gramplet):
if _MAGICK_FOUND: if _MAGICK_FOUND:
# Delete All Metadata button... # Delete All Metadata button...
hasd_box.add(self.__create_button( hasd_box.add(self.__create_button(
"Delete", False, [self.__delete_dialog], gtk.STOCK_DELETE ) ) "Delete", False, [self.__wipe_dialog], gtk.STOCK_DELETE ) )
return vbox return vbox
@ -470,13 +469,28 @@ class EditExifMetadata(Gramplet):
for ButtonName in ButtonList: for ButtonName in ButtonList:
self.exif_widgets[ButtonName].set_sensitive(False) self.exif_widgets[ButtonName].set_sensitive(False)
def activate_save(self, obj):
"""
will handle the toggle action of the Save button.
If there is no Exif metadata, then the data fields are connected to the
'changed' signal to be able to activate the Save button once data has been entered
into the data fields...
"""
if not self.exif_widgets["Save"].get_sensitive():
self.activate_buttons(["Save"])
# set Message Area to Entering Data...
self.exif_widgets["Message:Area"].set_text(_("Entering data..."))
def main(self): # return false finishes def main(self): # return false finishes
""" """
get the active media, mime type, and reads the image metadata get the active media, mime type, and reads the image metadata
""" """
db = self.dbstate.db db = self.dbstate.db
# clear Edit Areas # clear Edit Area and Labels...
self.clear_metadata(self.orig_image) self.clear_metadata(self.orig_image)
# De-activate the buttons except for Help and Clear... # De-activate the buttons except for Help and Clear...
@ -503,14 +517,14 @@ class EditExifMetadata(Gramplet):
self.image_path = Utils.media_path_full(db, self.orig_image.get_path() ) self.image_path = Utils.media_path_full(db, self.orig_image.get_path() )
if (not self.orig_image or not os.path.isfile(self.image_path)): if (not self.orig_image or not os.path.isfile(self.image_path)):
self.exif_widgets["Message:Area"].set_text(_("Image is either missing or deleted,\n" self.exif_widgets["Message:Area"].set_text(_("Image is either missing or deleted,\n"
"Choose a different image...")) "Please choose a different image..."))
return return
# 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:
self.exif_widgets["Message:Area"].set_text(_("Image is NOT readable,\n" self.exif_widgets["Message:Area"].set_text(_("Image is NOT readable,\n"
"Choose a different image...")) "Please choose a different image..."))
return return
# check image write privileges... # check image write privileges...
@ -519,43 +533,38 @@ class EditExifMetadata(Gramplet):
self.exif_widgets["Message:Area"].set_text(_("Image is NOT writable,\n" self.exif_widgets["Message:Area"].set_text(_("Image is NOT writable,\n"
"You will NOT be able to save Exif metadata....")) "You will NOT be able to save Exif metadata...."))
# Mime type information...
mime_type = self.orig_image.get_mime_type()
_mtype = gen.mime.get_description(mime_type)
self.exif_widgets["Mime:Type"].set_text(_mtype)
# display file description/ title... # display file description/ title...
self.exif_widgets["Media:Label"].set_text(_html_escape( self.exif_widgets["Media:Label"].set_text(_html_escape(
self.orig_image.get_description() ) ) self.orig_image.get_description() ) )
# Mime type information...
mime_type = self.orig_image.get_mime_type()
self.exif_widgets["Mime:Type"].set_text(mime_type)
# disable all data fields and buttons if NOT an exiv2 image type?
basename, self.extension = os.path.splitext(self.image_path)
_setup_datafields_buttons(self.extension, self.exif_widgets)
# determine if it is a mime image object? # determine if it is a mime image object?
goodmime = False
basename, extension = os.path.splitext(self.image_path)
# disable all data fields and buttons if NOT an exiv2 image type?
_setup_datafields_buttons(extension, self.exif_widgets)
if mime_type: if mime_type:
if mime_type.startswith("image"): if mime_type.startswith("image"):
self.activate_buttons(["Save"])
# Checks to make sure that ImageMagick is installed on this computer and # Checks to make sure that ImageMagick is installed on this computer and
# the image is NOT a (".jpeg", ".jfif", or ".jpg") image... # the image is NOT a (".jpeg", ".jfif", or ".jpg") image...
if _MAGICK_FOUND: # if not, then activate the Convert button?
if (_MAGICK_FOUND and self.extension not in [".jpeg", ".jpg", ".jfif"] ):
self.activate_buttons(["Convert"])
# check to make sure that the image is not a jpeg image? # setup widget tooltips for all fields and buttons...
# if not, then activate the Convert button...
if extension not in [".jpeg", ".jpg", ".jfif"]:
self.activate_buttons(["Convert"])
# setup widget tooltips for explanations...
_setup_widget_tips(self.exif_widgets) _setup_widget_tips(self.exif_widgets)
# creates, reads, and get all Exif metadata # 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)
# Retries all metadata key pairs from image... # Check for Thumbnails...
self.MediaDataTags = _get_exif_keypairs(self.plugin_image) previews = self.plugin_image.previews
if (len(previews) > 0):
self.activate_buttons(["ThumbnailView"])
# displays the imge Exif metadata into selected data fields... # displays the imge Exif metadata into selected data fields...
self.EditArea(self.orig_image) self.EditArea(self.orig_image)
@ -575,7 +584,7 @@ class EditExifMetadata(Gramplet):
# if ImageMagick and delete has been found on this computer? # if ImageMagick and delete has been found on this computer?
if (_MAGICK_FOUND and _DEL_FOUND): if (_MAGICK_FOUND and _DEL_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 .jpg 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 original"), self.convertdelete, _("Convert and Delete original"), self.convertdelete,
_("Convert"), self.convert2Jpeg) _("Convert"), self.convert2Jpeg)
@ -593,7 +602,7 @@ class EditExifMetadata(Gramplet):
QuestionDialog(_("Edit Image Exif Metadata"), _("Save Exif metadata to this image?"), QuestionDialog(_("Edit Image Exif Metadata"), _("Save Exif metadata to this image?"),
_("Save"), self.save_metadata) _("Save"), self.save_metadata)
def __delete_dialog(self, obj): def __wipe_dialog(self, obj):
""" """
Handles the Delete Dialog... Handles the Delete Dialog...
""" """
@ -610,19 +619,16 @@ class EditExifMetadata(Gramplet):
* setup the tooltips for the buttons, * setup the tooltips for the buttons,
""" """
if LesserVersion: if LesserVersion: # prior to pyexiv2-0.2.0
metadata = pyexiv2.Image(full_path) metadata = pyexiv2.Image(full_path)
else:
metadata = pyexiv2.ImageMetadata(full_path)
if LesserVersion:
try: try:
metadata.readMetadata() metadata.readMetadata()
except (IOError, OSError): except (IOError, OSError):
self.set_has_data(False) self.set_has_data(False)
return return
else: else: # pyexiv2-0.2.0 and above
metadata = pyexiv2.ImageMetadata(full_path)
try: try:
metadata.read() metadata.read()
except (IOError, OSError): except (IOError, OSError):
@ -727,7 +733,7 @@ class EditExifMetadata(Gramplet):
# clear all data fields # clear all data fields
if cleartype == "All": if cleartype == "All":
for widgetsName in ["Description", "Modified", "Artist", "Copyright", for widgetsName in ["Description", "Modified", "Artist", "Copyright",
"DateTime", "Latitude", "Longitude"]: "DateTime", "Latitude", "Longitude", "Media:Label", "Mime:Type", "Message:Area"]:
self.exif_widgets[widgetsName].set_text("") self.exif_widgets[widgetsName].set_text("")
# clear only the date/ time field # clear only the date/ time field
@ -740,23 +746,21 @@ class EditExifMetadata(Gramplet):
reads the image metadata after the pyexiv2.Image has been created reads the image metadata after the pyexiv2.Image has been created
""" """
# activate Clear button... # Retrieves all metadata key pairs from this image...
self.activate_buttons(["Clear"]) MediaDataTags = _get_exif_keypairs(self.plugin_image)
# if no exif metadata, disable the has_data functionality? # if no exif metadata, disable the has_data() functionality?
self.set_has_data(True) if MediaDataTags:
if not self.MediaDataTags: self.set_has_data(True)
self.set_has_data(False)
# Activate Delete button if ImageMagick or jhead is found?... # Activate Delete button if ImageMagick or jhead is found?...
if (_MAGICK_FOUND or _JHEAD_FOUND): if (_MAGICK_FOUND or _JHEAD_FOUND):
self.activate_buttons(["Delete"]) self.activate_buttons(["Delete"])
imageKeyTags = [KeyTag for KeyTag in self.MediaDataTags if KeyTag in _DATAMAP] imageKeyTags = [KeyTag for KeyTag in MediaDataTags if KeyTag in _DATAMAP]
if imageKeyTags:
# activate AdvancedView button... # activate AdvancedView and Save buttons...
self.activate_buttons(["AdvancedView"]) self.activate_buttons(["AdvancedView", "Save"])
# set Message Area to Copying... # set Message Area to Copying...
self.exif_widgets["Message:Area"].set_text(_("Copying Exif metadata to the Edit Area...")) self.exif_widgets["Message:Area"].set_text(_("Copying Exif metadata to the Edit Area..."))
@ -787,12 +791,12 @@ class EditExifMetadata(Gramplet):
elif widgetsName == "Latitude": elif widgetsName == "Latitude":
latitude = self._get_value(KeyTag) latitude = self._get_value(KeyTag)
longitude = self._get_value(_DATAMAP["Longitude"] ) longitude = self._get_value(_DATAMAP["Longitude"])
# if latitude and longitude exist, display them? # if latitude and longitude exist, display them?
if (latitude and longitude): if (latitude and longitude):
# split latitude metadata into (degrees, minutes, and seconds) from Rational # split latitude metadata into (degrees, minutes, and seconds)
latdeg, latmin, latsec = rational_to_dms(latitude) latdeg, latmin, latsec = rational_to_dms(latitude)
# split longitude metadata into degrees, minutes, and seconds # split longitude metadata into degrees, minutes, and seconds
@ -804,23 +808,27 @@ class EditExifMetadata(Gramplet):
if (not latfail and not longfail): if (not latfail and not longfail):
# Latitude Direction Reference # Latitude Direction Reference
LatitudeRef = self._get_value(_DATAMAP["LatitudeRef"] ) LatRef = self._get_value(_DATAMAP["LatitudeRef"] )
# Longitude Direction Reference # Longitude Direction Reference
LongitudeRef = self._get_value(_DATAMAP["LongitudeRef"] ) LongRef = self._get_value(_DATAMAP["LongitudeRef"] )
# set display for Latitude GPS Coordinates # set display for Latitude GPS Coordinates
self.exif_widgets["Latitude"].set_text( self.exif_widgets["Latitude"].set_text(
"""%s° %s %s%s""" % (latdeg, latmin, latsec, LatitudeRef) ) """%s° %s %s%s""" % (latdeg, latmin, latsec, LatRef) )
# set display for Longitude GPS Coordinates # set display for Longitude GPS Coordinates
self.exif_widgets["Longitude"].set_text( self.exif_widgets["Longitude"].set_text(
"""%s° %s %s%s""" % (longdeg, longmin, longsec, LongitudeRef) ) """%s° %s %s%s""" % (longdeg, longmin, longsec, LongRef) )
# Check for Thumbnails... else:
previews = self.plugin_image.previews
if (len(previews) > 0): # set Message Area to None...
self.activate_buttons(["ThumbnailView"]) self.exif_widgets["Message:Area"].set_text(_("There is NO Exif metadata for this image yet..."))
for widget, tooltip in _TOOLTIPS:
if widget is not "Modified":
self.exif_widgets[widget].connect("changed", self.activate_save)
def convertdelete(self): def convertdelete(self):
""" """
@ -1058,16 +1066,10 @@ class EditExifMetadata(Gramplet):
advarea.show() advarea.show()
# Update the image Exif metadata... # Update the image Exif metadata...
self.MediaDataTags = _get_exif_keypairs(self.plugin_image) MediaDataTags = _get_exif_keypairs(self.plugin_image)
# update has_data() functionality...
if self.MediaDataTags:
self.set_has_data(True)
else:
self.set_has_data(False)
if LesserVersion: # prior to pyexiv2-0.2.0 if LesserVersion: # prior to pyexiv2-0.2.0
for KeyTag in self.MediaDataTags: for KeyTag in MediaDataTags:
label = self.plugin_image.tagDetails(KeyTag)[0] label = self.plugin_image.tagDetails(KeyTag)[0]
if KeyTag in ("Exif.Image.DateTime", if KeyTag in ("Exif.Image.DateTime",
"Exif.Photo.DateTimeOriginal", "Exif.Photo.DateTimeOriginal",
@ -1078,7 +1080,7 @@ class EditExifMetadata(Gramplet):
self.model.add((label, human_value)) self.model.add((label, human_value))
else: # pyexiv2-0.2.0 and above else: # pyexiv2-0.2.0 and above
for KeyTag in self.MediaDataTags: for KeyTag in MediaDataTags:
tag = self.plugin_image[KeyTag] tag = self.plugin_image[KeyTag]
if KeyTag in ("Exif.Image.DateTime", if KeyTag in ("Exif.Image.DateTime",
"Exif.Photo.DateTimeOriginal", "Exif.Photo.DateTimeOriginal",
@ -1220,13 +1222,21 @@ class EditExifMetadata(Gramplet):
Will completely and irrevocably erase all Exif metadata from this image. Will completely and irrevocably erase all Exif metadata from this image.
""" """
# update the image Exif metadata...
MediaDataTags = _get_exif_keypairs(self.plugin_image)
if not MediaDataTags:
return
if _MAGICK_FOUND: if _MAGICK_FOUND:
erase = subprocess.check_call( ["convert", self.image_path, "-strip", self.image_path] ) erase = subprocess.check_call( ["convert", self.image_path, "-strip", self.image_path] )
erase_results = str(erase) erase_results = str(erase)
elif (_JHEAD_FOUND and self.extension in [".jpeg", ".jfif", ".jpg"]):
erase = subprocess.check_call( ["jhead", "-purejpeg", self.image_path] )
else: else:
if self.MediaDataTags: if MediaDataTags:
for KeyTag in self.MediaDataTags: for KeyTag in MediaDataTags:
del self.plugin_image[KeyTag] del self.plugin_image[KeyTag]
erase_results = True erase_results = True
@ -1238,20 +1248,15 @@ class EditExifMetadata(Gramplet):
# set Message Area for deleting... # set Message Area for deleting...
self.exif_widgets["Message:Area"].set_text(_("Deleting all Exif metadata...")) self.exif_widgets["Message:Area"].set_text(_("Deleting all Exif metadata..."))
# Clear the Display and Edit Areas # Clear the Edit Areas
self.clear_metadata(self.plugin_image) self.clear_metadata(self.plugin_image)
self.model.clear()
# Notify the User... # set Message Area to Delete...
self.exif_widgets["Message:Area"].set_text(_("All Exif metadata has been " self.exif_widgets["Message:Area"].set_text(_("All Exif metadata has been "
"deleted from this image...")) "deleted from this image..."))
self.update() self.update()
# re- initialize the image...
if _JHEAD_FOUND:
reinit = subprocess.check_call( ["jhead", "-purejpg", self.image_path] )
def select_date(self, obj): def select_date(self, obj):
""" """
will allow you to choose a date from the calendar widget will allow you to choose a date from the calendar widget
@ -1334,10 +1339,11 @@ def _setup_datafields_buttons(extension, exif_widgets):
for widget, tooltip in _TOOLTIPS: for widget, tooltip in _TOOLTIPS:
if widget is not "Modified": if widget is not "Modified":
exif_widgets[widget].set_visibility(goodextension)
exif_widgets[widget].set_editable(goodextension) exif_widgets[widget].set_editable(goodextension)
for widget, tooltip in _BUTTONTIPS.items(): for widget, tooltip in _BUTTONTIPS.items():
if widget not in ["Help", "Clear"]: if (widget not in ["Help", "Clear"] and not goodextension):
exif_widgets[widget].set_sensitive(False) exif_widgets[widget].set_sensitive(False)
def _setup_widget_tips(exif_widgets): def _setup_widget_tips(exif_widgets):