From 0f25f8de881e3228ba5909677d2f1082aeec72d5 Mon Sep 17 00:00:00 2001 From: Balthasar Reuter Date: Sat, 20 Jun 2015 00:08:22 +0200 Subject: [PATCH] A bit of cleanup. Pygame and multithreading is a real pain in the ass... --- gui.py | 22 +--------------------- slideshow.py | 39 +++++++++++++++++++++------------------ 2 files changed, 22 insertions(+), 39 deletions(-) diff --git a/gui.py b/gui.py index 218f650..2b6171d 100644 --- a/gui.py +++ b/gui.py @@ -141,6 +141,7 @@ class GUI_PyGame: # Clear screen self.clear() + self.apply() def clear(self, color=(0,0,0)): self.screen.fill(color) @@ -221,26 +222,5 @@ class GUI_PyGame: if r: return e - - def mainloop(self, filename, handle_keypress, handle_mousebutton, handle_gpio_event): - while True: - # Ignore all input that happened before entering the loop - EventModule.get() - # Clear display - self.clear() - # Show idle-picture and message - if filename != None: - self.show_picture(filename) - self.show_message("Hit the button!") - # Render everything - self.apply() - # Wait for event - event = EventModule.wait() - # Handle the event - if event.type == pygame.QUIT: return - elif event.type == pygame.KEYDOWN: handle_keypress(event.key) - elif event.type == pygame.MOUSEBUTTONUP: handle_mousebutton(event.button, event.pos) - elif event.type == gpio_pygame_event: handle_gpio_event(event.channel) - def teardown(self): pygame.quit() diff --git a/slideshow.py b/slideshow.py index 29f4fbe..d635cc5 100755 --- a/slideshow.py +++ b/slideshow.py @@ -1,12 +1,13 @@ #!/usr/bin/env python # Created by br@re-web.eu, 2015 +from gui import GUI_PyGame as GuiModule + import os from datetime import datetime from time import sleep import subprocess - -from gui import GUI_PyGame as GuiModule +from threading import Thread ##################### ### Configuration ### @@ -24,21 +25,12 @@ display_time = 3 # Waiting time between synchronizations sync_time = 60 +#keep_running = True + ############### ### Classes ### ############### -class RoutineRunner: - def __init__(self, cmd): - self.cmd = cmd - - def run(self, interval): - while True: - output = subprocess.check_output(self.cmd, shell=True, stderr=subprocess.STDOUT) - print(output) - sleep(interval) - - class Slideshow: def __init__(self, display_size, display_time, directory, recursive=True): self.directory = directory @@ -77,6 +69,7 @@ class Slideshow: def run(self): while True: + self.scan() for filename in self.filelist: self.display.clear() self.display.show_picture(filename) @@ -88,6 +81,7 @@ class Slideshow: def teardown(self): self.display.teardown() + #keep_running = False exit(0) @@ -95,12 +89,21 @@ class Slideshow: ### Functions ### ################# +def routine_command(cmd, interval): + while True: + print("Running routine") + #output = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT) + #print("Output is " + output) + sleep(interval) + def main(): - # sync = RoutineRunner("ls") - # sync.run(sync_time) - slideshow = Slideshow(display_size, display_time, directory, True) - slideshow.scan() - slideshow.run() + show = Slideshow(display_size, display_time, directory, True) + sync = Thread(target=routine_command, args=("/bin/echo 'Routine executed'", 5) ) + + #sync.run() + show.run() + + sync.join() return 0 if __name__ == "__main__":