diff options
author | Olivier Tilloy <olivier@tilloy.net> | 2009-11-15 21:41:03 +0100 |
---|---|---|
committer | Olivier Tilloy <olivier@tilloy.net> | 2009-11-15 21:41:03 +0100 |
commit | da5c442517be8fa5ce996830385569995fdfc9a8 (patch) | |
tree | 3fcc8d43e2315e426c263f8583bc25289af006ce | |
parent | 7a354b4495f7940f75b2bdf61732a0e166b7b2a0 (diff) | |
download | pyexiv2-da5c442517be8fa5ce996830385569995fdfc9a8.tar.gz |
ExifTag doesn't inherit from libexiv2python._ExifTag anymore, it keeps a reference to it as a protected attribute.
-rw-r--r-- | src/exiv2wrapper_python.cpp | 2 | ||||
-rw-r--r-- | src/pyexiv2/exif.py | 39 | ||||
-rw-r--r-- | src/pyexiv2/metadata.py | 3 |
3 files changed, 28 insertions, 16 deletions
diff --git a/src/exiv2wrapper_python.cpp b/src/exiv2wrapper_python.cpp index 0ff5e32..1c2bdf9 100644 --- a/src/exiv2wrapper_python.cpp +++ b/src/exiv2wrapper_python.cpp @@ -45,7 +45,7 @@ BOOST_PYTHON_MODULE(libexiv2python) register_exception_translator<Exiv2::Error>(&translateExiv2Error); - class_<ExifTag>("ExifTag", init<std::string>()) + class_<ExifTag>("_ExifTag", init<std::string>()) .def("_setRawValue", &ExifTag::setRawValue) diff --git a/src/pyexiv2/exif.py b/src/pyexiv2/exif.py index 9a0b0cb..b6aae32 100644 --- a/src/pyexiv2/exif.py +++ b/src/pyexiv2/exif.py @@ -52,7 +52,7 @@ class ExifValueError(ValueError): (self.type, self.value) -class ExifTag(libexiv2python.ExifTag, ListenerInterface): +class ExifTag(ListenerInterface): """ DOCME @@ -67,49 +67,60 @@ class ExifTag(libexiv2python.ExifTag, ListenerInterface): _date_formats = ('%Y:%m:%d',) - def __init__(self, key, value=None): + def __init__(self, key, value=None, _tag=None): """ DOCME """ - super(ExifTag, self).__init__(key) + super(ExifTag, self).__init__() + if _tag is not None: + self._tag = _tag + else: + self._tag = libexiv2python._ExifTag(key) + self.metadata = None if value is not None: self._set_value(value) else: self._raw_value = None self._value = None - self.metadata = None + + @staticmethod + def _from_existing_tag(_tag): + # Build a tag from an already existing _ExifTag + tag = ExifTag(_tag._getKey(), _tag=_tag) + tag.raw_value = _tag._getRawValue() + return tag @property def key(self): - return self._getKey() + return self._tag._getKey() @property def type(self): - return self._getType() + return self._tag._getType() @property def name(self): - return self._getName() + return self._tag._getName() @property def title(self): - return self._getTitle() + return self._tag._getTitle() @property def label(self): - return self._getLabel() + return self._tag._getLabel() @property def description(self): - return self._getDescription() + return self._tag._getDescription() @property def section_name(self): - return self._getSectionName() + return self._tag._getSectionName() @property def section_description(self): - return self._getSectionDescription() + return self._tag._getSectionDescription() def _get_raw_value(self): return self._raw_value @@ -138,7 +149,7 @@ class ExifTag(libexiv2python.ExifTag, ListenerInterface): self._raw_value = ' '.join(raw_values) else: self._raw_value = self._convert_to_string(value) - self._setRawValue(self._raw_value) + self._tag._setRawValue(self._raw_value) if self.metadata is not None: self.metadata._set_exif_tag_value(self.key, self._raw_value) @@ -162,7 +173,7 @@ class ExifTag(libexiv2python.ExifTag, ListenerInterface): @property def human_value(self): - return self._getHumanValue() or None + return self._tag._getHumanValue() or None # Implement the ListenerInterface def contents_changed(self): diff --git a/src/pyexiv2/metadata.py b/src/pyexiv2/metadata.py index fce964b..87db409 100644 --- a/src/pyexiv2/metadata.py +++ b/src/pyexiv2/metadata.py @@ -103,7 +103,8 @@ class ImageMetadata(object): try: return self._tags['exif'][key] except KeyError: - tag = ExifTag(*self._image.getExifTag(key)) + _tag = self._image.getExifTag(key) + tag = ExifTag._from_existing_tag(_tag) tag.metadata = self self._tags['exif'][key] = tag return tag |