Basically, a total new re-write of my addon.

svn: r17599
This commit is contained in:
Rob G. Healey
2011-05-28 06:00:22 +00:00
parent bd89ee1889
commit 42b6bcdb87

View File

@@ -26,7 +26,7 @@
# ***************************************************************************** # *****************************************************************************
import os, sys import os, sys
from datetime import datetime, date from datetime import datetime, date
from calendar import monthrange as _mr import calendar
import time import time
# abilty to escape certain characters from output... # abilty to escape certain characters from output...
@@ -164,14 +164,15 @@ _DATAMAP = {
"Exif.GPSInfo.GPSLatitude" : "Latitude", "Exif.GPSInfo.GPSLatitude" : "Latitude",
"Exif.GPSInfo.GPSLongitudeRef" : "LongitudeRef", "Exif.GPSInfo.GPSLongitudeRef" : "LongitudeRef",
"Exif.GPSInfo.GPSLongitude" : "Longitude", "Exif.GPSInfo.GPSLongitude" : "Longitude",
"Exif.GPSInfo.GPSAltitudeRef" : "AltitudeRef", "Exif.GPSInfo.GPSTimeStamp" : "GPSTimeStamp"}
"Exif.GPSInfo.GPSAltitude" : "Altitude"}
_DATAMAP = dict( (key, val) for key, val in _DATAMAP.items() ) _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 = { _TOOLTIPS = {
"ExifLabel" : _("This is equivalent to the Title field in the media object editor."),
"Description" : _("Provide a short descripion for this image."), "Description" : _("Provide a short descripion for this image."),
"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 "
@@ -179,30 +180,18 @@ _TOOLTIPS = {
"Copyright" : _("Enter the copyright information for this image. \n"), "Copyright" : _("Enter the copyright information for this image. \n"),
"Year" : _("Enter the year for the date of this image.\n" "Original" : _("The original date/ time when the image was first created/ taken as in a photograph.\n"
"Example: 1826 - 2100, You can either spin the up and down arrows by clicking on them or enter it manually."), "Example: 1830-01-1 09:30:59"),
"Month" : _("Enter the month for the date of this image.\n" "Modified" : _("This is the date/ time that the image was last changed/ modified.\n"
"Example: 0 - 12, You can either spin the up and down arrows by clicking on them or enter it manually."), "Example: 2011-05-24 14:30:00"),
"Day" : _("Enter the day for the date of this image.\n"
"Example: 1 - 31, You can either spin the up and down arrows by clicking on them or enter it manually."),
"Hour" : _("Enter the hour for the time of this image.\n"
"Example: 0 - 23, You can either spin the up and down arrows by clicking on them or enter it manually.\n\n"
"The hour is represented in 24-hour format."),
"Minutes" : _("Enter the minutes for the time of this image.\n"
"Example: 0 - 59, You can either spin the up and down arrows by clicking on them or enter it manually."),
"Seconds" : _("Enter the seconds for the time of this image.\n"
"Example: 0 - 59, You can either spin the up and down arrows by clicking on them or enter it manually."),
"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"),
"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") }
_TOOLTIPS = dict( (key, tip) for key, tip in _TOOLTIPS.items() ) _TOOLTIPS = dict( (key, tip) for key, tip in _TOOLTIPS.items() )
# define tooltips for all buttons... # define tooltips for all buttons...
@@ -264,7 +253,7 @@ class EditExifMetadata(Gramplet):
label.set_line_wrap(True) label.set_line_wrap(True)
medialabel.pack_start(label, expand =False) medialabel.pack_start(label, expand =False)
self.exif_widgets["MediaLabel"] = label self.exif_widgets["MediaLabel"] = label
main_vbox.pack_start(medialabel, expand =False, fill =False, padding =5) main_vbox.pack_start(medialabel, expand =False, fill =False, padding =2)
label.show() label.show()
# Displays mime type information... # Displays mime type information...
@@ -274,7 +263,7 @@ class EditExifMetadata(Gramplet):
label.set_line_wrap(True) label.set_line_wrap(True)
mimetype.pack_start(label, expand =False) mimetype.pack_start(label, expand =False)
self.exif_widgets["MimeType"] = label self.exif_widgets["MimeType"] = label
main_vbox.pack_start(mimetype, expand =False, fill =False, padding =5) main_vbox.pack_start(mimetype, expand =False, fill =False, padding =2)
label.show() label.show()
# Displays all plugin messages... # Displays all plugin messages...
@@ -284,9 +273,12 @@ class EditExifMetadata(Gramplet):
label.set_line_wrap(True) label.set_line_wrap(True)
messagearea.pack_start(label, expand =False) messagearea.pack_start(label, expand =False)
self.exif_widgets["MessageArea"] = label self.exif_widgets["MessageArea"] = label
main_vbox.pack_start(messagearea, expand =False, fill =False, padding =5) main_vbox.pack_start(messagearea, expand =False, fill =False, padding =2)
label.show() label.show()
# Separator line before the buttons...
main_vbox.pack_start(gtk.HSeparator(), expand =False, fill =False, padding =2)
# Clear, Thumbnail View, Convert horizontal box # Clear, Thumbnail View, Convert horizontal box
ctc_box = gtk.HButtonBox() ctc_box = gtk.HButtonBox()
ctc_box.set_layout(gtk.BUTTONBOX_START) ctc_box.set_layout(gtk.BUTTONBOX_START)
@@ -314,7 +306,7 @@ class EditExifMetadata(Gramplet):
# Help button... # Help button...
hed_box.add( self.__create_button( hed_box.add( self.__create_button(
"Help", False, [self.__help_page], gtk.STOCK_HELP) ) "Help", False, [self.__help_page], gtk.STOCK_HELP, True) )
# Edit button... # Edit button...
hed_box.add( self.__create_button( hed_box.add( self.__create_button(
@@ -341,9 +333,6 @@ class EditExifMetadata(Gramplet):
""" """
db = self.dbstate.db db = self.dbstate.db
# disable all buttons...
self.deactivate_buttons(["All"])
# clears all labels and display area... # clears all labels and display area...
for widget in ["MediaLabel", "MimeType", "MessageArea"]: for widget in ["MediaLabel", "MimeType", "MessageArea"]:
self.exif_widgets[widget].set_text("") self.exif_widgets[widget].set_text("")
@@ -524,39 +513,42 @@ class EditExifMetadata(Gramplet):
# set Message Area to Display... # set Message Area to Display...
self.exif_widgets["MessageArea"].set_text(_("Displaying all Exif metadata keypairs...")) self.exif_widgets["MessageArea"].set_text(_("Displaying all Exif metadata keypairs..."))
for KeyTag in metadatatags: # Activate Delete button if ImageMagick or jhead is found?...
if LesserVersion: # prior to pyexiv2-0.2.0... if (_MAGICK_FOUND or _JHEAD_FOUND):
self.activate_buttons(["Delete"])
label = self.plugin_image.tagDetails(KeyTag)[0] for KeyTag in metadatatags:
if LesserVersion: # prior to v0.2.0
label = metadata.tagDetails(KeyTag)[0]
if KeyTag in ("Exif.Image.DateTime", if KeyTag in ("Exif.Image.DateTime",
"Exif.Photo.DateTimeOriginal", "Exif.Photo.DateTimeOriginal",
"Exif.Photo.DateTimeDigitized"): "Exif.Photo.DateTimeDigitized"):
human_value = _format_datetime(self.plugin_image[KeyTag]) human_value = _format_datetime(self.plugin_image[KeyTag])
else: else:
human_value = self.plugin_image.interpretedExifValue(KeyTag) human_value = self.plugin_image.interpretedExifValue(KeyTag)
else: # pyexiv2-0.2.0 and above... self.model.add((label, human_value))
else: # v0.2.0 and above
try: try:
tag = self.plugin_image[KeyTag] tag = self.plugin_image[KeyTag]
# display the date as the user has set in preferences...
if KeyTag in ("Exif.Image.DateTime", if KeyTag in ("Exif.Image.DateTime",
"Exif.Photo.DateTimeOriginal", "Exif.Photo.DateTimeOriginal",
"Exif.Photo.DateTimeDigitized"): "Exif.Photo.DateTimeDigitized"):
label = tag.label
human_value = _format_datetime(tag.value) human_value = _format_datetime(tag.value)
elif ("Xmp" in KeyTag or "Iptc" in KeyTag): # display anything else...
label = KeyTag
human_value = tag.value
else: else:
label = tag.label
human_value = tag.human_value human_value = tag.human_value
self.model.add((label, human_value)) self.model.add((tag.label, human_value))
except AttributeError: except AttributeError:
pass pass
def __create_button(self, pos, text, callback =[], icon =False): self.set_has_data(self.model.count > 0)
def __create_button(self, pos, text, callback =[], icon =False, sensitive =False):
""" """
creates and returns a button for display creates and returns a button for display
""" """
@@ -573,6 +565,9 @@ class EditExifMetadata(Gramplet):
# attach a addon widget to the button for manipulation... # attach a addon widget to the button for manipulation...
self.exif_widgets[pos] = button self.exif_widgets[pos] = button
if not sensitive:
button.set_sensitive(False)
return button return button
def build_shaded_display(self): def build_shaded_display(self):
@@ -587,6 +582,27 @@ class EditExifMetadata(Gramplet):
return top return top
def __description_exif(self, object):
pass
def __origin_exif(self, object):
pass
def __image_exif(self, object):
pass
def __camera_exif(self, object):
pass
def __advanced_exif(self, object):
pass
def clear_display(self, obj): def clear_display(self, obj):
""" """
clears all data fields to nothing clears all data fields to nothing
@@ -614,19 +630,19 @@ class EditExifMetadata(Gramplet):
tip = _("Click Close to close this Thumbnail Viewing Area.") tip = _("Click Close to close this Thumbnail Viewing Area.")
tbarea = gtk.Window(gtk.WINDOW_TOPLEVEL) self.tbarea = gtk.Window(gtk.WINDOW_TOPLEVEL)
tbarea.tooltip = tip self.tbarea.tooltip = tip
tbarea.set_title(_("Thumbnail Viewing Area")) self.tbarea.set_title(_("Thumbnail Viewing Area"))
tbarea.set_default_size(250, 200) self.tbarea.set_default_size(250, 200)
tbarea.set_border_width(10) self.tbarea.set_border_width(10)
tbarea.connect('destroy', lambda tbarea: tbarea.destroy() ) self.tbarea.connect('destroy', lambda w: self.tbarea.destroy() )
# extract the thumbnail data # extract the thumbnail data
previews = self.plugin_image.previews previews = self.plugin_image.previews
if not previews: if not previews:
print(_("This image doesn't contain any Thumbnails...")) print(_("This image doesn't contain any Thumbnails..."))
tbarea.destroy() self.tbarea.destroy()
else: else:
# Get the largest preview available... # Get the largest preview available...
@@ -643,9 +659,9 @@ class EditExifMetadata(Gramplet):
imgwidget.set_from_pixbuf(pixbuf) imgwidget.set_from_pixbuf(pixbuf)
# Show the application's main window... # Show the application's main window...
tbarea.add(imgwidget) self.tbarea.add(imgwidget)
imgwidget.show() imgwidget.show()
tbarea.show() self.tbarea.show()
def __convert_dialog(self, obj): def __convert_dialog(self, obj):
""" """
@@ -811,16 +827,11 @@ class EditExifMetadata(Gramplet):
main_vbox.set_border_width(10) main_vbox.set_border_width(10)
main_vbox.set_size_request(480, 518) main_vbox.set_size_request(480, 518)
# Displays Last Change/ Modified DateStamp...
datestamp = gtk.HBox(False)
label = gtk.Label() label = gtk.Label()
label.set_alignment(0.0, 0.0) label.set_alignment(0.0, 0.0)
label.set_line_wrap(True) main_vbox.pack_start(label, expand =False, fill =False, padding =5)
datestamp.pack_start(label, expand =False, fill =False, padding =0)
self.exif_widgets["DateStamp"] = label
label.show() label.show()
main_vbox.pack_start(datestamp, expand =False, fill =False, padding =10) self.exif_widgets["Edit:Message"] = label
datestamp.show()
# create the data fields... # create the data fields...
# ***Label/ Title, Description, Artist, and Copyright # ***Label/ Title, Description, Artist, and Copyright
@@ -868,8 +879,8 @@ class EditExifMetadata(Gramplet):
now = time.localtime() now = time.localtime()
# iso format: Year, Month, Day spinners... # iso format: Year, Month, Day spinners...
datetime_frame = gtk.Frame(_("Original Date/ Time")) datetime_frame = gtk.Frame(_("Date/ Time"))
datetime_frame.set_size_request(460, 110) datetime_frame.set_size_request(460, 120)
main_vbox.pack_start(datetime_frame, expand =False, fill =False, padding =0) main_vbox.pack_start(datetime_frame, expand =False, fill =False, padding =0)
datetime_frame.show() datetime_frame.show()
@@ -882,57 +893,34 @@ class EditExifMetadata(Gramplet):
new_vbox.pack_start(new_hbox, expand =False, fill =False, padding =5) new_vbox.pack_start(new_hbox, expand =False, fill =False, padding =5)
new_hbox.show() new_hbox.show()
# create the adjustment for each of the SpinButtons for Date/ Time for widget, text in [
datetime_adj = [ [value, lower, upper, step, page] for (value, lower, upper, step, page) in [ ("Original", _("Original Date/ Time :") ),
(now[0], 1826, 2100, 1, 100), # Year ("Modified", _("Last Changed :") ) ]:
(now[1], 1, 12, 1, 1), # Month
(now[2], 1, 31, 1, 1), # Day
(now[3], 0, 23, 1, 1), # Hour
(now[4], 0, 59, 1, 1), # Minutes
(now[5], 0, 59, 1, 1) ] ] # Seconds
textNames = [_("Year :"), _("Month :"), _("Day :"), _("Hour :"), _("Minutes :"), _("Seconds :")]
widgetNames = ["Year", "Month", "Day", "Hour", "Minutes", "Seconds"]
index = 0
for (value, lower, upper, step, page) in datetime_adj:
text, widget = textNames[index], widgetNames[index]
vbox2 = gtk.VBox(False, 0) vbox2 = gtk.VBox(False, 0)
vbox2.set_size_request(224, 60)
new_hbox.pack_start(vbox2, expand =False, fill =False, padding =5) new_hbox.pack_start(vbox2, expand =False, fill =False, padding =5)
vbox2.show() vbox2.show()
label = gtk.Label(text) label = gtk.Label(text)
label.set_alignment(0.0, 0.0) label.set_alignment(0.0, 0.0)
label.set_size_request(70, 25) label.set_size_request(222, 25)
vbox2.pack_start(label, expand =False, fill =False, padding =0) vbox2.pack_start(label, expand =False, fill =False, padding =0)
label.show() label.show()
event_box = gtk.EventBox() event_box = gtk.EventBox()
event_box.set_border_width(2) event_box.set_size_request(222, 40)
event_box.set_size_request(70, 40)
vbox2.pack_start(event_box, expand =False, fill =False, padding =0) vbox2.pack_start(event_box, expand =False, fill =False, padding =0)
event_box.show()
self.exif_widgets[widget + "Box"] = event_box self.exif_widgets[widget + "Box"] = event_box
event_box.show()
adj = gtk.Adjustment(value, lower, upper, step, page) entry = gtk.Entry(max =40)
spinner = self.__create_spinner("Year", adj, False, False) event_box.add(entry)
event_box.add(spinner) self.exif_widgets[widget] = entry
spinner.show() entry.show()
self.exif_widgets[widget] = spinner
index += 1
new_hbox = gtk.HBox(False, 0)
datetime_frame.add(new_hbox)
new_vbox.show()
label = gtk.Label()
new_hbox.pack_start(label, expand =False, fill =False, padding =10)
label.show()
self.exif_widgets["DateOriginal"] = label
# GPS Coordinates... # GPS Coordinates...
latlong_frame = gtk.Frame(_("Latitude/ Longitude/ Altitude GPS Coordinates")) latlong_frame = gtk.Frame(_("Latitude/ Longitude GPS Coordinates"))
latlong_frame.set_size_request(460, 100) latlong_frame.set_size_request(460, 100)
main_vbox.pack_start(latlong_frame, expand =False, fill =False, padding =0) main_vbox.pack_start(latlong_frame, expand =False, fill =False, padding =0)
latlong_frame.show() latlong_frame.show()
@@ -945,11 +933,11 @@ class EditExifMetadata(Gramplet):
new_vbox.pack_start(new_hbox, expand =False, fill =False, padding =0) new_vbox.pack_start(new_hbox, expand =False, fill =False, padding =0)
new_hbox.show() new_hbox.show()
# Latitude/ Longitude/ Altitude GPS Coordinates... # Latitude/ Longitude GPS Coordinates...
widget_text = [ (text) for text in [_("Latitude"), _("Longitude"), _("Altitude") ] ] for widget, text in [
while widget_text: ("Latitude", _("Latitude :") ),
text = widget_text[0] + " :" ("Longitude", _("Longitude :") ),
widget = widget_text[0] ("GPSTimeStamp", _("GPS TimeStamp :") ) ]:
vbox2 = gtk.VBox(False, 0) vbox2 = gtk.VBox(False, 0)
new_hbox.pack_start(vbox2, expand =False, fill =False, padding =5) new_hbox.pack_start(vbox2, expand =False, fill =False, padding =5)
@@ -977,9 +965,6 @@ class EditExifMetadata(Gramplet):
entry.show() entry.show()
self.exif_widgets[widget] = entry self.exif_widgets[widget] = entry
# remove the entries one by one after displaying...
widget_text.remove(widget)
# Help, Save, Clear, and Close horizontal box # Help, Save, Clear, and Close horizontal box
hscc_box = gtk.HButtonBox() hscc_box = gtk.HButtonBox()
hscc_box.set_layout(gtk.BUTTONBOX_START) hscc_box.set_layout(gtk.BUTTONBOX_START)
@@ -988,23 +973,25 @@ class EditExifMetadata(Gramplet):
# Help button... # Help button...
button = self.__create_button( button = self.__create_button(
"Help", False, [self.__help_page], gtk.STOCK_HELP) "Help", False, [self.__help_page], gtk.STOCK_HELP, True)
hscc_box.add(button) hscc_box.add(button)
button.show() button.show()
# Save button... # Save button...
button = self.__create_button("Save", False, [self.save_metadata, self.update, button = self.__create_button("Save", False, [self.save_metadata, self.update,
self.display_metadata], gtk.STOCK_SAVE) self.display_metadata], gtk.STOCK_SAVE, True)
hscc_box.add(button) hscc_box.add(button)
button.show() button.show()
# Clear button... # Clear button...
button = self.__create_button("Clear", False, [self.clear_edit_area], gtk.STOCK_CLEAR) button = self.__create_button(
"Clear", False, [self.clear_edit_area], gtk.STOCK_CLEAR, True)
hscc_box.add(button) hscc_box.add(button)
button.show() button.show()
# Close button... # Close button...
button = self.__create_button("Close", False, [lambda w: self.edtarea.destroy()], gtk.STOCK_CLOSE) button = self.__create_button(
"Close", False, [lambda w: self.edtarea.destroy()], gtk.STOCK_CLOSE, True)
hscc_box.add(button) hscc_box.add(button)
button.show() button.show()
@@ -1044,26 +1031,16 @@ class EditExifMetadata(Gramplet):
will clear the Edit Area display... will clear the Edit Area display...
""" """
for widget in ["DateStamp", "ExifLabel", "Description", "Artist", "Copyright", "Latitude", "Longitude"]: for widget in ["ExifLabel", "Description", "Artist", "Copyright", "Modified", "Original",
self.exif_widgets[widget].set_text() "Latitude", "Longitude", "GPSTimeStamp", "Edit:Message"]:
self.exif_widgets[widget].set_text("")
index = 0
now = time.localtime()
for widget in ["Year", "Month", "Day", "Hour", "Minutes", "Seconds"]:
self.exif_widgets[widget].set_value(now[index])
index += 1
def clear_display(self, object): def clear_display(self, object):
""" """
clears all data fields to nothing clears all data fields to nothing
""" """
for widgetsName in ["DateStamp"]: self.model.clear()
self.exif_widgets[widgetsName].set_text("")
for widget, tooltip in _TOOLTIPS.items():
self.exif_widgets[widget].set_text("")
# De-activate the buttons except for Help... # De-activate the buttons except for Help...
self.deactivate_buttons(["Thumbnail"]) self.deactivate_buttons(["Thumbnail"])
@@ -1074,23 +1051,6 @@ class EditExifMetadata(Gramplet):
if (_MAGICK_FOUND or _HEAD_FOUND): if (_MAGICK_FOUND or _HEAD_FOUND):
self.deactivate_buttons(["Delete"]) self.deactivate_buttons(["Delete"])
def __create_spinner(self, pos, adjustment, climb =True, wrap =True, numdigits =0):
"""
Creates and returns the Date/ Time spinners...
"""
if climb:
spin_button = gtk.SpinButton(adjustment, climb_rate =0.0, digits =numdigits)
else:
spin_button = gtk.SpinButton(adjustment, climb_rate =1.0, digits =numdigits)
spin_button.set_wrap(wrap)
spin_button.set_numeric(True)
spin_button.update()
self.exif_widgets[pos] = spin_button
return spin_button
def EditArea(self, MediaDataTags): def EditArea(self, MediaDataTags):
""" """
displays the image Exif metadata in the Edit Area... displays the image Exif metadata in the Edit Area...
@@ -1102,13 +1062,6 @@ class EditExifMetadata(Gramplet):
# if no Exif metadata, disable the has_data() functionality? # if no Exif metadata, disable the has_data() functionality?
if MediaDataTags: if MediaDataTags:
# activate Save button...
self.activate_buttons(["Save"])
# Activate Delete button if ImageMagick or jhead is found?...
if (_MAGICK_FOUND or _JHEAD_FOUND):
self.activate_buttons(["Delete"])
for KeyTag in MediaDataTags: for KeyTag in MediaDataTags:
# name for matching to exif_widgets # name for matching to exif_widgets
@@ -1117,7 +1070,7 @@ class EditExifMetadata(Gramplet):
tagValue = self._get_value(KeyTag) tagValue = self._get_value(KeyTag)
if tagValue: if tagValue:
if widgetsName in ["ExifLabel", "Description", "Artist", "Copyright"]: if widgetsName in ["ExifLabel", "Description", "Artist", "Copyright", "GPSTimeStamp"]:
self.exif_widgets[widgetsName].set_text(tagValue) self.exif_widgets[widgetsName].set_text(tagValue)
# Last Changed/ Modified... # Last Changed/ Modified...
@@ -1125,8 +1078,7 @@ class EditExifMetadata(Gramplet):
use_date = self._get_value(_DATAMAP["Modified"]) use_date = self._get_value(_DATAMAP["Modified"])
use_date = _process_datetime(use_date) if use_date else False use_date = _process_datetime(use_date) if use_date else False
if use_date: if use_date:
self.exif_widgets["DateStamp"].set_text( self.exif_widgets["Modified"].set_text(use_date)
_("Last Changed: %s") % use_date)
# Original Creation Date/ Time... # Original Creation Date/ Time...
elif widgetsName == "Original": elif widgetsName == "Original":
@@ -1148,11 +1100,8 @@ class EditExifMetadata(Gramplet):
year = False year = False
if year: if year:
# update Date/ Time spin buttons...
self.update_spinners(year, month, day, hour, minutes, seconds)
use_date = _create_datetime(year, month, day, hour, minutes, seconds) use_date = _create_datetime(year, month, day, hour, minutes, seconds)
self.exif_widgets["DateOriginal"].set_text( _format_datetime(use_date) ) self.exif_widgets["Original"].set_text( _format_datetime(use_date) )
# LatitudeRef, Latitude, LongitudeRef, Longitude... # LatitudeRef, Latitude, LongitudeRef, Longitude...
elif widgetsName == "Latitude": elif widgetsName == "Latitude":
@@ -1188,28 +1137,13 @@ class EditExifMetadata(Gramplet):
self.exif_widgets["Longitude"].set_text( self.exif_widgets["Longitude"].set_text(
"""%s° %s %s%s""" % (longdeg, longmin, longsec, LongRef) ) """%s° %s %s%s""" % (longdeg, longmin, longsec, LongRef) )
elif widgetsName == "Altitude":
altitude = self._get_value(_DATAMAP["Altitude"] )
AltRef = self._get_value(_DATAMAP["AltitudeRef"] )
if (altitude and AltRef):
altdeg, altmin, altsec = rational_to_dms(altitude)
altfail = any(coords == False for coords in [altdeg, altmin, altsec])
if not altfail:
# set display for Altitude GPS Coordinates
self.exif_widgets["Altitude"].set_text(
"""%s° %s %s%s""" % (altdeg, altmin, altsec, AltRef) )
else: else:
# set Message Area to None... # set Message Area to None...
self.exif_widgets["MessageArea"].set_text(_("There is NO Exif " self.exif_widgets["MessageArea"].set_text(_("There is NO Exif "
"metadata for this image yet...")) "metadata for this image yet..."))
for widgetsName in ["Description", "Artist", "Copyright", "Latitude", for widgetsName in ["ExifLabel", "Description", "Artist", "Copyright", "Latitude", "Longitude"]:
"Longitude", "Altitude"]:
# 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...
@@ -1289,12 +1223,7 @@ class EditExifMetadata(Gramplet):
if (latitude and longitude): if (latitude and longitude):
if (latitude.count(".") == 1 and longitude.count(".") == 1): if (latitude.count(".") == 1 and longitude.count(".") == 1):
self.convert2dms(self.plugin_image) latitude, longitude = self.convert2dms(latitude, longitude)
# get Latitude/ Longitude from data fields
# after the conversion
latitude = self.exif_widgets["Latitude"].get_text()
longitude = self.exif_widgets["Longitude"].get_text()
# add DMS symbols if necessary? # add DMS symbols if necessary?
# the conversion to decimal format, require the DMS symbols # the conversion to decimal format, require the DMS symbols
@@ -1360,16 +1289,12 @@ class EditExifMetadata(Gramplet):
self.exif_widgets["Latitude"].set_text(latitude) self.exif_widgets["Latitude"].set_text(latitude)
self.exif_widgets["Longitude"].set_text(longitude) self.exif_widgets["Longitude"].set_text(longitude)
def convert2dms(self, obj): def convert2dms(self, latitude, longitude):
""" """
will convert a decimal GPS Coordinates into degrees, minutes, seconds will convert a decimal GPS Coordinates into degrees, minutes, seconds
for display only for display only
""" """
# get Latitude/ Longitude from the data fields
latitude = self.exif_widgets["Latitude"].get_text()
longitude = self.exif_widgets["Longitude"].get_text()
# if Latitude/ Longitude exists? # if Latitude/ Longitude exists?
if (latitude and longitude): if (latitude and longitude):
@@ -1393,14 +1318,13 @@ class EditExifMetadata(Gramplet):
LongitudeRef = "W" LongitudeRef = "W"
longdeg, longmin, longsec = longitude.split(":", 2) longdeg, longmin, longsec = longitude.split(":", 2)
self.exif_widgets["Latitude"].set_text( latitude = """%s° %s %s%s""" % (latdeg, latmin, latsec, LatitudeRef)
"""%s° %s %s%s""" % (latdeg, latmin, latsec, LatitudeRef) ) self.exif_widgets["Latitude"].set_text(latitude)
self.exif_widgets["Longitude"].set_text( longitude = """%s° %s %s%s""" % (longdeg, longmin, longsec, LongitudeRef)
"""%s° %s %s%s""" % (longdeg, longmin, longsec, LongitudeRef) ) self.exif_widgets["Longitude"].set_text(longitude)
def destroy(self, widget): return latitude, longitude
self.window.destroy()
def save_metadata(self, object): def save_metadata(self, object):
""" """
@@ -1409,13 +1333,8 @@ class EditExifMetadata(Gramplet):
""" """
# determine if there has been something entered in the data fields? # determine if there has been something entered in the data fields?
datatags = ( datatags = [ (self.exif_widgets[widget].get_text() ) for widget in _TOOLTIPS.keys()
len(self.exif_widgets["ExifLabel"].get_text() ) + if widget not in ["Close", "Save"] ]
len(self.exif_widgets["Description"].get_text() ) +
len(self.exif_widgets["Artist"].get_text() ) +
len(self.exif_widgets["Copyright"].get_text() ) +
len(self.exif_widgets["Latitude"].get_text() ) +
len(self.exif_widgets["Longitude"].get_text() ) )
# Exif Label/ Title # Exif Label/ Title
exiflabel = self.exif_widgets["ExifLabel"].get_text() exiflabel = self.exif_widgets["ExifLabel"].get_text()
@@ -1428,9 +1347,7 @@ class EditExifMetadata(Gramplet):
# Modify Date/ Time... not a data field, but saved anyway... # Modify Date/ Time... not a data field, but saved anyway...
modified = datetime.now() modified = datetime.now()
self._set_value(_DATAMAP["Modified"], modified) self._set_value(_DATAMAP["Modified"], modified)
self.exif_widgets["Modified"].set_text(_format_datetime(modified) )
# display modified Date/ Time...
self.exif_widgets["MessageArea"].set_text(_("Last Changed: %s") % _format_datetime(modified) )
# Artist/ Author data field... # Artist/ Author data field...
artist = self.exif_widgets["Artist"].get_text() artist = self.exif_widgets["Artist"].get_text()
@@ -1440,23 +1357,11 @@ class EditExifMetadata(Gramplet):
copyright = self.exif_widgets["Copyright"].get_text() copyright = self.exif_widgets["Copyright"].get_text()
self._set_value(_DATAMAP["Copyright"], copyright) self._set_value(_DATAMAP["Copyright"], copyright)
# Original Date/ Time # Original Date/ Time...
year = self._get_spin_value("Year"), original = self.exif_widgets["Original"].get_text()
month = self._get_spin_value("Month"), original = _process_datetime(original) if original else False
day = self._get_spin_value("Day"), if original is not False:
hour = self._get_spin_value("Hour"), self._set_value(_DATAMAP["Original"], original)
minutes = self._get_spin_value("Minutes"),
seconds = self._get_spin_value("Seconds")
print(year, month, day, hour, minutes, seconds)
use_date = False
if year < 1900:
use_date = "%04d-%s-%02d %02d:%02d:%02d" % (year, _dd.long_months[month], day,
hour, minutes, seconds)
else:
use_date = datetime(year, month, day, hour, minutes, seconds)
if use_date:
self._set_value(_DATAMAP["Original"], use_date)
# Latitude/ Longitude data fields # Latitude/ Longitude data fields
latitude = self.exif_widgets["Latitude"].get_text() latitude = self.exif_widgets["Latitude"].get_text()
@@ -1480,11 +1385,7 @@ class EditExifMetadata(Gramplet):
# if it is in decimal format, convert it to DMS? # if it is in decimal format, convert it to DMS?
# if not, then do nothing? # if not, then do nothing?
self.convert2dms(self.plugin_image) latitude, longitude = self.convert2dms(latitude, longitude)
# get Latitude/ Longitude from the data fields
latitude = self.exif_widgets["Latitude"].get_text()
longitude = self.exif_widgets["Longitude"].get_text()
# will add (degrees, minutes, seconds) symbols if needed? # will add (degrees, minutes, seconds) symbols if needed?
# if not, do nothing... # if not, do nothing...
@@ -1517,13 +1418,9 @@ class EditExifMetadata(Gramplet):
self._set_value(_DATAMAP["LongitudeRef"], LongitudeRef) self._set_value(_DATAMAP["LongitudeRef"], LongitudeRef)
self._set_value(_DATAMAP["Longitude"], coords_to_rational(longitude)) self._set_value(_DATAMAP["Longitude"], coords_to_rational(longitude))
if datatags: if (len(datatags) > 0):
# set Message Area to Saved... # set Message Area to Saved...
self.exif_widgets["MessageArea"].set_text(_("Saving Exif metadata to this image...")) self.exif_widgets["Edit:Message"].set_text(_("Saving Exif metadata to this image..."))
else:
# set Message Area to Cleared...
self.exif_widgets["MessageArea"].set_text(_("Image Exif metadata has been cleared "
"from this 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)
@@ -1573,47 +1470,23 @@ class EditExifMetadata(Gramplet):
update Date/ Time spinners. update Date/ Time spinners.
""" """
# split the date/ time into its six pieces... for widget, value in {
datetimevalues = {
"Year" : syear, "Year" : syear,
"Month" : smonth, "Month" : smonth,
"Day" : day, "Day" : day,
"Hour" : hour, "Hour" : hour,
"Minutes" : minutes, "Minutes" : minutes,
"Seconds" : seconds}.items() "Seconds" : seconds}.items():
for widget, value in datetimevalues:
# make sure that the amount of days for that year and month is not > than the number of days selected... # make sure that the amount of days for that year and month is not > than the number of days selected...
if widget == "Day": if widget == "Day":
numdays = [0] + [_mr(year, month)[1] for year in [syear] for month in range(1, 13) ] numdays = [0] + [calendar.monthrange(year, month)[1] for year in [syear] for month in range(1, 13) ]
if value > numdays[smonth]: if value > numdays[smonth]:
value = numdays[smonth] value = numdays[smonth]
# set the date/ time spin buttons... # set the date/ time SpinButttons
self.exif_widgets[widget].set_value(value) self.exif_widgets[widget].set_value(value)
def _get_spin_value(self, pos):
"""
will retrieve the spinner's value and format it as two digit integer...
"""
value = self.exif_widgets[pos].get_value_as_int()
if pos == "Day":
syear = self._get_spin_value("Year")
smonth = self._get_spin_value("Month")
numdays = [0] + [_mr(year, month)[1] for year in [syear] for month in range(1, 13) ]
if value > numdays[smonth]:
value = numdays[smonth]
elif value <= 0:
value = 1
return value
def _get_exif_keypairs(plugin_image): def _get_exif_keypairs(plugin_image):
""" """
Will be used to retrieve and update the Exif metadata from the image. Will be used to retrieve and update the Exif metadata from the image.
@@ -1710,18 +1583,23 @@ def _format_datetime(exif_dt):
standard Gramps date format. standard Gramps date format.
""" """
if type(exif_dt) is not datetime:
return exif_dt
date_part = gen.lib.Date() date_part = gen.lib.Date()
date_part.set_yr_mon_day(exif_dt.year, exif_dt.month, exif_dt.day) if type(exif_dt) == datetime:
date_str = _dd.display(date_part) 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)
if exif_dt.year < 1900: date_str = _dd.display(date_part)
split_time = "%02d:%02d:%02d" % (exif_dt.hour, exif_dt.minute, exif_dt.second)
time_str = split_time.strftime('%H:%M:%S') elif type(exif_dt) == str:
else:
time_str = exif_dt.strftime('%H:%M:%S') exif_dt = _get_date_format(exif_dt)
if exif_dt == False:
return False
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)
return _('%(date)s %(time)s') % {'date': date_str, 'time': time_str} return _('%(date)s %(time)s') % {'date': date_str, 'time': time_str}
@@ -1730,7 +1608,7 @@ def _get_date_format(datestr):
attempt to retrieve date format from date string attempt to retrieve date format from date string
""" """
# attempt to determine the dateformat of the variable passed to it... # attempt to determine the dateformat of the date string...
tmpDate = False tmpDate = False
for dateformat in ["%Y-%m-%d %H:%M:%S", "%Y %m %d %H:%M:%S", for dateformat in ["%Y-%m-%d %H:%M:%S", "%Y %m %d %H:%M:%S",
"%Y-%b-%d %H:%M:%S", "%Y %b %d %H:%M:%S", "%Y-%b-%d %H:%M:%S", "%Y %b %d %H:%M:%S",
@@ -1747,7 +1625,7 @@ def _get_date_format(datestr):
tmpDate = time.strptime(datestr, dateformat) tmpDate = time.strptime(datestr, dateformat)
break break
# datestring format not found... # date string format not found...
except ValueError: except ValueError:
pass pass
@@ -1783,18 +1661,14 @@ def _create_datetime(pyear, pmonth, day, hour, minutes, seconds):
seconds = 0 seconds = 0
# get the number of days in year for all months # get the number of days in year for all months
numdays = [0] + [_mr(year, month)[1] for year in [pyear] for month in range(1, 13) ] numdays = [0] + [calendar.monthrange(year, month)[1] for year in [pyear] for month in range(1, 13) ]
if day > numdays[pmonth]: if day > numdays[pmonth]:
day = numdays[pmonth] day = numdays[pmonth]
elif day <= 0: elif day <= 0:
day = 1 day = 1
if pyear < 1900: if pyear < 1900:
try: tmpDate = "%04d-%02d-%02d %02d:%02d:%02d" % (pyear, pmonth, day, hour, minutes, seconds)
tmpDate = "%04d-%02d-%02d %02d:%02d:%02d" % (pyear, pmonth, day, hour, minutes, seconds)
except ValueError:
tmpDate = False
else: else:
try: try:
tmpDate = datetime(pyear, pmonth, day, hour, minutes, seconds) tmpDate = datetime(pyear, pmonth, day, hour, minutes, seconds)
@@ -1802,9 +1676,6 @@ def _create_datetime(pyear, pmonth, day, hour, minutes, seconds):
except ValueError: except ValueError:
tmpDate = False tmpDate = False
if tmpDate is False:
tmpDate = ""
return tmpDate return tmpDate
def _process_datetime(tmpDate, exif_type =True): def _process_datetime(tmpDate, exif_type =True):