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()
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. import time import sys from bsb_io import * import spidev import NokiaLCD as lcd from PIL import Image from PIL import ImageDraw from PIL import ImageFont disp = lcd.display() image, draw = lcd.image() # Draw a white filled box to clear the image. draw.rectangle((0,0,PCD8544.LCDWIDTH,PCD8544.LCDHEIGHT), outline=255, fill=255) # Draw some shapes. draw.ellipse((2,2,22,22), outline=0, fill=255) draw.rectangle((24,2,44,22), outline=0, fill=255) draw.polygon([(46,22), (56,2), (66,22)], outline=0, fill=255) draw.line((68,22,81,2), fill=0) draw.line((68,2,81,22), fill=0) # Load default font. #font = ImageFont.load_default() # Alternatively load a TTF font.