kivy/kivy — pull request #985 by meric (2013-02-26 03:02:12+00:00)
Title: Made ImageLoader.zip_loader skip loaders that raised an error or returned None.

For some reason one of the image loaders was failing on Mac OS X. Running the widgets/sequence_images example:

[DEBUG ] [ImageImageIO] Load from
[WARNING] [Image ] Unable to load image in zip trying to continue...
[DEBUG ] [ImageImageIO] Load from
[WARNING] [Image ] Unable to load image in zip trying to continue...
[DEBUG ] [ImageImageIO] Load from
[WARNING] [Image ] Unable to load image in zip trying to continue...
[DEBUG ] [ImageImageIO] Load from
[WARNING] [Image ] Unable to load image in zip trying to continue...
[DEBUG ] [ImageImageIO] Load from
[WARNING] [Image ] Unable to load image in zip trying to continue...
[DEBUG ] [ImageImageIO] Load from
[WARNING] [Image ] Unable to load image in zip trying to continue...
[DEBUG ] [ImageImageIO] Load from
[WARNING] [Image ] Unable to load image in zip trying to continue...
[DEBUG ] [ImageImageIO] Load from
[WARNING] [Image ] Unable to load image in zip trying to continue...
[DEBUG ] [ImageImageIO] Load from
[WARNING] [Image ] Unable to load image in zip trying to continue...
[DEBUG ] [ImageImageIO] Load from
[WARNING] [Image ] Unable to load image in zip trying to continue...
[DEBUG ] [ImageImageIO] Load from
[WARNING] [Image ] Unable to load image in zip trying to continue...
[DEBUG ] [ImageImageIO] Load from
[WARNING] [Image ] Unable to load image in zip trying to continue...
[DEBUG ] [ImageImageIO] Load from
[WARNING] [Image ] Unable to load image in zip trying to continue...
[DEBUG ] [ImageImageIO] Load from
[WARNING] [Image ] Unable to load image in zip trying to continue...
[DEBUG ] [ImageImageIO] Load from
[WARNING] [Image ] Unable to load image in zip trying to continue...
Traceback (most recent call last):
File "main.py", line 147, in
mainApp().run()
File "/Library/Python/2.7/site-packages/kivy/app.py", line 527, in run
root = self.build()
File "main.py", line 140, in build
upl = mainclass()
File "main.py", line 76, in __init__
background_normal = 'data/images/button_white_animated.zip')
File "/Users/Eric/Projects/kivy/examples/widgets/sequenced_images/uix/custom_button.py", line 42, in __init__
keep_ratio = self.keep_ratio, mipmap = True)
File "/Library/Python/2.7/site-packages/kivy/uix/image.py", line 219, in __init__
self.texture_update()
File "/Library/Python/2.7/site-packages/kivy/uix/image.py", line 234, in texture_update
nocache=self.nocache)
File "/Library/Python/2.7/site-packages/kivy/core/image/__init__.py", line 418, in __init__
self.filename = arg
File "/Library/Python/2.7/site-packages/kivy/core/image/__init__.py", line 606, in _set_filename
mipmap=self._mipmap, nocache=self._nocache)
File "/Library/Python/2.7/site-packages/kivy/core/image/__init__.py", line 339, in load
return ImageLoader.zip_loader(filename)
File "/Library/Python/2.7/site-packages/kivy/core/image/__init__.py", line 276, in zip_loader
raise Exception('no images in zip <%s>' % filename)
Exception: no images in zip

However, wrapping the:

im = loader(tmpfile, **kwargs)

in `try...except` was not enough.

Sometimes there was an image not recognized by any loader. (e.g. an artefact from the zip program while performing the zipping), and if that artefact turns out to be the last file attempted to be loaded, `im` in:

im._data = image_data

would be `None`, causing an AttributeError.

So I've had to change it to use another variable `image` to keep track of the last image successfully loaded. It is only assigned when `im` returned from the loader is not `None`.