import kivy
kivy.require('1.0.6')
from glob import glob
from random import randint
from os.path import join, dirname
from kivy.logger import Logger
from kivy.uix.scatter import Scatter
from kivy.properties import StringProperty
# FIXME this shouldn't be necessary
from kivy.core.window import Window
from kivy.clock import Clock
from kivy.uix.label import Label
class Picture(Scatter):
source = StringProperty(None)
class PicturesApp(App):
def build(self):
# the root is created in pictures.kv
root = self.root
self.root.on_touch_move = self.on_touch_move
self.fps_label = Label(halign='left')
self.root.add_widget(self.fps_label)
Clock.schedule_interval(self.set_fps, 1.0/60)
# get any files into images directory
curdir = dirname(__file__)
for filename in glob(join(curdir, 'images', '*')):
try:
# load the image
for x in range(100):
picture = Picture(source=filename, rotation=randint(-30,30), pos=(randint(0,400), randint(0,400)))
# add to the main field
root.add_widget(picture)
except Exception, e:
Logger.exception('Pictures: Unable to load <%s>' % filename)
def on_pause(self):
return True
def on_touch_move(self, touch):
for p in self.root.children:
if (p.__class__.__name__ == "Picture" and touch.grab_current != p):
p.pos = (p.x + touch.dx/2, p.y + touch.dy/2)
def set_fps(self, dt):
self.fps_label.text = 'Current FPS: ' + str(Clock.get_fps())
self.fps_label.pos = (-Window.width/2 + 120, Window.height/2 - 40)
if __name__ in ('__main__', '__android__'):
PicturesApp().run()