A bit of cleanup. Pygame and multithreading is a real pain in the ass...
This commit is contained in:
22
gui.py
22
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()
|
||||
|
||||
39
slideshow.py
39
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__":
|
||||
|
||||
Reference in New Issue
Block a user