Removed a duplicate function. Removed some set.size_requests as possible without destroying the layout of the Edit window.

svn: r17902
This commit is contained in:
Rob G. Healey 2011-07-07 19:19:30 +00:00
parent dc469aed0b
commit 2514f1dc77

View File

@ -378,17 +378,16 @@ class EditExifMetadata(Gramplet):
label.show() label.show()
# 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 =True, padding =0)
# Thumbnail, ImageType, and Convert buttons... # 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 =True, padding =5)
new_hbox.show() new_hbox.show()
# Thumbnail button... # Thumbnail button...
event_box = gtk.EventBox() event_box = gtk.EventBox()
event_box.set_size_request(90, 30) new_hbox.pack_start(event_box, expand =False, fill =True, padding =5)
new_hbox.pack_start(event_box, expand =False, fill =False, padding =0)
event_box.show() event_box.show()
button = self.__create_button( button = self.__create_button(
@ -398,9 +397,8 @@ class EditExifMetadata(Gramplet):
# Image Type... # Image Type...
event_box = gtk.EventBox() event_box = gtk.EventBox()
event_box.set_size_request(160, 30) event_box.set_size_request(150, 30)
new_hbox.pack_start(event_box, expand =False, fill =False, padding =0) new_hbox.pack_start(event_box, expand =False, fill =True, padding =5)
self.exif_widgets["ImageTypeBox"] = event_box
event_box.show() event_box.show()
combo_box = gtk.combo_box_new_text() combo_box = gtk.combo_box_new_text()
@ -412,8 +410,7 @@ class EditExifMetadata(Gramplet):
# Convert button... # Convert button...
event_box = gtk.EventBox() event_box = gtk.EventBox()
event_box.set_size_request(100, 30) new_hbox.pack_start(event_box, expand =False, fill =True, padding =5)
new_hbox.pack_start(event_box, expand =False, fill =False, padding =0)
event_box.show() event_box.show()
button = self.__create_button( button = self.__create_button(
@ -427,7 +424,7 @@ class EditExifMetadata(Gramplet):
# Help, Edit, and Delete horizontal box # Help, Edit, and Delete horizontal box
hed_box = gtk.HButtonBox() hed_box = gtk.HButtonBox()
hed_box.set_layout(gtk.BUTTONBOX_START) hed_box.set_layout(gtk.BUTTONBOX_START)
main_vbox.pack_start(hed_box, expand =False, fill =False, padding =5) main_vbox.pack_start(hed_box, expand =False, fill =True, padding =5)
# Help button... # Help button...
hed_box.add( self.__create_button( hed_box.add( self.__create_button(
@ -458,8 +455,8 @@ class EditExifMetadata(Gramplet):
""" """
top = gtk.TreeView() top = gtk.TreeView()
titles = [(_('Key'), 1, 180), titles = [(_('Key'), 1, 160),
(_('Value'), 2, 310)] (_('Value'), 2, 290)]
self.model = ListModel(top, titles, list_mode="tree") self.model = ListModel(top, titles, list_mode="tree")
return top return top
@ -477,6 +474,7 @@ class EditExifMetadata(Gramplet):
""" """
db = self.dbstate.db db = self.dbstate.db
# self.update()
# display all button tooltips only... # display all button tooltips only...
# 1st argument is for Fields, 2nd argument is for Buttons... # 1st argument is for Fields, 2nd argument is for Buttons...
@ -538,18 +536,18 @@ class EditExifMetadata(Gramplet):
# if image file type is not an Exiv2 acceptable image type, offer to convert it.... # if image file type is not an Exiv2 acceptable image type, offer to convert it....
if self.extension not in _VALIDIMAGEMAP.values(): if self.extension not in _VALIDIMAGEMAP.values():
self.activate_buttons(["ImageType"])
# remove the extension out of the list of convertible image types... imageconvert_ = _validconvert
# What would make sense to be able to convert to your current image type? if self.extension in imageconvert_:
PILConvert = _validconvert imageconvert_.remove(self.extension)
if self.extension in PILConvert: self._VCONVERTMAP = dict( (index, imgtype_) for index, imgtype_ in enumerate(imageconvert_) )
PILConvert.remove(self.extension)
self._VCONVERTMAP = dict( (index, imgtype_) for index, imgtype_ in enumerate(PILConvert) )
for imgtype_ in self._VCONVERTMAP.values(): for imgtype_ in self._VCONVERTMAP.values():
self.exif_widgets["ImageType"].append_text(imgtype_) self.exif_widgets["ImageType"].append_text(imgtype_)
self.exif_widgets["ImageType"].set_active(0) self.exif_widgets["ImageType"].set_active(0)
self.activate_buttons(["ImageType"]) else:
self.activate_buttons(["Edit"])
# determine if it is a mime image object? # determine if it is a mime image object?
if mime_type: if mime_type:
@ -601,23 +599,25 @@ class EditExifMetadata(Gramplet):
self.exif_widgets["MessageArea"].set_text(_("Please choose a different image...")) self.exif_widgets["MessageArea"].set_text(_("Please choose a different image..."))
return return
def __display_exif_tags(self): def __display_exif_tags(self, metadatatags_ =None):
""" """
Display the exif tags. Display the exif tags.
""" """
metadatatags_ = _get_exif_keypairs(self.plugin_image) metadatatags_ = _get_exif_keypairs(self.plugin_image)
if not metadatatags_: if not metadatatags_:
self.exif_widgets["MessageArea"].set_text(_("No Exif metadata for this image..."))
self.set_has_data(False)
return return
if OLD_API: # prior to v0.2.0 if OLD_API: # prior to v0.2.0
try: try:
self.plugin_image.readMetadata() self.plugin_image.readMetadata()
metadata_yes = True has_metadata = True
except (IOError, OSError): except (IOError, OSError):
metadata_yes = False has_metadata = False
if metadata_yes: if has_metadata:
for section, key, key2, func in TAGS_: for section, key, key2, func in TAGS_:
if key in metadatatags_: if key in metadatatags_:
if section not in self.sections: if section not in self.sections:
@ -639,11 +639,11 @@ class EditExifMetadata(Gramplet):
else: # v0.2.0 and above else: # v0.2.0 and above
try: try:
self.plugin_image.read() self.plugin_image.read()
metadata_yes = True has_metadata = True
except (IOError, OSError): except (IOError, OSError):
metadata_yes = False has_metadata = False
if metadata_yes: if has_metadata:
for section, key, key2, func in TAGS_: for section, key, key2, func in TAGS_:
if key in metadatatags_: if key in metadatatags_:
if section not in self.sections: if section not in self.sections:
@ -661,6 +661,12 @@ class EditExifMetadata(Gramplet):
self.model.add((tag.label, human_value), node =node) self.model.add((tag.label, human_value), node =node)
self.model.tree.expand_all() self.model.tree.expand_all()
# update has_data functionality...
self.set_has_data(self.model.count > 0)
# activate these buttons...
self.activate_buttons(["Delete"])
def changed_cb(self, object): def changed_cb(self, object):
""" """
will show the Convert Button once an Image Type has been selected, and if will show the Convert Button once an Image Type has been selected, and if
@ -758,83 +764,6 @@ class EditExifMetadata(Gramplet):
return False return False
def display_metadata(self, media):
"""
displays all of the image's Exif metadata in a grey-shaded tree view...
"""
metadatatags_ = _get_exif_keypairs(self.plugin_image)
if not metadatatags_:
self.exif_widgets["MessageArea"].set_text(_("No Exif metadata for this image..."))
self.set_has_data(False)
return
# clear display area...
self.model.clear()
# set Message Area to Display...
self.exif_widgets["MessageArea"].set_text(_("Displaying all Exif metadata keypairs..."))
# pylint: disable-msg=E1101
full_path = Utils.media_path_full(self.dbstate.db, media.get_path())
if OLD_API: # prior to v0.2.0
try:
metadata = pyexiv2.Image(full_path)
except IOError:
self.set_has_data(False)
return
metadata.readMetadata()
for section, key, key2, func in TAGS:
if key in metadata.exifKeys():
if section not in self.sections:
node = self.model.add([section, ''])
self.sections[section] = node
else:
node = self.sections[section]
label = metadata.tagDetails(key)[0]
if func:
human_value = func(metadata[key])
else:
human_value = metadata.interpretedExifValue(key)
if key2:
human_value += ' ' + metadata.interpretedExifValue(key2)
self.model.add((label, human_value), node =node)
self.model.tree.expand_all()
else: # v0.2.0 and above
metadata = pyexiv2.ImageMetadata(full_path)
try:
metadata.read()
except IOError:
self.set_has_data(False)
return
for section, key, key2, func in TAGS:
if key in metadatatags_:
if section not in self.sections:
node = self.model.add([section, ''])
self.sections[section] = node
else:
node = self.sections[section]
tag = metadata[key]
if func:
human_value = func(tag.value)
else:
human_value = tag.human_value
if key2:
human_value += ' ' + metadata[key2].human_value
self.model.add((tag.label, human_value), node=node)
self.model.tree.expand_all()
self.set_has_data(self.model.count > 0)
# activate Delete button...
self.activate_buttons(["Delete"])
self.exif_widgets["Total"].set_text(_("Number of Key/ Value pairs : %04d") % self.model.count)
def __create_button(self, pos, text, callback =[], icon =False, sensitive =False): 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
@ -1051,7 +980,7 @@ class EditExifMetadata(Gramplet):
# check for new destination and if source image file is removed? # check for new destination and if source image file is removed?
if (os.path.isfile(newfilepath) and not os.path.isfile(full_path) ): if (os.path.isfile(newfilepath) and not os.path.isfile(full_path) ):
self.update_media_path(newfilepath) self.__update_media_path(newfilepath)
else: else:
self.exif_widgets["MessageArea"].set_text(_("There has been an error, " self.exif_widgets["MessageArea"].set_text(_("There has been an error, "
"Please check your source and destination file paths...")) "Please check your source and destination file paths..."))
@ -1077,12 +1006,12 @@ class EditExifMetadata(Gramplet):
if newfilepath: if newfilepath:
# update the media object path... # update the media object path...
self.update_media_path(newfilepath) self.__update_media_path(newfilepath)
else: else:
self.exif_widgets["MessageArea"].set_text(_("There was an error " self.exif_widgets["MessageArea"].set_text(_("There was an error "
"in converting your image file.")) "in converting your image file."))
def update_media_path(self, newfilepath =None): def __update_media_path(self, newfilepath =None):
""" """
update the media object's media path. update the media object's media path.
""" """
@ -1170,7 +1099,7 @@ class EditExifMetadata(Gramplet):
# create a new scrolled window. # create a new scrolled window.
scrollwindow = gtk.ScrolledWindow() scrollwindow = gtk.ScrolledWindow()
scrollwindow.set_border_width(10) scrollwindow.set_border_width(10)
scrollwindow.set_size_request(520, 500) # scrollwindow.set_size_request(520, 500)
scrollwindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) scrollwindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
self.edtarea.add(scrollwindow) self.edtarea.add(scrollwindow)
@ -1380,7 +1309,7 @@ class EditExifMetadata(Gramplet):
# Save button... # Save button...
hsccc_box.add(self.__create_button( hsccc_box.add(self.__create_button(
"Save", False, [self.save_metadata, self.update, self.display_metadata], "Save", False, [self.save_metadata, self.update, self.__display_exif_tags],
gtk.STOCK_SAVE, True) ) gtk.STOCK_SAVE, True) )
# Clear button... # Clear button...
@ -1677,7 +1606,7 @@ class EditExifMetadata(Gramplet):
# Modify Date/ Time... # Modify Date/ Time...
elif widgetname_ == "Modified": elif widgetname_ == "Modified":
date1 = self.dates["Modified"] date1 = self.dates["Modified"]
widgetvalue_ = date1 if date1 is not None else datetime.now() widgetvalue_ = date1 if date1 is not None else datetime.datetime.now()
self._set_value(_DATAMAP[widgetname_], widgetvalue_) self._set_value(_DATAMAP[widgetname_], widgetvalue_)
# display modified date in its cell... # display modified date in its cell...