class ClockPlugin: def __init__(self): self.author = 'Infected' self.name = 'Clock Plugin' self.version = 'V3.23-4.2-DOS.26__release' self.time = datetime.now() self.timer = Text() self.canvas = Image(64, 16) self.time_frame = Image(64, 16) self.canvas_draw = Drawer(self.canvas) self.invert = Image(64, 16) self.invert.fill() self.screen = Screen(matrix=True, show=False, fps=15) self.screen.add(self.time_frame, refresh=True) self.screen.add(self.timer, refresh=True, x=3, y=3) self.screen.add(self.canvas, refresh=False) self.screen.add(self.invert, mode='invert', refresh=False) self.gen_canvas() def get_info(self): """Get the current state and information of the plugin""" print(color(self.name, "red"), color(self.author, "green"), color(self.version, "magenta"), sep='\n') def gen_canvas(self): self.canvas_draw.line(0, 0, 63, 0) self.canvas_draw.line(0, 0, 0, 15) self.canvas_draw.line(0, 15, 63, 15) self.canvas_draw.line(63, 0, 63, 15) def refresh(self): self.time = datetime.now() def print_time(self): self.timer.edit('{}:{}:{}'.format( str(self.time.hour).zfill(2), str(self.time.minute).zfill(2), str(self.time.second).zfill(2)), font='fontbignum') def stream(self): self.refresh() self.print_time() self.screen.refresh()
class Hbd_plugin: def __init__(self): msg("input()", 2, "Hbd_plugin.__init__()") self.name_label = input(color("Enter label: ", "red")).lower() self.name_text = input(color("Enter name: ", "yellow")).lower() self.mask = Image(64,16) self.mask.fill() self.bg = Image(64, 16) self.drawer = Drawer(self.bg) self.drawer.dot(0, 0) self.drawer.dot(0, 15) self.drawer.dot(63, 0) self.drawer.dot(63, 15) self.label = Text(text="§" + self.name_label + "§") self.name = Text(text=self.name_text) self.screen = Screen(matrix=True, show=True, fps=1.7, tty='/dev/ttyACM1') self.screen.add(self.bg, refresh=False) xloc_label = (64 - abs(self.label.width)) // 2 self.screen.add(self.label, x=xloc_label, y=1, refresh=False) xloc_text = (64 - abs(self.name.width)) // 2 self.screen.add(self.name, x=xloc_text, y=8, refresh=False) self.screen.add(self.mask, refresh=False, mode="invert") def stream(self): try: blink = False while True: blink = not blink if blink: self.mask.blank() else: self.mask.fill() self.screen.refresh() except KeyboardInterrupt: print() msg(self.name_label, 0, "label") msg(self.name_text, 0, "name") exit()
class MatrixDrawer: def __init__(self, x=64, y=16): self.image = Image(width=x, height=y) self.drawer = Drawer(self.image) self.updater = Updater(self) self.x = x self.y = y self.live = False self.drawmode = True self.updatethread = None self.create_window() self.create_canvas() self.create_buttons() self.root.mainloop() # Launch tkinter eventloop # This is run only after tkinter is closed and its event loop ends # Cleaning up any potential loose ends at close of program if self.updatethread is not None: self.updater.live = False self.updatethread.join() def create_window(self): self.root = tkinter.Tk() self.root.configure(bg="light blue") self.root.title("Matrix Drawer") self.root.bind("<Button-1>", self.mouse_interact_left) self.root.bind("<B1-Motion>", self.mouse_interact_left) self.root.bind("<Button-3>", self.mouse_interact_right) self.root.bind("<B3-Motion>", self.mouse_interact_right) def create_canvas(self): self.canvasframe = tkinter.Frame(self.root) self.canvasframe.pack(side="right") pixel_size = 20 self.canvas = tkinter.Canvas(self.canvasframe, bg="black", height=self.y*pixel_size, width=self.x*pixel_size) self.canvas.grid(row=0, column=0) for y in range(self.y): for x in range(self.x): self.canvas.create_oval(x*pixel_size, y*pixel_size, x*pixel_size + pixel_size, y*pixel_size + pixel_size, fill="grey") def create_buttons(self): self.buttonframe = tkinter.Frame(self.root, bg="light blue") self.buttonframe.pack(side="left") self.updatebutton = tkinter.Button(self.buttonframe, text="Send To Matrix", bg="Yellow", command=self.updater.one_refresh ) self.clearbutton = tkinter.Button(self.buttonframe, text="Clear All", bg="Yellow", command=self.clearall ) self.fillbutton = tkinter.Button(self.buttonframe, text="Fill All", bg="Yellow", command=self.fillall ) self.livebutton = tkinter.Button(self.buttonframe, text="Status: Manual", bg="Yellow", command=self.togglelive ) self.drawbutton = tkinter.Button(self.buttonframe, command=self.toggledraw, text="Draw Mode", bg="Yellow", relief="sunken", activebackground="Yellow" ) self.erasebutton = tkinter.Button(self.buttonframe, command=self.toggleerase, text="Erase Mode", bg="Grey", activebackground="Grey" ) self.updatebutton.grid(row=0, column=0, columnspan=2) self.clearbutton.grid(row=1, column=0, columnspan=2) self.fillbutton.grid(row=2, column=0, columnspan=2) self.livebutton.grid(row=3, column=0, columnspan=2) self.drawbutton.grid(row=4, column=0) self.erasebutton.grid(row=4, column=1) def toggledraw(self): """ Sets left mouse button to drawing """ self.drawmode = True self.drawbutton.configure(relief="sunken", bg="Yellow", activebackground="Yellow") self.erasebutton.configure(relief="raised", bg="Grey", activebackground="Grey") def toggleerase(self): """ Sets left mouse button to erasing """ self.drawmode = False self.drawbutton.configure(relief="raised", bg="Grey", activebackground="Grey") self.erasebutton.configure(relief="sunken", bg="Yellow", activebackground="Yellow") def togglelive(self): """ Creates new thread and launches permanent loop to keep matrix updated in real time """ if self.updater.live: # we were already live, going manual now self.livebutton.configure(text="Status: Manual") # Stop the infinite loop in the other thread and terminate it self.updater.live = False self.updatethread.join() self.updatethread = None else: # we were manual, now going live self.livebutton.configure(text="Status: Live") self.updater.live = True # Open a new thread and launch the infinite update loop self.updatethread = threading.Thread(target=self.updater.toggle_live) self.updatethread.start() def clearall(self): """ Clears all pixels, resetting them back to grey """ for i in range(self.x * self.y): self.canvas.itemconfig(i+1, fill="grey") self.image.blank() def fillall(self): """ Fills all pixels, setting them to red """ for i in range(self.x * self.y): self.canvas.itemconfig(i+1, fill="red") self.image.fill() def mouse_interact_left(self, event): """ Left mouse's function depends on the 2 draw/erase buttons available to the user """ if event.widget.winfo_id() == self.canvas.winfo_id(): x = self.canvas.canvasx(event.x) y = self.canvas.canvasy(event.y) pixel = self.canvas.find_closest(x, y) if self.drawmode: self.canvas.itemconfig(pixel, fill="red") self.drawer.dot((pixel[0]-1) % self.x, (pixel[0] - 1) // self.x) else: self.canvas.itemconfig(pixel, fill="grey") self.drawer.erase((pixel[0]-1) % self.x, (pixel[0] - 1) // self.x) def mouse_interact_right(self, event): """ Right mouse button always used for erasing """ if event.widget.winfo_id() == self.canvas.winfo_id(): x = self.canvas.canvasx(event.x) y = self.canvas.canvasy(event.y) pixel = self.canvas.find_closest(x, y) self.canvas.itemconfig(pixel, fill="grey") self.drawer.erase((pixel[0]-1) % self.x, (pixel[0] - 1) // self.x)