Skip to content

Instantly share code, notes, and snippets.

@jeanpat
Created August 20, 2013 19:52
Show Gist options
  • Save jeanpat/6286350 to your computer and use it in GitHub Desktop.
Save jeanpat/6286350 to your computer and use it in GitHub Desktop.
modified version of kivy-example/demo/pictures/main.py available in kivy package
'''
Pictures demo
=============
This is a basic picture viewer, using the scatter widget.
'''
import os
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
class Picture(Scatter):
'''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
#user=os.path.expanduser("~")
#workdir=os.path.join(user,"QFISH","CytoProject","Jpp48","1","DAPI")
#image='part9.png'
#curdir=os.path.join(workdir,image)
curdir = dirname(__file__)
for filename in glob(join(curdir, 'particles', '*')):
print type(filename)
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)
def on_pause(self):
return True
if __name__ == '__main__':
PicturesApp().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment