2011-06-19 17:42:40 +00:00
|
|
|
'''
|
|
|
|
Pictures demo
|
|
|
|
=============
|
|
|
|
|
|
|
|
This is a basic picture viewer, using the scatter widget.
|
|
|
|
'''
|
|
|
|
|
2011-04-21 17:22:17 +00:00
|
|
|
import kivy
|
|
|
|
kivy.require('1.0.6')
|
|
|
|
|
|
|
|
from glob import glob
|
|
|
|
from random import randint
|
2011-03-29 16:08:07 +00:00
|
|
|
from os.path import join, dirname
|
2011-02-22 23:21:35 +00:00
|
|
|
from kivy.app import App
|
2011-04-21 17:22:17 +00:00
|
|
|
from kivy.logger import Logger
|
2011-02-22 23:21:35 +00:00
|
|
|
from kivy.uix.scatter import Scatter
|
2011-04-21 17:22:17 +00:00
|
|
|
from kivy.properties import StringProperty
|
|
|
|
# FIXME this shouldn't be necessary
|
|
|
|
from kivy.core.window import Window
|
|
|
|
|
|
|
|
|
|
|
|
class Picture(Scatter):
|
2011-06-19 17:42:40 +00:00
|
|
|
'''Picture is the class that will show the image with a white border and a
|
|
|
|
shadow. They are nothing here because almost everything is inside the
|
|
|
|
picture.kv. Check the rule named <Picture> inside the file, and you'll see
|
|
|
|
how the Picture() is really constructed and used.
|
|
|
|
|
|
|
|
The source property will be the filename to show.
|
|
|
|
'''
|
2011-02-22 23:21:35 +00:00
|
|
|
|
2011-04-21 17:22:17 +00:00
|
|
|
source = StringProperty(None)
|
2011-02-22 23:21:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
class PicturesApp(App):
|
2011-04-21 17:22:17 +00:00
|
|
|
|
2011-02-22 23:21:35 +00:00
|
|
|
def build(self):
|
2011-04-21 17:22:17 +00:00
|
|
|
|
|
|
|
# the root is created in pictures.kv
|
|
|
|
root = self.root
|
|
|
|
|
|
|
|
# get any files into images directory
|
2011-03-29 16:08:07 +00:00
|
|
|
curdir = dirname(__file__)
|
2011-04-21 17:22:17 +00:00
|
|
|
for filename in glob(join(curdir, 'images', '*')):
|
|
|
|
try:
|
|
|
|
# load the image
|
|
|
|
picture = Picture(source=filename, rotation=randint(-30,30))
|
|
|
|
# add to the main field
|
|
|
|
root.add_widget(picture)
|
|
|
|
except Exception, e:
|
|
|
|
Logger.exception('Pictures: Unable to load <%s>' % filename)
|
|
|
|
|
2012-03-11 01:16:02 +00:00
|
|
|
def on_pause(self):
|
|
|
|
return True
|
|
|
|
|
2011-02-22 23:21:35 +00:00
|
|
|
|
|
|
|
if __name__ in ('__main__', '__android__'):
|
|
|
|
PicturesApp().run()
|
|
|
|
|