summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortmzullinger <tmzullinger@f01d2545-417e-4e96-918e-98f8d0dbbcb6>2008-08-20 17:37:32 +0000
committertmzullinger <tmzullinger@f01d2545-417e-4e96-918e-98f8d0dbbcb6>2008-08-20 17:37:32 +0000
commita784f5941d57b692338782b1955f5721aaabaa7d (patch)
tree37bb6b8b5441a64777d5a2faca68326fc4777633
parent11917cb3864eba4e3314719523849868f8a127cc (diff)
downloadlibgpod-a784f5941d57b692338782b1955f5721aaabaa7d.tar.gz
libgpod-a784f5941d57b692338782b1955f5721aaabaa7d.tar.xz
libgpod-a784f5941d57b692338782b1955f5721aaabaa7d.zip
Update python bindings to work with the new thumbnail API.python-thumb-api-fix-v2
This removes sw_get_artwork_thumbnails() and the Thumbnail class from the python bindings. The get_pixbuf() function is now in the Photo class. git-svn-id: https://gtkpod.svn.sf.net/svnroot/gtkpod/libgpod/trunk@2108 f01d2545-417e-4e96-918e-98f8d0dbbcb6
-rw-r--r--ChangeLog12
-rwxr-xr-xbindings/python/examples/save_photos.py8
-rw-r--r--bindings/python/gpod.i.in18
-rw-r--r--bindings/python/ipod.py79
-rw-r--r--bindings/python/tests/tests.py5
5 files changed, 32 insertions, 90 deletions
diff --git a/ChangeLog b/ChangeLog
index 18e1380..44f6373 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2008-08-09 Todd Zullinger <tmzullinger at users.sourceforge.net>
+
+ * bindings/python/examples/save_photos.py
+ bindings/python/gpod.i.in
+ bindings/python/ipod.py
+ bindings/python/tests/tests.py:
+ Update python bindings to work with the new thumbnail API.
+
+ This removes sw_get_artwork_thumbnails() and the Thumbnail
+ class from the python bindings. The get_pixbuf() function
+ is now in the Photo class.
+
2008-08-09 Paul Richardson <phantom_sf at users.sourceforge.net>
* Added eclipse project related files to svn:ignore
diff --git a/bindings/python/examples/save_photos.py b/bindings/python/examples/save_photos.py
index ec8079b..c02a5ab 100755
--- a/bindings/python/examples/save_photos.py
+++ b/bindings/python/examples/save_photos.py
@@ -24,7 +24,7 @@
import gpod
-if not hasattr(gpod.Thumbnail, 'get_pixbuf'):
+if not hasattr(gpod.Photo, 'get_pixbuf'):
print 'Sorry, gpod was built without pixbuf support.'
raise SystemExit
@@ -35,9 +35,7 @@ for album in photodb.PhotoAlbums:
print " ", album
for photo in album:
print " ", photo
- for thumbnail, n in zip(photo.thumbnails,
- range(0,len(photo.thumbnails))):
- print " ", thumbnail
- thumbnail.get_pixbuf().save("/tmp/%d-%d.png" % (photo['id'],n),"png")
+ for w,h,s in ((0,0,'small'), (-1,-1,'large')):
+ photo.get_pixbuf(w,h).save("/tmp/%d-%s.png" % (photo['id'],s),"png")
photodb.close()
diff --git a/bindings/python/gpod.i.in b/bindings/python/gpod.i.in
index 4ac7e20..1b5d5f5 100644
--- a/bindings/python/gpod.i.in
+++ b/bindings/python/gpod.i.in
@@ -82,7 +82,6 @@ PyObject* sw_get_photoalbums(Itdb_PhotoDB *db);
PyObject* sw_get_photoalbum(GList *list, gint index);
PyObject* sw_get_photos(Itdb_PhotoDB *db);
PyObject* sw_get_photo(GList *list, gint index);
-PyObject* sw_get_artwork_thumbnails(Itdb_Artwork *artwork);
PyObject* sw_get_photoalbum_members(Itdb_PhotoAlbum *album);
PyObject* sw_ipod_device_to_dict(Itdb_Device *device);
void sw__track_extra_destroy (PyObject *data);
@@ -208,18 +207,6 @@ SWIGTYPE_p__Itdb_PhotoAlbum, 0));
return list;
}
- PyObject* sw_get_artwork_thumbnails(Itdb_Artwork *artwork) {
- PyObject *list;
- gint i;
- GList *l;
- list = PyList_New(g_list_length(artwork->thumbnails));
- for (l = artwork->thumbnails, i = 0; l; l = l->next, ++i) {
- PyList_SET_ITEM(list, i, SWIG_NewPointerObj((void*)(l->data), SWIGTYPE_p__Itdb_Thumb, 0));
- }
- return list;
- }
-
-
PyObject* sw_get_photoalbum(GList *list, gint index) {
GList *position;
if ( (index >= g_list_length(list)) || index < 0 ) {
@@ -489,7 +476,9 @@ typedef int gint;
#ifdef HAVE_PYGOBJECT
%typemap(out) gpointer itdb_artwork_get_pixbuf {
$result = pygobject_new((GObject *)$1);
- g_object_unref($1);
+ if ($1) {
+ g_object_unref($1);
+ }
}
%typemap(in) gpointer pixbuf {
@@ -515,7 +504,6 @@ PyObject* sw_get_photoalbum(GList *list, gint index);
PyObject* sw_get_photos(Itdb_PhotoDB *db);
PyObject* sw_get_photo(GList *list, gint index);
PyObject* sw_get_photoalbum_members(Itdb_PhotoAlbum *album);
-PyObject* sw_get_artwork_thumbnails(Itdb_Artwork *artwork);
PyObject* sw_ipod_device_to_dict(Itdb_Device *device);
%include "@top_srcdir@/src/itdb.h"
diff --git a/bindings/python/ipod.py b/bindings/python/ipod.py
index e5440d2..7048955 100644
--- a/bindings/python/ipod.py
+++ b/bindings/python/ipod.py
@@ -964,69 +964,18 @@ class Photo:
else:
raise KeyError('No such key: %s' % item)
- def get_thumbnails(self):
- return [Thumbnail(proxied_thumbnail=t,
- ownerobject=self) for t in gpod.sw_get_artwork_thumbnails(
- self._photo)]
-
- thumbnails = property(get_thumbnails)
-
-class Thumbnail:
- """A thumbnail in an Photo."""
-
- _proxied_attributes = [k for k in gpod._Itdb_Thumb.__dict__.keys()
- if not (k.startswith("_") or k.startswith("reserved"))]
-
- def __init__(self, proxied_thumbnail=None, ownerobject=None):
- """Create a thumbnail object."""
-
- if not proxied_thumbnail:
- raise NotImplemented("Can't create new Thumbnails from scratch, create Photos instead")
-
- self._thumbnail = proxied_thumbnail
- self.__ownerobject = ownerobject
-
- def __str__(self):
- return self.__repr__()
-
- def __repr__(self):
- return "<Thumbnail Filename:%s Size:%d Width:%d Height:%d>" % (
- repr(self['filename']),
- self['size'],
- self['width'],
- self['height'])
-
- def keys(self):
- return list(self._proxied_attributes)
-
- def items(self):
- return [self[k] for k in self._proxied_attributes]
-
- def pairs(self):
- return [(k, self[k]) for k in self._proxied_attributes]
-
- def __getitem__(self, item):
- if item in self._proxied_attributes:
- return getattr(self._thumbnail, item)
- else:
- raise KeyError('No such key: %s' % item)
-
- def __setitem__(self, item, value):
- if type(value) == types.UnicodeType:
- value = value.encode('UTF-8','replace')
- if item in self._proxied_attributes:
- return setattr(self._thumbnail, item, value)
- else:
- raise KeyError('No such key: %s' % item)
-
if pixbuf_support:
- def get_pixbuf(self):
- # this deals with coverart and photo albums
- if hasattr(self.__ownerobject._database,"_itdb"):
- return gpod.itdb_artwork_get_pixbuf(
- self.__ownerobject._database._itdb.device,
- self._thumbnail)
- else:
- return gpod.itdb_artwork_get_pixbuf(
- self.__ownerobject._database.device,
- self._thumbnail)
+ def get_pixbuf(self, width=-1, height=-1):
+ """Get a pixbuf from a Photo.
+
+ width: the width of the pixbuf to retrieve, -1 for the biggest
+ possible size and 0 for the smallest possible size (with no scaling)
+
+ height: the height of the pixbuf to retrieve, -1 for the biggest
+ possible size and 0 for the smallest possible size (with no scaling)
+ """
+ device = self._database.device
+ if hasattr(self._database,"_itdb"):
+ device = self._database._itdb.device
+ return gpod.itdb_artwork_get_pixbuf(device, self._photo,
+ width, height)
diff --git a/bindings/python/tests/tests.py b/bindings/python/tests/tests.py
index f52015e..6efb114 100644
--- a/bindings/python/tests/tests.py
+++ b/bindings/python/tests/tests.py
@@ -182,10 +182,5 @@ class TestPhotoDatabase(unittest.TestCase):
for album in self.db.PhotoAlbums:
[photo for photo in album]
- def testEnumeratePhotosThumbs(self):
- for album in self.db.PhotoAlbums:
- for photo in album:
- [thumb for thumb in photo.thumbnails]
-
if __name__ == '__main__':
unittest.main()