Fixed errors in _format_datetime() to match corrections from Nick Hall. Removed 'Clear' button from the initial display, thanks Nick and Helge.

svn: r17711
This commit is contained in:
Rob G. Healey 2011-06-08 00:29:14 +00:00
parent deebab7a01
commit ba55888eff

View File

@ -151,10 +151,10 @@ _vtypes = [".jpeg", ".jpg", ".jfif", ".exv", ".tiff", ".dng", ".nef", ".pef", ".
_DATAMAP = { _DATAMAP = {
"Xmp.xmp.Label" : "ExifLabel", "Xmp.xmp.Label" : "ExifLabel",
"Exif.Image.ImageDescription" : "Description", "Exif.Image.ImageDescription" : "Description",
"Exif.Image.DateTime" : "Modified",
"Exif.Image.Artist" : "Artist", "Exif.Image.Artist" : "Artist",
"Exif.Image.Copyright" : "Copyright", "Exif.Image.Copyright" : "Copyright",
"Exif.Photo.DateTimeOriginal" : "Original", "Exif.Photo.DateTimeOriginal" : "Original",
"Exif.Image.DateTime" : "Modified",
"Exif.Photo.DateTimeDigitized" : "Digitized", "Exif.Photo.DateTimeDigitized" : "Digitized",
"Xmp.xmp.ModifyDate" : "ModifyDate", "Xmp.xmp.ModifyDate" : "ModifyDate",
"Exif.GPSInfo.GPSTimeStamp" : "gpsTimeStamp", "Exif.GPSInfo.GPSTimeStamp" : "gpsTimeStamp",
@ -168,7 +168,7 @@ _DATAMAP = dict((key, val) for key, val in _DATAMAP.items())
_DATAMAP.update( (val, key) for key, val in _DATAMAP.items()) _DATAMAP.update( (val, key) for key, val in _DATAMAP.items())
# define tooltips for all data entry fields... # define tooltips for all data entry fields...
_TOOLTIPS = { _DATATIPS = {
# Exif Label/ Title... # Exif Label/ Title...
"ExifLabel" : _("This is equivalent to the Title field in the media object editor."), "ExifLabel" : _("This is equivalent to the Title field in the media object editor."),
@ -176,6 +176,10 @@ _TOOLTIPS = {
# Description... # Description...
"Description" : _("Provide a short descripion for this image."), "Description" : _("Provide a short descripion for this image."),
# Last Change/ Modify Date/ Time...
"Modified" : _("This is the date/ time that the image was last changed/ modified.\n"
"Example: 2011-05-24 14:30:00"),
# Artist... # Artist...
"Artist" : _("Enter the Artist/ Author of this image. The person's name or " "Artist" : _("Enter the Artist/ Author of this image. The person's name or "
"the company who is responsible for the creation of this image."), "the company who is responsible for the creation of this image."),
@ -183,14 +187,10 @@ _TOOLTIPS = {
# Copyright... # Copyright...
"Copyright" : _("Enter the copyright information for this image. \n"), "Copyright" : _("Enter the copyright information for this image. \n"),
# Original Date/ Time of the image... # Original Date/ Time...
"Original" : _("The original date/ time when the image was first created/ taken as in a photograph.\n" "Original" : _("The original date/ time when the image was first created/ taken as in a photograph.\n"
"Example: 1830-01-1 09:30:59"), "Example: 1830-01-1 09:30:59"),
# Last Change/ Modify Date/ Time...
"Modified" : _("This is the date/ time that the image was last changed/ modified.\n"
"Example: 2011-05-24 14:30:00"),
# GPS Latitude Coordinates... # GPS Latitude Coordinates...
"Latitude" : _("Enter the Latitude GPS Coordinates for this image,\n" "Latitude" : _("Enter the Latitude GPS Coordinates for this image,\n"
"Example: 43.722965, 43 43 22 N, 38° 38 03″ N, 38 38 3"), "Example: 43.722965, 43 43 22 N, 38° 38 03″ N, 38 38 3"),
@ -199,20 +199,17 @@ _TOOLTIPS = {
"Longitude" : _("Enter the Longitude GPS Coordinates for this image,\n" "Longitude" : _("Enter the Longitude GPS Coordinates for this image,\n"
"Example: 10.396378, 10 23 46 E, 105° 6 6″ W, -105 6 6"), "Example: 10.396378, 10 23 46 E, 105° 6 6″ W, -105 6 6"),
# GPS Altitude measured in meters... # GPS Altitude (in meters)...
"Altitude" : _("This is the measurement of Above or Below Sea Level. It is measured in meters." "Altitude" : _("This is the measurement of Above or Below Sea Level. It is measured in meters."
"Example: 200.558, -200.558"), "Example: 200.558, -200.558"),
# Date/ Time received from the GPS Satellites... # Date/ Time (received from the GPS Satellites)...
"gpsTimeStamp" : _("The time that the GPS Latitude/ Longitude was received from the GPS Satellites.") } "gpsTimeStamp" : _("The time that the GPS Latitude/ Longitude was received from the GPS Satellites.") }
_DATATIPS = dict( (key, tooltip) for key, tooltip in _DATATIPS.items() )
_TOOLTIPS = dict( (key, tip) for key, tip in _TOOLTIPS.items() )
# define tooltips for all buttons... # define tooltips for all buttons...
# common buttons for all images... # common buttons for all images...
_BUTTONTIPS = { _BUTTONTIPS = {
# Clear Edit Area button...
"Clear" : _("Clears the Exif metadata from the Edit area."),
# Wiki Help button... # Wiki Help button...
"Help" : _("Displays the Gramps Wiki Help page for 'Edit Image Exif Metadata' in your web browser."), "Help" : _("Displays the Gramps Wiki Help page for 'Edit Image Exif Metadata' in your web browser."),
@ -290,24 +287,20 @@ 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)
# Clear, Thumbnail View, Convert horizontal box # Thumbnail View, and Convert horizontal box
ctc_box = gtk.HButtonBox() thc_box = gtk.HButtonBox()
ctc_box.set_layout(gtk.BUTTONBOX_START) thc_box.set_layout(gtk.BUTTONBOX_START)
main_vbox.pack_start(ctc_box, expand =False, fill =False, padding =5) main_vbox.pack_start(thc_box, expand =False, fill =False, padding =5)
# Clear button...
ctc_box.add( self.__create_button(
"Clear", False, [self.clear_display], gtk.STOCK_CLEAR) )
# Thumbnail View button... # Thumbnail View button...
ctc_box.add( self.__create_button( thc_box.add( self.__create_button(
"Thumbnail", _("Thumbnail"), [self.thumbnail_view] ) ) "Thumbnail", _("Thumbnail"), [self.thumbnail_view]) )
# is ImageMagick installed? # is ImageMagick installed?
if _MAGICK_FOUND: if _MAGICK_FOUND:
# Convert button... # Convert button...
ctc_box.add( self.__create_button( thc_box.add( self.__create_button(
"Convert", False, [self.__convert_dialog], gtk.STOCK_CONVERT) ) "Convert", False, [self.__convert_dialog], gtk.STOCK_CONVERT) )
# Help, Edit, and Delete horizontal box # Help, Edit, and Delete horizontal box
@ -355,7 +348,9 @@ class EditExifMetadata(Gramplet):
db = self.dbstate.db db = self.dbstate.db
# clears all labels and display area... # clears all labels and display area...
self.clear_display(self.plugin_image) for widgetName in ["MediaLabel", "MimeType", "ImageSize", "MessageArea"]:
self.exif_widgets[widgetName].set_text("")
self.model.clear()
# set Message Ares to Select... # set Message Ares to Select...
self.exif_widgets["MessageArea"].set_text(_("Select an image to view it's Exif metadata...")) self.exif_widgets["MessageArea"].set_text(_("Select an image to view it's Exif metadata..."))
@ -382,7 +377,7 @@ class EditExifMetadata(Gramplet):
return return
# Activate the Clear and Edit buttons... # Activate the Clear and Edit buttons...
self.activate_buttons(["Clear", "Edit"]) self.activate_buttons(["Edit"])
# check image write privileges... # check image write privileges...
_writable = os.access(self.image_path, os.W_OK) _writable = os.access(self.image_path, os.W_OK)
@ -449,7 +444,7 @@ class EditExifMetadata(Gramplet):
# if True, setup tooltips for all Data Entry Fields... # if True, setup tooltips for all Data Entry Fields...
if fields: if fields:
for widget, tooltip in _TOOLTIPS.items(): for widget, tooltip in _DATATIPS.items():
self.exif_widgets[widget].set_tooltip_text(tooltip) self.exif_widgets[widget].set_tooltip_text(tooltip)
# if True, setup tooltips for all Buttons... # if True, setup tooltips for all Buttons...
@ -639,26 +634,6 @@ class EditExifMetadata(Gramplet):
return top return top
def clear_display(self, object):
"""
clears all data fields to nothing
"""
for widgetsName in ["MediaLabel", "MimeType", "MessageArea", "ImageSize"]:
self.exif_widgets[widgetsName].set_text("")
# Clears the display area...
self.model.clear()
# De-activate the buttons except for Help...
self.deactivate_buttons(["Thumbnail"])
if _MAGICK_FOUND:
self.deactivate_buttons(["Convert"])
if (_MAGICK_FOUND or _HEAD_FOUND):
self.deactivate_buttons(["Delete"])
def thumbnail_view(self, object): def thumbnail_view(self, object):
""" """
will allow a display area for a thumbnail pop-up window. will allow a display area for a thumbnail pop-up window.
@ -817,8 +792,8 @@ class EditExifMetadata(Gramplet):
self.exif_widgets[widget].set_sensitive(False) self.exif_widgets[widget].set_sensitive(False)
else: else:
for widgetsName in ButtonList: for widgetName in ButtonList:
self.exif_widgets[widgetsName].set_sensitive(False) self.exif_widgets[widgetName].set_sensitive(False)
def active_buttons(self, obj): def active_buttons(self, obj):
""" """
@ -837,9 +812,6 @@ class EditExifMetadata(Gramplet):
# set Message Area to Entering Data... # set Message Area to Entering Data...
self.exif_widgets["MessageArea"].set_text(_("Entering data...")) self.exif_widgets["MessageArea"].set_text(_("Entering data..."))
if not self.exif_widgets["Clear"].get_sensitive():
self.activate_buttons(["Clear"])
if _MAGICK_FOUND: if _MAGICK_FOUND:
if not self.exif_widgets["Delete"].get_sensitive(): if not self.exif_widgets["Delete"].get_sensitive():
self.activate_buttons(["Delete"]) self.activate_buttons(["Delete"])
@ -889,6 +861,12 @@ class EditExifMetadata(Gramplet):
"WARNING: This action will NOT Save any changes/ modification made to this " "WARNING: This action will NOT Save any changes/ modification made to this "
"image's Exif metadata."), "image's Exif metadata."),
# Clear button...
"Clear" : _("This button will clear all of the data fields shown here."),
# Re- display the data fields button...
"Display" : _("Re -display the data fields that were cleared from the Edit Area."),
# Convert 2 Decimal button... # Convert 2 Decimal button...
"Decimal" : _("Convert GPS Latitude/ Longitude Coordinates to Decimal representation."), "Decimal" : _("Convert GPS Latitude/ Longitude Coordinates to Decimal representation."),
@ -1079,38 +1057,34 @@ class EditExifMetadata(Gramplet):
button.show() button.show()
# Help, Save, Clear, and Close horizontal box # Help, Save, Clear, and Close horizontal box
hscc_box = gtk.HButtonBox() hscdc_box = gtk.HButtonBox()
hscc_box.set_layout(gtk.BUTTONBOX_START) hscdc_box.set_layout(gtk.BUTTONBOX_START)
main_vbox.pack_start(hscc_box, expand =False, fill =False, padding =10) main_vbox.pack_start(hscdc_box, expand =False, fill =False, padding =10)
hscc_box.show() hscdc_box.show()
# Help button... # Help button...
button = self.__create_button( hscdc_box.add(self.__create_button(
"Help", False, [self.__help_page], gtk.STOCK_HELP, True) "Help", False, [self.__help_page], gtk.STOCK_HELP, True) )
hscc_box.add(button)
button.show()
# Save button... # Save button...
button = self.__create_button("Save", False, [self.save_metadata, self.update, hscdc_box.add(self.__create_button("Save", False, [self.save_metadata, self.update,
self.display_metadata], gtk.STOCK_SAVE, True) self.display_metadata], gtk.STOCK_SAVE, True) )
hscc_box.add(button)
button.show()
# Clear button... # Clear button...
button = self.__create_button( hscdc_box.add(self.__create_button(
"Clear", False, [self.clear_edit_area], gtk.STOCK_CLEAR, True) "Clear", False, [self.clear_metadata], gtk.STOCK_CLEAR, True) )
hscc_box.add(button)
button.show() # Re -display the edit area button...
hscdc_box.add(self.__create_button(
"Display", _("Display"), [self.EditArea], False, True) )
# Close button... # Close button...
button = self.__create_button( hscdc_box.add(self.__create_button(
"Close", False, [lambda w: self.edtarea.destroy()], gtk.STOCK_CLOSE, True) "Close", False, [lambda w: self.edtarea.destroy()], gtk.STOCK_CLOSE, True) )
hscc_box.add(button)
button.show()
# disable all data fields if not one of the available exiv2 image types? # disable all data fields if not one of the available exiv2 image types?
if not any(exiv2type == self.extension for exiv2type in _vtypes): if not any(exiv2type == self.extension for exiv2type in _vtypes):
for widget in _TOOLTIPS.keys(): for widget in _DATATIPS.keys():
self.exif_widgets[widget].set_editable(False) self.exif_widgets[widget].set_editable(False)
self.edtarea.destroy() self.edtarea.destroy()
return return
@ -1147,30 +1121,13 @@ class EditExifMetadata(Gramplet):
return KeyValue return KeyValue
def clear_edit_area(self, object): def clear_metadata(self, object):
"""
will clear the Edit Area display...
"""
for widget in ["ExifLabel", "Description", "Artist", "Copyright", "Modified", "Original",
"Latitude", "Longitude", "Edit:Message"]:
self.exif_widgets[widget].set_text("")
def clear_display(self, object):
""" """
clears all data fields to nothing clears all data fields to nothing
""" """
self.model.clear() for widget in _DATATIPS.keys():
self.exif_widgets[widget].set_text("")
# De-activate the buttons except for Help...
self.deactivate_buttons(["Thumbnail"])
if _MAGICK_FOUND:
self.deactivate_buttons(["Convert"])
if (_MAGICK_FOUND or _HEAD_FOUND):
self.deactivate_buttons(["Delete"])
def EditArea(self, object): def EditArea(self, object):
""" """
@ -1179,103 +1136,99 @@ class EditExifMetadata(Gramplet):
MediaDataTags = _get_exif_keypairs(self.plugin_image) MediaDataTags = _get_exif_keypairs(self.plugin_image)
if MediaDataTags: if MediaDataTags:
MediaDataTags = [KeyTag for KeyTag in MediaDataTags if KeyTag in _DATAMAP] MediaDataTags = [KeyTag for KeyTag in MediaDataTags if KeyTag in _DATAMAP]
for KeyTag in MediaDataTags: for KeyTag in MediaDataTags:
widgetName = _DATAMAP[KeyTag]
# name for matching to exif_widgets tagValue = self._get_value(KeyTag)
widgetsName = _DATAMAP[KeyTag] if tagValue:
tagValue = self._get_value(KeyTag) if widgetName in ["ExifLabel", "Description", "Artist", "Copyright"]:
if tagValue: self.exif_widgets[widgetName].set_text(tagValue)
if widgetsName in ["ExifLabel", "Description", "Artist", "Copyright"]: # Last Changed/ Modified...
self.exif_widgets[widgetsName].set_text(tagValue) elif widgetName == "Modified":
use_date = _process_datetime(tagValue)
if use_date:
self.exif_widgets[widgetName].set_text(use_date)
# Original Creation Date/ Time... # Original Date/ Time...
elif widgetsName == "Original": elif widgetName == "Original":
date1 = self._get_value(_DATAMAP["Original"]) date1 = tagValue
date2 = self._get_value(_DATAMAP["Digitized"]) date2 = self._get_value(_DATAMAP["Digitized"])
date3 = self.orig_image.get_date_object() date3 = self.orig_image.get_date_object()
use_date = date1 or date2 or date3 use_date = date1 or date2 or date3 or False
if use_date: if use_date:
if isinstance(use_date, str): if isinstance(use_date, (str, unicode)):
use_date = _get_date_format(use_date) use_date = _get_date_format(use_date)
if use_date: if use_date:
pyear, pmonth, day, hour, minutes, seconds = use_date[0:6] pyear, pmonth, day, hour, minutes, seconds = use_date[0:6]
elif isinstance(use_date, datetime):
pyear, pmonth, day = use_date.year, use_date.month, use_date.day
hour, minutes, seconds = use_date.hour, use_date.minute, use_date.second
else:
pyear = False
if pyear:
use_date = _create_datetime(pyear, pmonth, day, hour, minutes, seconds)
if use_date:
self.exif_widgets[widgetName].set_text(_format_datetime(use_date))
elif isinstance(use_date, datetime): # LatitudeRef, Latitude, LongitudeRef, Longitude...
pyear, pmonth, day = use_date.year, use_date.month, use_date.day elif widgetName == "Latitude":
hour, minutes, seconds = use_date.hour, use_date.minute, use_date.second
else: latitude, longitude = tagValue, self._get_value(_DATAMAP["Longitude"])
pyear = False
if pyear:
use_date = _create_datetime(pyear, pmonth, day, hour, minutes, seconds) # if latitude and longitude exist, display them?
self.exif_widgets["Original"].set_text( _format_datetime(use_date) ) if (latitude and longitude):
# Last Changed/ Modified... # split latitude metadata into (degrees, minutes, and seconds)
elif widgetsName == "Modified": latdeg, latmin, latsec = rational_to_dms(latitude)
use_date = self._get_value(_DATAMAP["Modified"])
use_date = _process_datetime(use_date) if use_date else False
if use_date:
self.exif_widgets["Modified"].set_text(use_date)
# LatitudeRef, Latitude, LongitudeRef, Longitude...
elif widgetsName == "Latitude":
latitude = tagValue # split longitude metadata into degrees, minutes, and seconds
longitude = self._get_value(_DATAMAP["Longitude"]) longdeg, longmin, longsec = rational_to_dms(longitude)
# if latitude and longitude exist, display them? # check to see if we have valid GPS Coordinates?
if (latitude and longitude): latfail = any(coords == False for coords in [latdeg, latmin, latsec])
longfail = any(coords == False for coords in [longdeg, longmin, longsec])
if (not latfail and not longfail):
# split latitude metadata into (degrees, minutes, and seconds) # Latitude Direction Reference
latdeg, latmin, latsec = rational_to_dms(latitude) LatRef = self._get_value(_DATAMAP["LatitudeRef"] )
# split longitude metadata into degrees, minutes, and seconds # Longitude Direction Reference
longdeg, longmin, longsec = rational_to_dms(longitude) LongRef = self._get_value(_DATAMAP["LongitudeRef"] )
# check to see if we have valid GPS Coordinates? # set display for Latitude GPS Coordinates
latfail = any(coords == False for coords in [latdeg, latmin, latsec]) self.exif_widgets["Latitude"].set_text(
longfail = any(coords == False for coords in [longdeg, longmin, longsec]) """%s° %s %s%s""" % (latdeg, latmin, latsec, LatRef) )
if (not latfail and not longfail):
# Latitude Direction Reference # set display for Longitude GPS Coordinates
LatRef = self._get_value(_DATAMAP["LatitudeRef"] ) self.exif_widgets["Longitude"].set_text(
"""%s° %s %s%s""" % (longdeg, longmin, longsec, LongRef) )
# Longitude Direction Reference elif widgetName == "Altitude":
LongRef = self._get_value(_DATAMAP["LongitudeRef"] ) altitude = tagValue
AltitudeRef = self._get_value(_DATAMAP["AltitudeRef"])
# set display for Latitude GPS Coordinates
self.exif_widgets["Latitude"].set_text(
"""%s° %s %s%s""" % (latdeg, latmin, latsec, LatRef) )
# set display for Longitude GPS Coordinates
self.exif_widgets["Longitude"].set_text(
"""%s° %s %s%s""" % (longdeg, longmin, longsec, LongRef) )
elif widgetsName == "Altitude":
altitude = tagValue
AltitudeRef = self._get_value(_DATAMAP["AltitudeRef"])
if (altitude and AltitudeRef): if (altitude and AltitudeRef):
if AltitudeRef == "1": altitude = convert_value(altitude)
altitude = "-" + altitude if altitude:
self.exif_widgets[widgetsName].set_text(convert_value(altitude)) if AltitudeRef == "1":
altitude = "-" + altitude
self.exif_widgets[widgetName].set_text(altitude)
elif widgetsName == "gpsTimeStamp": elif widgetName == "gpsTimeStamp":
hour, minutes, seconds = rational_to_dms(tagValue) hour, minutes, seconds = rational_to_dms(tagValue)
hour, minutes, seconds = int(hour), int(minutes), int(seconds) hour, minutes, seconds = int(hour), int(minutes), int(seconds)
self.exif_widgets[widgetsName].set_text("%02d:%02d:%02d" % (hour, minutes, seconds)) self.exif_widgets[widgetName].set_text("%02d:%02d:%02d" % (
hour, minutes, seconds) )
else: else:
# set Message Area to None... # set Edit Message Area to None...
self.exif_widgets["Edit:Message"].set_text(_("There is NO Exif " self.exif_widgets["Edit:Message"].set_text(_("There is NO Exif metadata for this image."))
"metadata for this image yet..."))
for widget in _TOOLTIPS.keys(): for widget in _DATATIPS.keys():
# once the user types in that field, # once the user types in that field,
# the Edit, Clear, and Delete buttons will become active... # the Edit, Clear, and Delete buttons will become active...
@ -1286,40 +1239,35 @@ class EditExifMetadata(Gramplet):
sets the value for the metadata KeyTags sets the value for the metadata KeyTags
""" """
tagClass = KeyTag[0:5]
if LesserVersion: if LesserVersion:
self.plugin_image[KeyTag] = KeyValue self.plugin_image[KeyTag] = KeyValue
else: else:
if "Exif" in KeyTag: if tagClass == "Exif":
try: # tag is being modified... try: # tag is being modified...
self.plugin_image.__setitem__(KeyTag, KeyValue) self.plugin_image.__setitem__(KeyTag, KeyValue)
except KeyError: # tag is being created... except KeyError: # tag is being created...
self.plugin_image[KeyTag] = pyexiv2.ExifTag(KeyTag, KeyValue) self.plugin_image[KeyTag] = pyexiv2.ExifTag(KeyTag, KeyValue)
except (ValueError, AttributeError): # there is an error except (ValueError, AttributeError): # there is an error
# with either KeyTag or KeyValue pass # with either KeyTag or KeyValue is bad...
pass
elif "Xmp" in KeyTag: elif tagClass == "Xmp.":
try: try: # tag is being modified...
self.plugin_image.__setitem__(KeyTag, KeyValue) self.plugin_image.__setitem__(KeyTag, KeyValue)
except KeyError: # tag is being created...
except KeyError:
self.plugin_image[KeyTag] = pyexiv2.XmpTag(KeyTag, KeyValue) self.plugin_image[KeyTag] = pyexiv2.XmpTag(KeyTag, KeyValue)
except (ValueError, AttributeError): # there is an error
pass # with either KeyTag or KeyValue is bad...
except (ValueError, AttributeError): elif tagClass == "Uptc":
pass try: # tag is being modified...
else:
try:
self.plugin_image.__setitem__(KeyTag, KeyValue) self.plugin_image.__setitem__(KeyTag, KeyValue)
except KeyError: # tag is being created...
except KeyError:
self.plugin_image[KeyTag] = pyexiv2.IptcTag(KeyTag, KeyValue) self.plugin_image[KeyTag] = pyexiv2.IptcTag(KeyTag, KeyValue)
except (ValueError, AttributeError): # there is an error
except (ValueError, AttributeError): pass # with either KeyTag or KeyValue is bad...
pass
def write_metadata(self, plugininstance): def write_metadata(self, plugininstance):
""" """
@ -1474,115 +1422,107 @@ class EditExifMetadata(Gramplet):
and sets the KeyTag = keyvalue image metadata and sets the KeyTag = keyvalue image metadata
""" """
# determine if there has been something entered in the data fields? for widgetName in _DATATIPS.keys():
datatags = [ (self.exif_widgets[widget].get_text() ) for widget in _TOOLTIPS.keys() ]
# Exif Label/ Title widgetValue = self.exif_widgets[widgetName].get_text()
exiflabel = self.exif_widgets["ExifLabel"].get_text()
self._set_value(_DATAMAP["ExifLabel"], exiflabel)
# Description data field... # Exif Label, Description, Artist, Copyright...
description = self.exif_widgets["Description"].get_text() if widgetName in ["ExifLabel", "Description", "Artist", "Copyright"]:
self._set_value(_DATAMAP["Description"], description) self._set_value(_DATAMAP[widgetName], widgetValue)
# Modify Date/ Time... not a data field, but saved anyway... # Modify Date/ Time...
modified = datetime.now() elif widgetName == "Modified":
self._set_value(_DATAMAP["Modified"], modified) modified = datetime.now()
self.exif_widgets["Modified"].set_text(_format_datetime(modified) ) self._set_value(_DATAMAP[widgetName], modified)
self.exif_widgets[widgetName].set_text(_format_datetime(modified) )
# Artist/ Author data field... # Original Date/ Time...
artist = self.exif_widgets["Artist"].get_text() elif widgetName == "Original":
self._set_value(_DATAMAP["Artist"], artist) original = _process_datetime(widgetValue)
if original:
self._set_value(_DATAMAP[widgetName], original)
# Copyright data field... # Latitude/ Longitude...
copyright = self.exif_widgets["Copyright"].get_text() elif widgetName == "Latitude":
self._set_value(_DATAMAP["Copyright"], copyright) latitude = widgetValue
longitude = self.exif_widgets["Longitude"].get_text()
# Original Date/ Time... # check to see if Latitude/ Longitude exists?
original = self.exif_widgets["Original"].get_text() if (latitude and longitude):
original = _process_datetime(original) if original else False
if original is not False:
self._set_value(_DATAMAP["Original"], original)
# Latitude/ Longitude data fields # complete some error checking to prevent crashes...
latitude = self.exif_widgets["Latitude"].get_text() # if "?" character exist, remove it?
longitude = self.exif_widgets["Longitude"].get_text() if "?" in latitude:
latitude = latitude.replace("?", "")
if "?" in longitude:
longitude = longitude.replace("?", "")
# check to see if Latitude/ Longitude exists? # if "," character exists, remove it?
if (latitude and longitude): if "," in latitude:
latitude = latitude.replace(",", "")
if "," in longitude:
longitude = longitude.replace(",", "")
# complete some error checking to prevent crashes... # if it is in decimal format, convert it to DMS?
# if "?" character exist, remove it? # if not, then do nothing?
if "?" in latitude: self.convert2dms(self.plugin_image)
latitude = latitude.replace("?", "")
if "?" in longitude:
longitude = longitude.replace("?", "")
# if "," character exists, remove it? # get Latitude/ Longitude after converting it...
if "," in latitude: latitude = self.exif_widgets["Latitude"].get_text()
latitude = latitude.replace(",", "") longitude = self.exif_widgets["Longitude"].get_text()
if "," in longitude:
longitude = longitude.replace(",", "")
# if it is in decimal format, convert it to DMS? # will add (degrees, minutes, seconds) symbols if needed?
# if not, then do nothing? # if not, do nothing...
self.convert2dms(self.plugin_image) latitude, longitude = self.addsymbols2gps(latitude, longitude)
# get Latitude/ Longitude after converting it... # set up for display...
latitude = self.exif_widgets["Latitude"].get_text() self.exif_widgets["Latitude"].set_text(latitude)
longitude = self.exif_widgets["Longitude"].get_text() self.exif_widgets["Longitude"].set_text(longitude)
# will add (degrees, minutes, seconds) symbols if needed? LatitudeRef = " N"
# if not, do nothing... if "S" in latitude:
latitude, longitude = self.addsymbols2gps(latitude, longitude) LatitudeRef = " S"
latitude = latitude.replace(LatitudeRef, "")
LatitudeRef = LatitudeRef.replace(" ", "")
# set up display LongitudeRef = " E"
self.exif_widgets["Latitude"].set_text(latitude) if "W" in longitude:
self.exif_widgets["Longitude"].set_text(longitude) LongitudeRef = " W"
longitude = longitude.replace(LongitudeRef, "")
LongitudeRef = LongitudeRef.replace(" ", "")
LatitudeRef = " N" # remove symbols for saving Latitude/ Longitude GPS Coordinates
if "S" in latitude: latitude, longitude = _removesymbols4saving(latitude, longitude)
LatitudeRef = " S"
latitude = latitude.replace(LatitudeRef, "")
LatitudeRef = LatitudeRef.replace(" ", "")
LongitudeRef = " E" # convert (degrees, minutes, seconds) to Rational for saving
if "W" in longitude: self._set_value(_DATAMAP["LatitudeRef"], LatitudeRef)
LongitudeRef = " W" self._set_value(_DATAMAP["Latitude"], coords_to_rational(latitude))
longitude = longitude.replace(LongitudeRef, "")
LongitudeRef = LongitudeRef.replace(" ", "")
# remove symbols for saving Latitude/ Longitude GPS Coordinates # convert (degrees, minutes, seconds) to Rational for saving
latitude, longitude = _removesymbols4saving(latitude, longitude) self._set_value(_DATAMAP["LongitudeRef"], LongitudeRef)
self._set_value(_DATAMAP["Longitude"], coords_to_rational(longitude))
# convert (degrees, minutes, seconds) to Rational for saving # Altitude, and Altitude Reference...
self._set_value(_DATAMAP["LatitudeRef"], LatitudeRef) elif widgetName == "Altitude":
self._set_value(_DATAMAP["Latitude"], coords_to_rational(latitude)) altitude = widgetValue
# convert (degrees, minutes, seconds) to Rational for saving AltitudeRef = "0"
self._set_value(_DATAMAP["LongitudeRef"], LongitudeRef) if altitude:
self._set_value(_DATAMAP["Longitude"], coords_to_rational(longitude)) if altitude[0] == "-":
altitude = altitude.replace("-", "")
AltitudeRef = "1"
# AltitudeRef and Altitude data fields... self._set_value(_DATAMAP["AltitudeRef"], AltitudeRef)
altitude = self.exif_widgets["Altitude"].get_text() self._set_value(_DATAMAP["Altitude"], coords_to_rational(altitude) )
if altitude:
AltitudeRef = "0" # gpsTimeStamp...
if altitude[0] == "-": elif widgetName == "gpsTimeStamp":
AltitudeRef = "1" if widgetValue:
widgetValue = coords_to_rational(widgetValue)
self._set_value(_DATAMAP["AltitudeRef"], AltitudeRef) self._set_value(_DATAMAP[widgetName], widgetValue)
self._set_value(_DATAMAP["Altitude"], coords_to_rational(altitude) )
# gpsTimeStamp data field...
gpsTimeStamp = self.exif_widgets["gpsTimeStamp"].get_text()
if gpsTimeStamp:
gpsTimeStamp = coords_to_rational(gpsTimeStamp)
self._set_value(_DATAMAP["gpsTimeStamp"], gpsTimeStamp)
if (len(datatags) > 0):
# set Message Area to Saved... # set Message Area to Saved...
self.exif_widgets["Edit:Message"].set_text(_("Saving Exif metadata to this image...")) self.exif_widgets["Edit:Message"].set_text(_("Saving Exif metadata to image..."))
# writes all Exif Metadata to image even if the fields are all empty... # writes all Exif Metadata to image even if the fields are all empty...
self.write_metadata(self.plugin_image) self.write_metadata(self.plugin_image)
@ -1685,13 +1625,20 @@ def string_to_rational(coordinate):
def coords_to_rational(Coordinates): def coords_to_rational(Coordinates):
""" """
returns the GPS coordinates to Latitude/ Longitude returns the rational equivalent for Latitude/ Longitude, gpsTimeStamp, and Altitude...
""" """
# Latitude/ Longitude...
if " " in Coordinates: if " " in Coordinates:
return [string_to_rational(coordinate) for coordinate in Coordinates.split(" ")] Coordinates = [string_to_rational(coordinate) for coordinate in Coordinates.split(" ")]
# gpsTimeStamp...
elif ":" in Coordinates: elif ":" in Coordinates:
return [string_to_rational(coordinate) for coordinate in Coordinates.split(":")] Coordinates = [string_to_rational(coordinate) for coordinate in Coordinates.split(":")]
# Altitude...
else:
Coordinates = [string_to_rational(Coordinates)]
return Coordinates return Coordinates
@ -1757,23 +1704,22 @@ def _format_datetime(exif_dt):
""" """
date_part = gen.lib.Date() date_part = gen.lib.Date()
if type(exif_dt) == datetime: if isinstance(exif_dt, datetime):
date_part.set_yr_mon_day(exif_dt.year, exif_dt.month, exif_dt.day) date_part.set_yr_mon_day(exif_dt.year, exif_dt.month, exif_dt.day)
time_str = "%02d:%02d:%02d" % (exif_dt.hour, exif_dt.minute, exif_dt.second)
date_str = _dd.display(date_part) date_str = _dd.display(date_part)
time_str = _('%(hr)02d:%(min)02d:%(sec)02d') % {'hr': exif_dt.hour,
elif type(exif_dt) == str: 'min': exif_dt.minute,
'sec': exif_dt.second}
elif isinstance(exif_dt, str):
exif_dt = _get_date_format(exif_dt) exif_dt = _get_date_format(exif_dt)
if exif_dt == False: if exif_dt == False:
return False return False
date_part.set_yr_mon_day(exif_dt[0], exif_dt[1], exif_dt[2]) date_part.set_yr_mon_day(exif_dt[0], exif_dt[1], exif_dt[2])
time_str = "%02d:%02d:%02d" % exif_dt[3:6]
date_str = _dd.display(date_part) date_str = _dd.display(date_part)
time_str = _('%(hr)02d:%(min)02d:%(sec)02d') % {'hr' : exif_dt[3],
'min': exif_dt[4],
'sec': exif_dt[5]}
return _('%(date)s %(time)s') % {'date': date_str, 'time': time_str} return _('%(date)s %(time)s') % {'date': date_str, 'time': time_str}
def _get_date_format(datestr): def _get_date_format(datestr):