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
|
# Clear screen
|
||||||
self.clear()
|
self.clear()
|
||||||
|
self.apply()
|
||||||
|
|
||||||
def clear(self, color=(0,0,0)):
|
def clear(self, color=(0,0,0)):
|
||||||
self.screen.fill(color)
|
self.screen.fill(color)
|
||||||
@@ -221,26 +222,5 @@ class GUI_PyGame:
|
|||||||
if r:
|
if r:
|
||||||
return e
|
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):
|
def teardown(self):
|
||||||
pygame.quit()
|
pygame.quit()
|
||||||
|
|||||||
39
slideshow.py
39
slideshow.py
@@ -1,12 +1,13 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# Created by br@re-web.eu, 2015
|
# Created by br@re-web.eu, 2015
|
||||||
|
|
||||||
|
from gui import GUI_PyGame as GuiModule
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from time import sleep
|
from time import sleep
|
||||||
import subprocess
|
import subprocess
|
||||||
|
from threading import Thread
|
||||||
from gui import GUI_PyGame as GuiModule
|
|
||||||
|
|
||||||
#####################
|
#####################
|
||||||
### Configuration ###
|
### Configuration ###
|
||||||
@@ -24,21 +25,12 @@ display_time = 3
|
|||||||
# Waiting time between synchronizations
|
# Waiting time between synchronizations
|
||||||
sync_time = 60
|
sync_time = 60
|
||||||
|
|
||||||
|
#keep_running = True
|
||||||
|
|
||||||
###############
|
###############
|
||||||
### Classes ###
|
### 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:
|
class Slideshow:
|
||||||
def __init__(self, display_size, display_time, directory, recursive=True):
|
def __init__(self, display_size, display_time, directory, recursive=True):
|
||||||
self.directory = directory
|
self.directory = directory
|
||||||
@@ -77,6 +69,7 @@ class Slideshow:
|
|||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
while True:
|
while True:
|
||||||
|
self.scan()
|
||||||
for filename in self.filelist:
|
for filename in self.filelist:
|
||||||
self.display.clear()
|
self.display.clear()
|
||||||
self.display.show_picture(filename)
|
self.display.show_picture(filename)
|
||||||
@@ -88,6 +81,7 @@ class Slideshow:
|
|||||||
|
|
||||||
def teardown(self):
|
def teardown(self):
|
||||||
self.display.teardown()
|
self.display.teardown()
|
||||||
|
#keep_running = False
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
|
|
||||||
@@ -95,12 +89,21 @@ class Slideshow:
|
|||||||
### Functions ###
|
### 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():
|
def main():
|
||||||
# sync = RoutineRunner("ls")
|
show = Slideshow(display_size, display_time, directory, True)
|
||||||
# sync.run(sync_time)
|
sync = Thread(target=routine_command, args=("/bin/echo 'Routine executed'", 5) )
|
||||||
slideshow = Slideshow(display_size, display_time, directory, True)
|
|
||||||
slideshow.scan()
|
#sync.run()
|
||||||
slideshow.run()
|
show.run()
|
||||||
|
|
||||||
|
sync.join()
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user