def drawApp(app, position, amount): drawTitle() positionText = "{}/{}".format(position+1, amount) if app["path"].startswith("/sd"): positionText = "SD "+positionText positionWidth = display.getTextWidth(positionText, "org18") display.drawText(display.width()-positionWidth-2, 0, positionText, 0x000000, "org18") titleWidth = display.getTextWidth(app["name"], "7x5") display.drawText((display.width()-titleWidth)//2,display.height()-10, app["name"], 0xFFFFFF, "7x5") try: icon_data = None if app["icon"]: if not app["icon"].startswith(b"\x89PNG"): with open(app["path"]+"/"+app["icon"], "rb") as icon_file: icon_data = icon_file.read() else: icon_data = app["icon"] if not icon_data: display.drawPng(48,15,default_icon) else: info = display.pngInfo(icon_data) if info[0] == 32 and info[1] == 32: display.drawPng(48,15,icon_data) else: drawMessageBox("Invalid icon size\nExpected 32x32!") except BaseException as e: sys.print_exception(e) drawMessageBox("Icon parsing error!") if not position < 1: display.drawText(0, display.height()//2-12, "<", 0xFFFFFF, "roboto_regular18") if not position >= (amount-1): display.drawText(display.width()-10, display.height()//2-12, ">", 0xFFFFFF, "roboto_regular18") display.flush()
def drawLogo(offset = 0, max_height = display.height(), center = True): global cfg_logo try: info = display.pngInfo(cfg_logo) except: return 0 width = info[0] height = info[1] if width > display.width(): print("Image too large (x)") return if height > display.height(): print("Image too large (y)") x = int((display.width() - width) / 2) if center: if max_height - height < 0: #print("Not enough space for logo",max_height,height) #return 0 y = 0 else: y = int((max_height - height) / 2) + offset else: y = offset try: display.drawPng(x,y,cfg_logo) return height except BaseException as e: sys.print_exception(e) return 0
def messageCentered(message, firstLineTitle=True, png=None): try: display.drawFill(0xFFFFFF) color = 0x000000 font1 = "Roboto_Regular18" font2 = "Roboto_Regular12" font1Height = display.getTextHeight(" ", font1) font2Height = display.getTextHeight(" ", font2) message = message.split("\n") lines = [] for i in range(len(message)): line = message[i] if len(line) < 1: lines.append("") else: if firstLineTitle and i == 0: lines.extend(lineSplit(line, display.width(), font1)) else: lines.extend(lineSplit(line, display.width(), font2)) pngSize = (0, 0) if png != None: try: pngSize = display.pngInfo(png) pngSize = [pngSize[0], pngSize[1] + 2] #Little bit of extra offset except BaseException as e: #print("Error in PNG height",e) pass textHeight = len(lines) * font2Height if firstLineTitle: textHeight -= font2Height textHeight += font1Height offset_y = (display.height() - pngSize[1] - textHeight) // 2 if png != None: try: display.drawPng((display.width() - pngSize[0]) // 2, offset_y, png) offset_y += pngSize[1] except BaseException as e: print("Error in PNG draw", e) for i in range(len(lines)): if firstLineTitle and i == 0: lineCentered(offset_y, lines[i], font1, color) offset_y += font1Height else: lineCentered(offset_y, lines[i], font2, color) offset_y += font2Height display.flush(display.FLAG_LUT_FASTEST) except BaseException as e: print("Error in messageCentered!", e)
def demoThread(): global demoThreadRunning counter = 0 fpsTrig = False w, h, _, _ = display.pngInfo(mascot.snek) display.drawFill(0xFFFF00) prev = time.ticks_ms() av = [0] * 100 while demoThreadRunning: if counter > 100: fpsTrig = True current = time.ticks_ms() if (current - prev) > 0: fps = 1000 // (current - prev) else: fps = 0 _ = av.pop(0) av.append(fps) fps = 0 for i in range(len(av)): fps += av[i] fps = fps // len(av) display.drawRect(0, 0, display.width() - 1, 20, True, 0xFFFF00) if fpsTrig: display.drawText(0, 0, "{} fps".format(fps), 0x000000, "ocra16") else: display.drawText(0, 0, "Demo time!", 0x000000, "ocra16") my = (display.height() - h) // 2 - (round(math.sin(counter)) - 1) * 10 mx = (display.width() - w) // 2 - (round(math.cos(counter)) - 1) * 10 display.drawPng(mx, my, mascot.snek) #Draw squares display.drawRect(display.width() - 39 - (counter % display.width()), display.height() // 2 - 20, 40, 40, True, 0x00FF00) display.drawRect(counter % display.width(), display.height() // 2 - 10, 20, 20, True, 0xFF0000) #Flush to display display.flush() #Clear away the squares display.drawRect(display.width() - 39 - (counter % display.width()), display.height() // 2 - 20, 40, 40, True, 0xFFFF00) display.drawRect(counter % display.width(), display.height() // 2 - 10, 20, 20, True, 0xFFFF00) #Clear away the mascot display.drawRect(mx, my, w, h, True, 0xFFFF00) #Increment counter counter += 1 #time.sleep(0.01) prev = current drawNickname()
def drawApp(app, position, amount): global extended_menu, appList oneFourthWidth = display.width() // 4 display.drawFill(0x000000) display.drawRect(0, 0, display.width() // (2 if extended_menu else 1), 10, True, 0xFFFFFF) display.drawText(2, 0, "LAUNCHER", 0x000000, "org18") positionText = "{}/{}".format(position + 1, amount) if app["path"].startswith("/sd"): positionText = "SD " + positionText positionWidth = display.getTextWidth(positionText, "org18") display.drawText( display.width() // (2 if extended_menu else 1) - positionWidth - 2, 0, positionText, 0x000000, "org18") titleWidth = display.getTextWidth(app["name"], "7x5") display.drawText( (oneFourthWidth * (3 if extended_menu else 2) - titleWidth // 2), display.height() - 10, app["name"], 0xFFFFFF, "7x5") try: icon_data = None if app["icon"]: if not app["icon"].startswith(b"\x89PNG"): with open(app["path"] + "/" + app["icon"], "rb") as icon_file: icon_data = icon_file.read() else: icon_data = app["icon"] if not icon_data: display.drawPng(oneFourthWidth * (3 if extended_menu else 2) - 16, display.height() // 2 - 16, default_icon) else: info = display.pngInfo(icon_data) if info[0] == 32 and info[1] == 32: display.drawPng( oneFourthWidth * (3 if extended_menu else 2) - 16, display.height() // 2 - 16, icon_data) else: drawMessageBox("Invalid icon size\nExpected 32x32!") except BaseException as e: sys.print_exception(e) drawMessageBox("Icon parsing error!") if not extended_menu: if not position < 1: display.drawText(0, display.height() // 2 - 12, "<", 0xFFFFFF, "roboto_regular18") if not position >= (amount - 1): display.drawText(display.width() - 10, display.height() // 2 - 12, ">", 0xFFFFFF, "roboto_regular18") if appList: appList.draw() display.flush(display.FLAG_LUT_FASTEST)
def start(app, status=False): if status: import term, easydraw, display if app == "" or app == "launcher": term.header(True, "Loading menu...") #easydraw.messageCentered("Loading the menu...", False, "/media/busy.png") else: term.header(True, "Loading application "+app+"...") #easydraw.messageCentered("Loading '"+app+"'...", False, "/media/busy.png") try: info = display.pngInfo("/media/busy.png") display.drawPng((display.width()-info[0])//2, (display.height()-info[1])//2, "/media/busy.png") except: easydraw.messageCentered("Loading...", False, "/media/busy.png") machine.RTC().write_string(app) reboot()
def drawLogo(offset=0, max_height=display.height(), center=True): global cfg_logo try: info = display.pngInfo(cfg_logo) except: return 0 width = info[0] height = info[1] x = int((display.width() - width) / 2) if center: if max_height - height < 0: y = 0 else: y = int((max_height - height) / 2) + offset else: y = offset try: display.drawPng(x, y, cfg_logo) return height except BaseException as e: sys.print_exception(e) return 0
def png_info(arg): return display.pngInfo(arg)
print("sunset", sunsetSec) print("night len", nightLen) print("day len", dayLen) print(24 * 3600, ":", dayLen + nightLen) print("now night", nowNight) x = int((nowNight / nightLen) * 296) print("Moon pos:", x) x = int(x - (90 / 2)) print("Moon pos:", x) display.drawFill(0x000000) # Fill the screen with black display.drawPng(x, 8, "/lib/stillsolunaanyway/moon.png") print(display.pngInfo("/lib/stillsolunaanyway/moon.png")) display.drawText(0, 105, sunset, 0xFFFFFF, "Roboto_Regular18") display.drawText(140, 105, nowStr, 0xFFFFFF, "Roboto_Regular18") display.drawText(245, 105, sunrise, 0xFFFFFF, "Roboto_Regular18") display.flush() # Write the contents of the buffer to the display badge.eink_busy_wait() time.sleep(15) #display.drawpng(0,0,moon1.png) except: print( "################################################################################################################################################################" )