def __init__(self, font = None, fsize=None): self.d = ex.display() self.img,self.drw = ex.image() ft = ex.font(font, fsize) self.drw.text((4,3),'Happy', font=ft) self.drw.text((8,20),'Birthday', font=ft) self.drw.text((30,36),'Elsa!',font=ft)
class Size: def GET(self): return json.dumps(web.size) class Buffer: def POST(self): data = unicode(web.data(), 'utf-8').split("\n") LCD.clear_image(web.draw) for n, line in enumerate(data): web.draw.text((0, n*web.font_size[1]), line, font=web.font) LCD.render_display(web.disp, web.img) web.disp = LCD.display() web.img, web.draw = LCD.image() cfg = config() fname = cfg.get("server", "font") fsize = cfg.getint("server", "size") print "Got font {} size {}".format(fname, fsize) try: web.font = LCD.font(fname, fsize) except IOError: fname = os.path.join(os.path.dirname(__file__), fname) web.font = LCD.font(fname, fsize) sizes = web.font_size = web.font.getsize(u"\u2592") web.size = int(LCD.width / sizes[0]), int(LCD.height / sizes[1]) if __name__ == "__main__": app.run()