Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/kivy
- import kivy
- kivy.require('1.0.6')
- from glob import glob
- from random import randint
- from os.path import join, dirname
- from kivy.app import App
- 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.properties import ObjectProperty
- from kivy.graphics.transformation import Matrix
- from kivy.clock import Clock
- from kivy.lang import Builder
- Builder.load_string("""
- <-SmoothedScatter>:
- canvas.before:
- PushMatrix
- MatrixInstruction:
- matrix: self.target_transform
- canvas.after:
- PopMatrix
- """)
- class SmoothedScatter(Scatter):
- target_transform = ObjectProperty(Matrix())
- def __init__(self, **kwargs):
- super(SmoothedScatter, self).__init__(**kwargs)
- Clock.schedule_interval(self.target_transform_update, 1 / 60.)
- def target_transform_update(self, *args):
- transform = list(self.transform.get())
- target_transform = list(self.target_transform.get())
- for i in range(4):
- target_transform[i] = list(target_transform[i])
- for j in range(4):
- b = transform[i][j]
- a = target_transform[i][j]
- d = (b - a) / 3.
- target_transform[i][j] += d
- m = Matrix()
- m.set(target_transform)
- self.target_transform = m
- class Picture(SmoothedScatter):
- '''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.
- '''
- source = StringProperty(None)
- class PicturesApp(App):
- def build(self):
- # the root is created in pictures.kv
- root = self.root
- # get any files into images directory
- curdir = dirname(__file__)
- 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 as e:
- Logger.exception('Pictures: Unable to load <%s>' % filename)
- def on_pause(self):
- return True
- if __name__ == '__main__':
- PicturesApp().run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement