starcontrol/mainloop.py

47 lines
1.2 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
import logging
import os
import math
import pathlib
import time
import threading
from PIL import Image, ImageDraw
import blocklists
import screen
log = logging.getLogger("main")
if __name__ == "__main__":
screen.screen_init()
screen.scr_light.value = True
img_canvas = Image.new("RGB", (135, 240))
hnd_canvas = ImageDraw.Draw(img_canvas)
hnd_canvas.rectangle((0,0,135,240), (0,0,0))
img_canvas.paste(Image.open("res/image/hourglass.png"),(math.floor(135/2) - math.ceil(49/2),math.floor(240/2) - math.ceil(90/2)))
screen.scr.image(img_canvas)
thr_blocklists = threading.Thread(target=blocklists.blocklist_thread)
thr_screen = threading.Thread(target=screen.screen_thread)
thr_blocklists.start()
thr_screen.start()
ok = True
while ok:
try:
thr_blocklists.join(5.0)
thr_screen.join(5.0)
ok = thr_blocklists.is_alive() and thr_screen.is_alive()
except KeyboardInterrupt:
ok = False
print("KEYBOARD INTERRUPT")
except:
ok = False
screen.running = False
blocklists.running = False
thr_screen.join()
thr_blocklists.join()