diff options
author | Olivier Tilloy <olivier@tilloy.net> | 2009-08-07 17:48:13 +0200 |
---|---|---|
committer | Olivier Tilloy <olivier@tilloy.net> | 2009-08-07 17:48:13 +0200 |
commit | 47f9b236116b2073c7d3c93ebb847f8ea0d05a71 (patch) | |
tree | c5c9666425acbf186773ff33dd9dcf1d9b8caeca /src/pyexiv2.py | |
parent | d9cb2ac5e54b6126119c9f34f7268a1fc4deb3ad (diff) | |
download | pyexiv2-47f9b236116b2073c7d3c93ebb847f8ea0d05a71.tar.gz |
EXIF tag with a list of values notify the metadata container upon any change in the list.
Diffstat (limited to 'src/pyexiv2.py')
-rw-r--r-- | src/pyexiv2.py | 41 |
1 files changed, 37 insertions, 4 deletions
diff --git a/src/pyexiv2.py b/src/pyexiv2.py index 0bd180e..6b6ed69 100644 --- a/src/pyexiv2.py +++ b/src/pyexiv2.py @@ -468,7 +468,7 @@ class ExifValueError(ValueError): (self.type, self.value) -class ExifTag(MetadataTag): +class ExifTag(MetadataTag, ListenerInterface): """ An EXIF metadata tag. @@ -501,7 +501,10 @@ class ExifTag(MetadataTag): # May contain multiple values values = self.raw_value.split() if len(values) > 1: - self._value = map(self._convert_to_python, values) + # Make values a notifying list + values = map(self._convert_to_python, values) + self._value = NotifyingList(values) + self._value.register_listener(self) return self._value = self._convert_to_python(self.raw_value) @@ -510,19 +513,49 @@ class ExifTag(MetadataTag): def _set_value(self, new_value): if self.metadata is not None: - raw_value = self._convert_to_string(new_value) + if isinstance(new_value, (list, tuple)): + raw_values = map(self._convert_to_string, new_value) + raw_value = ' '.join(raw_values) + else: + raw_value = self._convert_to_string(new_value) self.metadata._set_exif_tag_value(self.key, raw_value) - self._value = new_value + + if isinstance(self._value, NotifyingList): + self._value.unregister_listener(self) + + if isinstance(new_value, NotifyingList): + # Already a notifying list + self._value = new_value + self._value.register_listener(self) + elif isinstance(new_value, (list, tuple)): + # Make the values a notifying list + self._value = NotifyingList(new_value) + self._value.register_listener(self) + else: + # Single value + self._value = new_value def _del_value(self): if self.metadata is not None: self.metadata._delete_exif_tag(self.key) + + if isinstance(self._value, NotifyingList): + self._value.unregister_listener(self) + del self._value """the value of the tag converted to its corresponding python type""" value = property(fget=_get_value, fset=_set_value, fdel=_del_value, doc=None) + def contents_changed(self): + """ + Implementation of the L{ListenerInterface}. + React on changes to the list of values of the tag. + """ + # self._value is a list of value and its contents changed. + self._set_value(self._value) + def _convert_to_python(self, value): """ Convert one raw value to its corresponding python type. |