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 set_pixmap(self, pixmap): """Set a new pixmap and check for width and height""" self.is_pixmap(pixmap) pixmap_height = self.get_pixmap_height(pixmap) pixmap_width = self.get_pixmap_width(pixmap) if pixmap_height > self.height: msg("pixmap too high", 2, "Image.set_pixmap()", pixmap_height) if pixmap_width > self.width: msg("pixmap too large", 2, "Image.set_pixmap()", pixmap_width) self.pixmap = pixmap self.resize(self.width, self.height)
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()
def add(self, element, x=0, y=0, refresh=True, mode="fill", name="Child"): """ Add a new Image to the childs. Keyword arguments: image -- Image x -- x paste location (default 0) y -- y paste location (default 0) refresh -- blank Image after refresh (default True) mode -- paste mode [Image.paste()] (default "fill") name -- name (default "Child") """ if str(type(element)) == "<class 'libs.slide.Slide'>": self.childs.append((element.view, x, y, refresh, mode, name)) elif str(type(element)) == "<class 'libs.text.Text'>": self.childs.append((element, x, y, refresh, mode, name)) elif str(type(element)) == "<class 'libs.image.Image'>": self.childs.append((element, x, y, refresh, mode, name)) else: msg("not a valid element", 2, "Screen.add()", type(element))
def paste(self, image, x=0, y=0, mode="fill"): """ Paste an Image over another, can take an image or a pixmap. Keyword arguments: image -- Image x -- x location (default 0) y -- y location (default 0) mode -- paste mode (default 'fill') ['fill', 'replace', 'invert', 'modulo'] """ if mode == "fill": for i in range(y, image.height + y): for j in range(x, image.width + x): if i < self.height and j < self.width: if i >= 0 and j >= 0: self.pixmap[i][j] |= image.get_pixmap()[i - y][j - x] elif mode == "replace": for i in range(y, image.height + y): for j in range(x, image.width + x): if i < self.height and j < self.width: if i >= 0 and j >= 0: self.pixmap[i][j] = image.get_pixmap()[i - y][j - x] elif mode == "invert": for i in range(y, image.height + y): for j in range(x, image.width + x): if i < self.height and j < self.width: if i >= 0 and j >= 0: self.pixmap[i][j] ^= image.get_pixmap()[i - y][j - x] elif mode == "modulo": for i in range(y, image.height + y): for j in range(x, image.width + x): self.pixmap[i % self.height][j % self.width] |= image.get_pixmap()[i - y][j - x] else: msg("no such paste mode", 2, "Image.paste()", mode)
def stream(self): msg("Starting download...", 2, "Download", "0%") for p in range(0,101): self.percent.blank() self.percent.edit(p, font="fontbignum") for i in self.load: self.loading.edit(i) self.screen.refresh() msg("Downloading...", 1, "Download", "{0}%".format(p)) msg("Done", 0, "Download", "100%")
def is_pixmap(self, pixmap): """ Check if the given pixmap has a pixmap format. Tell you what is wrong and kill the program if it is not the case. """ if type(pixmap) is list: if type(pixmap[0]) is list: for i in pixmap: for j in i: if j != 0 and j != 1: msg("pixmap wrong data !(1|0)", 3, "Image", j, i) exit() else: msg("pixmap is not a matrix", 3, "Image", type(pixmap[0])) exit() else: msg("pixmap is not a matrix", 3, "Image", type(pixmap)) exit()
def remove(self, id_): """Delete a child by his id""" if id_ <= len(self.childs) - 1: msg(self.childs.pop(id_)[5], 0, "Removed") else: msg("no such child", 2, "Screen.remove()", len(self.childs), id_)
def dot(self, x, y): if x < self.image.width and y < self.image.height: self.image.pixmap[y][x] = 1 else: msg("outside image", 1, "dot", x, y)
def erase(self, x, y): if x < self.image.width and y < self.image.height: self.image.pixmap[y][x] = 0 else: msg("outside image", 1, "erase", x, y)
def stream(self): for i in range(1, 101): self.drawer.line(i, 0, 9, i) self.label.edit(str(i)) self.screen.refresh() msg("Progression", 0, None, i)