Загрузка изобращения из сети

text/x-python load_image.py — 1.3 KB

Содержимое файла

"""
Using the asynchronous data loader

How to do it…
We need only a Python file and the URL in this recipe. To complete the recipe:
1. Import the usual kivy package.
2. Import the Image and Loader packages.
3. Import the Widget package.
4. Define the e2App class.
5. Define the _image_Loaded() method, which loads the image in the app.
6. Define the build() method.
7. In this method, load the image in a proxy image.
8. Define the image variable instanced as Image().
9. Return the image variable to display the load image:
"""
import kivy
kivy.require('1.9.0')
from kivy.app import App
from kivy.uix.image import Image
from kivy.loader import Loader

class e2App(App):
	#We bind the event on_load to the variable proxyImage:
	def _image_loaded(self, proxyImage):
		if proxyImage.image.texture:
			self.image.texture = proxyImage.image.texture
	def build(self):
		#loads the image
		proxyImage = Loader.image(
		'http://ontogovorun.ru:8080/Plone/resursy/greger5.png/@@images/6566e547-bdb1-44d5-8c59-54a2085c5532.png')
		#We assign the image to the proxyImage variable because we are not 
		#sure if the image exists or could be retrieved from the Web. 
		#We have the following line:
		proxyImage.bind(on_load=self._image_loaded)
		self.image = Image()
		return self.image
if __name__ == '__main__':
	e2App().run()