Skip to content

Instantly share code, notes, and snippets.

@GiovanniMoretti
Forked from hansent/screensaver.py
Last active August 29, 2015 14:09
Show Gist options
  • Save GiovanniMoretti/c1def5d3024374886c44 to your computer and use it in GitHub Desktop.
Save GiovanniMoretti/c1def5d3024374886c44 to your computer and use it in GitHub Desktop.
import kivy
kivy.require('1.4.1')
import random, os, sys, os.path
from kivy.app import App
from kivy.uix.image import Image
from kivy.core.window import Window
from kivy.clock import Clock
from kivy.config import Config
from plyer import notification
class PhotoScreensaver(App):
def __init__(self):
App.__init__(self)
self.photos = []
self.find_all_photos()
def build(self):
keyb = Window.request_keyboard(self.stop, self)
keyb.bind(on_key_down = self.key_pressed)
self.image = Image()
self.change_image()
Clock.schedule_interval(self.change_image, 10)
return self.image
def key_pressed(self, keyboard, keycode, text, modifiers):
self.stop()
def change_image(self, whatever = None):
self.image.source = random.choice(self.photos)
def find_all_photos(self):
try:
photoPath = os.path.expanduser('~/Pictures')
self.photos = []
for root, dirs, files in os.walk(photoPath):
for file in files:
if file.endswith('.jpg') or file.endswith('.JPG'):
self.photos.append(os.path.join(root,file))
if not self.photos:
notification.notify("Can't load photos", "The photo list is empty" % photoPath)
sys.exit(1)
except IOError:
notification.notify("Can't load photos", "Couldn't load the photos from %s" % photoPath)
if __name__ == '__main__':
Config.set('graphics', 'fullscreen', '1')
Config.set('graphics', 'size', '0x0')
PhotoScreensaver().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment