diff --git a/slave/main.py b/slave/main.py index ba17426..8b19e81 100644 --- a/slave/main.py +++ b/slave/main.py @@ -9,15 +9,18 @@ from video import Video import multiprocessing import sys from random import randint - +from PIL import Image, ImageDraw +import cv2 class App: def __init__(self, client, x, y): + self.x = x + self.y = y self.client = client self.video = Video(x, y) self.videos = [join("slave/videos", f) for f in listdir("slave/videos") if isfile(join("slave/videos", f))] print(self.videos) - print(self.videos[randint(0, len(self.videos))]) + print(self.videos[randint(0, len(self.videos)-1)]) def on_connect(self, client, userdata, flags, rc): print("Connected with result code "+str(rc)) @@ -33,15 +36,38 @@ class App: elif msg.payload == b'stop': print("Stop") - self.x.terminate() - + try: + self.x.terminate() + except: + pass def idle(self): + last = -1 + secondlast = -1 while True: - #if self.x is not None: - # self.x.terminate() - video = self.videos[randint(0, len(self.videos))] + try: + self.x.terminate() + except: + pass + i = randint(0, len(self.videos)-1) + if i == last or i == secondlast: + continue + + secondlast = last + last = i + video = self.videos[i] + print(video) self.video.start(video) + self.blank() + sleep(1) + + def blank(self): + image = Image.new('RGB', (2000, 2000), color='black') + cv2.namedWindow("window", cv2.WND_PROP_FULLSCREEN) + cv2.moveWindow("window", self.x, self.y) + cv2.setWindowProperty("window",cv2.WND_PROP_FULLSCREEN,cv2.WINDOW_FULLSCREEN) + + cv2.imshow("window", image) def main():