aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier Tilloy <olivier@tilloy.net>2009-11-05 09:52:43 +0100
committerOlivier Tilloy <olivier@tilloy.net>2009-11-05 09:52:43 +0100
commit5ee4579755d346122b7eb818f6c5a30290e87be2 (patch)
treebf2c5ecc0bb7dc8c827e4c31820afac52c45f47d
parenta40fa3744742d67b87bb5c04d0ad33a426d3f314 (diff)
downloadpyexiv2-5ee4579755d346122b7eb818f6c5a30290e87be2.tar.gz
Renamed ExifTag's _value to _raw_value.
Value and raw value setters.
-rw-r--r--src/exiv2wrapper.cpp10
-rw-r--r--src/exiv2wrapper.hpp6
-rw-r--r--src/exiv2wrapper_python.cpp4
-rw-r--r--src/pyexiv2/exif2.py68
4 files changed, 63 insertions, 25 deletions
diff --git a/src/exiv2wrapper.cpp b/src/exiv2wrapper.cpp
index 96c840a..ce0c7fc 100644
--- a/src/exiv2wrapper.cpp
+++ b/src/exiv2wrapper.cpp
@@ -480,13 +480,13 @@ ExifTag::ExifTag(const std::string& key): _key(key), _datum(_key)
_description = Exiv2::ExifTags::tagDesc(tag, ifd);
_sectionName = Exiv2::ExifTags::sectionName(tag, ifd);
_sectionDescription = Exiv2::ExifTags::sectionDesc(tag, ifd);
- _value = _datum.toString();
+ _raw_value = _datum.toString();
}
-void ExifTag::setValue(const std::string& value)
+void ExifTag::setRawValue(const std::string& value)
{
_datum.setValue(value);
- _value = _datum.toString();
+ _raw_value = _datum.toString();
}
const std::string ExifTag::getKey()
@@ -529,9 +529,9 @@ const std::string ExifTag::getSectionDescription()
return _sectionDescription;
}
-const std::string ExifTag::getValue()
+const std::string ExifTag::getRawValue()
{
- return _value;
+ return _raw_value;
}
diff --git a/src/exiv2wrapper.hpp b/src/exiv2wrapper.hpp
index 8f593a8..9ea95e4 100644
--- a/src/exiv2wrapper.hpp
+++ b/src/exiv2wrapper.hpp
@@ -162,7 +162,7 @@ public:
// Constructor
ExifTag(const std::string& key);
- void setValue(const std::string& value);
+ void setRawValue(const std::string& value);
const std::string getKey();
const std::string getType();
@@ -172,7 +172,7 @@ public:
const std::string getDescription();
const std::string getSectionName();
const std::string getSectionDescription();
- const std::string getValue();
+ const std::string getRawValue();
private:
Exiv2::ExifKey _key;
@@ -184,7 +184,7 @@ private:
std::string _description;
std::string _sectionName;
std::string _sectionDescription;
- std::string _value;
+ std::string _raw_value;
};
diff --git a/src/exiv2wrapper_python.cpp b/src/exiv2wrapper_python.cpp
index 54967a5..88c1353 100644
--- a/src/exiv2wrapper_python.cpp
+++ b/src/exiv2wrapper_python.cpp
@@ -78,7 +78,7 @@ BOOST_PYTHON_MODULE(libexiv2python)
class_<ExifTag>("ExifTag", init<std::string>())
- .def("_setValue", &ExifTag::setValue)
+ .def("_setRawValue", &ExifTag::setRawValue)
.def("_getKey", &ExifTag::getKey)
.def("_getType", &ExifTag::getType)
@@ -88,7 +88,7 @@ BOOST_PYTHON_MODULE(libexiv2python)
.def("_getDescription", &ExifTag::getDescription)
.def("_getSectionName", &ExifTag::getSectionName)
.def("_getSectionDescription", &ExifTag::getSectionDescription)
- .def("_getValue", &ExifTag::getValue)
+ .def("_getRawValue", &ExifTag::getRawValue)
;
class_<IptcTag>("IptcTag", init<std::string>())
diff --git a/src/pyexiv2/exif2.py b/src/pyexiv2/exif2.py
index d73c072..cae290d 100644
--- a/src/pyexiv2/exif2.py
+++ b/src/pyexiv2/exif2.py
@@ -26,7 +26,7 @@
import libexiv2python
-from pyexiv2.utils import Rational
+from pyexiv2.utils import Rational, NotifyingList, ListenerInterface
import time
import datetime
@@ -52,7 +52,7 @@ class ExifValueError(ValueError):
(self.type, self.value)
-class ExifTag(libexiv2python.ExifTag):
+class ExifTag(libexiv2python.ExifTag, ListenerInterface):
"""
DOCME
@@ -71,20 +71,13 @@ class ExifTag(libexiv2python.ExifTag):
"""
DOCME
"""
- #libexiv2python.ExifTag.__init__(key)
super(ExifTag, self).__init__(key)
if value is not None:
self._set_value(value)
else:
self._raw_value = None
self._value = None
-
- def _convert_to_string(self, value):
- """
- DOCME
- """
- # TODO: implement me
- return str(value)
+ self.metadata = None
@property
def key(self):
@@ -118,16 +111,59 @@ class ExifTag(libexiv2python.ExifTag):
def section_description(self):
return self._getSectionDescription()
+ def _get_raw_value(self):
+ return self._raw_value
+
+ def _set_raw_value(self, value):
+ self._raw_value = value
+ if self.type in ('Short', 'Long', 'SLong', 'Rational', 'SRational'):
+ # May contain multiple values
+ values = value.split()
+ if len(values) > 1:
+ # 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(value)
+
+ raw_value = property(fget=_get_raw_value, fset=_set_raw_value, doc=None)
+
def _get_value(self):
return self._value
- def _set_value(self, new_value):
- self._value = new_value
- self._raw_value = self._convert_to_string(new_value)
- self._setValue(self._raw_value)
+ def _set_value(self, value):
+ if isinstance(value, (list, tuple)):
+ raw_values = map(self._convert_to_string, value)
+ self._raw_value = ' '.join(raw_values)
+ else:
+ self._raw_value = self._convert_to_string(value)
+ self._setRawValue(self._raw_value)
+
+ if self.metadata is not None:
+ self.metadata._set_exif_tag_value(self.key, self._raw_value)
+
+ if isinstance(self._value, NotifyingList):
+ self._value.unregister_listener(self)
+
+ if isinstance(value, NotifyingList):
+ # Already a notifying list
+ self._value = value
+ self._value.register_listener(self)
+ elif isinstance(value, (list, tuple)):
+ # Make the values a notifying list
+ self._value = NotifyingList(value)
+ self._value.register_listener(self)
+ else:
+ # Single value
+ self._value = value
value = property(fget=_get_value, fset=_set_value, doc=None)
+ # Implement the ListenerInterface
+ def contents_changed(self):
+ raise NotImplementedError('TODO: implement me!')
+
def _convert_to_python(self, value):
"""
Convert one raw value to its corresponding python type.
@@ -298,7 +334,9 @@ class ExifTag(libexiv2python.ExifTag):
@rtype: C{str}
"""
left = '%s [%s]' % (self.key, self.type)
- if self.type == 'Undefined' and len(self._value) > 100:
+ if self._value is None:
+ right = '(No value)'
+ elif self.type == 'Undefined' and len(self._value) > 100:
right = '(Binary value suppressed)'
else:
#right = self.fvalue