from threading import Thread from tkinter import Tk, Canvas from lib.strip.FakeStrip import FakeStrip import time class Visualizer(Thread): def __init__(self): Thread.__init__(self) self.x, self.y = 1000, 500 self.first_loop = True self.start() time.sleep(0.01) def run(self): self.root = Tk() self.canvas = Canvas(self.root, width=self.x, height=self.y) self.root.geometry(f'{self.x}x{self.y}') self.canvas.grid() self.root.mainloop() class WindowStrip(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() self.show() def show(self): """Update the display with the data from the LED buffer.""" size = 10.5 bp = [47, 97, 191, 242, 289] x = self.viz.x y = self.viz.y first_loop = self.viz.first_loop for s in range(self.numPixels()): rgb_int = self.getPixelColor(s) r = rgb_int & 255 g = (rgb_int >> 8) & 255 b = (rgb_int >> 16) & 255 if not first_loop: self.viz.canvas.itemconfig(s + 1, fill="#%02x%02x%02x" % (r, g, b)) else: x1 = 0 y1 = 0 x2 = 0 y2 = 0 if s < bp[0]: x1 = (x / 2) + s * size y1 = 0 x2 = x1 + size y2 = size elif s < bp[1]: x1 = x - size y1 = -(bp[0] - s) * size x2 = x1 + size y2 = y1 + size elif s < bp[2]: x1 = x + (bp[1] - s) * size y1 = y x2 = x1 - size y2 = y1 - size elif s < bp[3]: x1 = 0 y1 = y + (bp[2] - s) * size x2 = x1 + size y2 = y1 - size elif s < bp[4]: x1 = size * - (bp[3] - s) y1 = 0 x2 = x1 + size y2 = y1 + size self.viz.canvas.create_rectangle(x1, y1, x2, y2, fill="#%02x%02x%02x" % (r, g, b), outline="") self.viz.first_loop = False