Skip to content

Instantly share code, notes, and snippets.

@Zen-CODE
Last active December 20, 2015 14:39
Show Gist options
  • Save Zen-CODE/6147929 to your computer and use it in GitHub Desktop.
Save Zen-CODE/6147929 to your computer and use it in GitHub Desktop.
Example of asynchronous image loading and stopping
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.image import AsyncImage, Image
from kivy.loader import Loader
from kivy.clock import Clock
class TestApp(App):
'''Demonstrate the mechanics of managing asynchronous image loading'''
def _image_loaded(self, proxyImage):
'''Fired once the image is loaded and ready to use'''
if proxyImage.image.texture:
self.image.texture = proxyImage.image.texture
def _cancel_loading(self, dt):
'''Stop the image from loading'''
Loader.stop() # It looks like this would stop all other
# ProxyImages loading too.
def build(self):
'''Build and return the main Image widget'''
proxyImage = Loader.image("e:/Zen/My Pictures/Computer/Aqua Blue.jpg")
proxyImage.bind(on_load=self._image_loaded)
self.image = Image()
# Uncomment the line below to close the background loading threads
# Clock.schedule_once(self._cancel_loading, 0.1)
return self.image
if __name__ == '__main__':
TestApp().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment