#!/usr/bin/env python import glob import os os.environ['KIVY_GL_DEBUG'] = '1' import time from kivy.app import App from kivy.clock import Clock from kivy.lang import Builder from kivy.properties import StringProperty, ObjectProperty from kivy.uix.image import AsyncImage from kivy.uix.floatlayout import FloatLayout from kivy.uix.screenmanager import ScreenManager, Screen, FadeTransition # Define the path to our images folder = '/home/pi/.masterpics/pix' # Set the extenstions you want to display extensions = ["*.png","*.jpg", "*.JPG"] # Define the layout in a KV file. # It's good to get familiar with the format as it makes building Kivy apps # very quick kv = """ #:kivy 1.0.9 templabel: templabel scrmgr: scrmgr size_hint: 1,1 ScreenManager: id: scrmgr size_hint: 1,1 # This is the label to show your temperature info Label: id: templabel text: root.temp pos: 0,0 size: 200,20 size_hint: None, None Image: source: root.imsource """ # Simple Screen class that displays a single image class PhotoScreen(Screen): # String property for the image path imsource = StringProperty(None) def __init__(self, **kwargs): super(PhotoScreen, self).__init__(**kwargs) # Set the file path self.imsource = self.name # This is our base screen class KivySlideshow(FloatLayout): scrmgr = ObjectProperty(None) templabel = ObjectProperty(None) temp = StringProperty("Loading data...") def __init__(self, **kwargs): super(KivySlideshow, self).__init__(**kwargs) # Use a fade transition between photos self.scrmgr.transition = FadeTransition() self.scrmgr.transition.duration = 1 # Get a list of photos to show self.photos = [] for ext in extensions: photos = glob.glob(os.path.join(folder, ext)) self.photos += photos # Put them in order self.photos.sort() # Set some variables that we'll use to keep track of the photos # x is the index of the photo to be shown self.x = 0 # old is a reference to the old photo so we can unload it. self.old = None # We're ready, so load the first photo self.load_photo() # Update our temperature label every 5 seconds Clock.schedule_interval(self.show_temp, 5) def load_photo(self, *args): # Get the current photo current = self.photos[self.x] print 'current photo: ' + str(current) + ' Time: ' + str(time.strftime('%d %b %Y %H:%M')) # Create a screen with this name newphoto = PhotoScreen(name=current) # Add it to the screen manager self.scrmgr.add_widget(newphoto) # Display it self.scrmgr.current = current # If there's an old photo if self.old: # unload it self.scrmgr.remove_widget(self.old) # Create a reference to the photo so we can remove it later self.old = newphoto self.x = (self.x + 1) % len(self.photos) Clock.schedule_once(self.load_photo, 2) # Method to update the temperature def show_temp(self, *args): # Set the text for the label self.temp = "Temp is: {}".format(self.x) # Base app class class KivySlideshowApp(App): def build(self): # Return an instance of the slideshow return KivySlideshow() if __name__ == "__main__": Builder.load_string(kv) KivySlideshowApp().run()