from threading import Thread from tkinter import Tk, Label from .FakeStrip import FakeStrip from lib.Color import Color_to_list from time import sleep import numpy as np from PIL import Image, ImageTk class Visualizer(Thread): def __init__(self, x, y, multi): Thread.__init__(self) self.x, self.y = x, y self.multi = multi self.root = None self.panel = None self.first_loop = True self.start() sleep(0.04) def run(self): self.root = Tk() self.root.title("RGB Visualizer") self.panel = Label(self.root) self.root.geometry(f'{int(self.x * self.multi)}x{int(self.y * self.multi)}') self.panel.pack() self.root.mainloop() def print_image(self, frame): self.panel.configure(image=frame) self.panel.frame = frame class TkinterStrip(FakeStrip): def __init__(self, num, pin, freq_hz=800000, dma=10, invert=False, brightness=255, channel=0, strip_type=None, gamma=None): super().__init__(num, pin, freq_hz, dma, invert, brightness, channel, strip_type, gamma) self.viz = Visualizer(95, 50, 6) # self.ms = time() * 1000.0 self.show() def show(self): """Update the display with the data from the LED buffer.""" bp = [49, 99, 194, 244, 290] x = self.viz.x y = self.viz.y data = np.zeros((y, x, 3), dtype=np.uint8) for s in range(self.numPixels()): x1 = y1 = 0 if s < 49: x1 = x / 2 + s - 1 elif s < 99: x1 = x - 1 y1 = (s - 49) elif s < 194: x1 = x + (99 - s) - 1 y1 = y - 1 elif s < 244: y1 = y + (194 - s) - 1 elif s < 290: x1 = s - 244 x1 = int(x1) y1 = int(y1) data[y1, x1] = Color_to_list(self.getPixelColor(s)) img = Image.fromarray(data, 'RGB').resize((int(self.viz.x * self.viz.multi), int(self.viz.y * self.viz.multi))) self.viz.print_image(ImageTk.PhotoImage(img)) # ms = time() * 1000.0 # print(ms - self.ms) # self.ms = ms