def main(argv): global font fontsize = "" entry = "" try: opts, arg = getopt.getopt(argv, "he:f:", ["entry=", "fontsize="]) except getopt.GetoptError: print('argv.py -f <fontsize> -e <entry>') sys.exit(2) for opt, arg in opts: print("opt: ", opt) print("arg: ", arg) if opt == '-h': print('argv.py -f <fontsize> -e <entry>') sys.exit() elif opt in ("-e", "--entry"): entry = arg elif opt in ("-f", "--fontsize"): fontsize = int(arg) print('font size is ', fontsize) print('entry is ', entry) font = ImageFont.truetype(inkyphat.fonts.FredokaOne, fontsize) inkyphat.clear() inkyphat.set_colour('red') text(entry, inkyphat.BLACK)
def display_notification_message(self, data): message = data[0] message2 = data[1] message3 = data[2] inkyphat.set_colour("black") font = ImageFont.truetype(inkyphat.fonts.FredokaOne, 26) font2 = ImageFont.truetype(inkyphat.fonts.FredokaOne, 20) font3 = ImageFont.truetype(inkyphat.fonts.FredokaOne, 14) print(message) print(message2) print(message3) w, h = font.getsize(message) x = (inkyphat.WIDTH / 2) - (w / 2) y = (inkyphat.HEIGHT / 3) - (h / 1.5) inkyphat.text((x, y), message, inkyphat.BLACK, font) w, h = font2.getsize(message2) x = (inkyphat.WIDTH / 2) - (w / 2) y = (inkyphat.HEIGHT / 2) - 5 inkyphat.text((x, y), message2, inkyphat.BLACK, font2) w, h = font2.getsize(message3) x = (inkyphat.WIDTH / 2) - (w / 2) y = (inkyphat.HEIGHT / 3) * 2 inkyphat.text((x, y), message3, inkyphat.BLACK, font2) inkyphat.show()
def show_image(filepath): img = Image.open(filepath) pixel_font = get_font("SFPixelate.ttf", 9) medium_font = get_font("SFPixelate.ttf", 18) # large_font = get_font('SFPixelate.ttf', 36) d = ImageDraw.Draw(img) time_string = datetime.datetime.now().strftime("%H:%M") ip_address = check_output(["hostname", "-I"]).decode("utf-8").strip() info_string = f"{ip_address} / {time_string}" d.text((1, 95), info_string, font=pixel_font, fill=WHITE) quote_url = "https://notify.goude.se/quote" quote = requests.get(quote_url).text quote_font = pixel_font chunk_width = 35 quote = "\n".join(chunkstring(quote, chunk_width)) d.multiline_text((1, 1), quote, font=quote_font, fill=WHITE) inkyphat.set_colour("black") # 'red' is much slower inkyphat.set_border(inkyphat.BLACK) inkyphat.set_image(img) inkyphat.show()
def update(self, temperature, weather): if temperature and weather: self.temp = temperature self.weather = weather self.active = True else: self.active = False self.update_colors() try: inkyphat.set_colour(self.color) except ValueError: print('Invalid colour "{}" for V{}\n'.format( self.color, inkyphat.get_version())) if inkyphat.get_version() == 2: sys.exit(1) print('Defaulting to "red"') inkyphat.set_border(inkyphat.BLACK) # Load our backdrop image inkyphat.set_image("resources/backdrop.png") # Let's draw some lines! inkyphat.line((69, 36, 69, 81)) # Vertical line inkyphat.line((31, 35, 184, 35)) # Horizontal top line inkyphat.line((69, 58, 174, 58)) # Horizontal middle line inkyphat.line((169, 58, 169, 58), 2) # Red seaweed pixel :D # And now some text dt = (datetime.datetime.now() + datetime.timedelta(seconds=self.tz)).strftime("%m/%d %H:%M") inkyphat.text((36, 12), dt, inkyphat.WHITE, font=font) inkyphat.text((72, 34), "T", inkyphat.WHITE, font=font) inkyphat.text( (92, 34), u"{:.2f}°".format(self.temp), inkyphat.WHITE if self.temp < WARNING_TEMP else inkyphat.RED, font=font) inkyphat.text((72, 58), "Active" if self.active else "Disconn", inkyphat.WHITE, font=font) # Draw the current weather icon over the backdrop if self.weather is not None: inkyphat.paste(icons[icon_mapping[self.weather]], (28, 36), masks[icon_mapping[self.weather]]) else: inkyphat.text((28, 36), "?", inkyphat.RED, font=font) self.display()
def __init__(self, config): self.config = config # Basic Inky settings inkyphat.set_colour(self.config.inky_color) inkyphat.set_border(self.config.inky_border_color) inkyphat.set_rotation(self.config.inky_rotate) # startup vars self.api_key = self.config.api_key self.coin_id = self.config.coin_id self.currency = self.config.currency self.coin_invest = self.config.coin_invest self.coin_amount = self.config.coin_amount self.show_roi = self.config.show_roi self.font = self.config.font_path
def displayStatus(statusString): # Prepare the String into two lines wrapped = textwrap.wrap(statusString, width=20) # Show the backdrop image inkyphat.set_colour(config["inkyphatConfig"]["colour"]) inkyphat.set_border(inkyphat.RED) inkyphat.set_image("background.png") inkyphat.set_rotation(config["inkyphatConfig"]["rotation"]) # Add the text font = ImageFont.truetype(inkyphat.fonts.FredokaOne, 21) # Title Line line_one = config["inkyphatConfig"]["line_one"] w, h = font.getsize(line_one) # Center the text and align it with the name strip x = (inkyphat.WIDTH / 2) - (w / 2) y = 18 - (h / 2) inkyphat.text((x, y), line_one, inkyphat.WHITE, font) if(len(wrapped) >= 1): # Status Line 1 status_one = wrapped[0] w, h = font.getsize(status_one) # Center the text and align it with the name strip x = (inkyphat.WIDTH / 2) - (w / 2) y = 50 - (h / 2) inkyphat.text((x, y), status_one, inkyphat.BLACK, font) if(len(wrapped) >= 2): # Status Line 2 status_two = wrapped[1] w, h = font.getsize(status_two) # Center the text and align it with the name strip x = (inkyphat.WIDTH / 2) - (w / 2) y = 80 - (h / 2) inkyphat.text((x, y), status_two, inkyphat.BLACK, font) inkyphat.show()
def main (argv): global font file = "" try: opts, arg = getopt.getopt(argv,"hf:",["file="]) except getopt.GetoptError: print( 'image.py -f <filename> ') sys.exit(2) for opt, arg in opts: print("opt: ", opt) print("arg: ", arg) if opt == '-h': print( 'image.py -f <filename> ') sys.exit() elif opt in ("-f", "--file"): file = arg print( 'file is ', file ) inkyphat.clear() inkyphat.set_colour('red') image(file)
def draw_weather(): weather = get_weather() if weather == None: print 'No weather!' return if ROTATE_180 == True: inkyphat.set_rotation(180) # TODO configurable color inkyphat.set_colour('red') inkyphat.set_border(inkyphat.RED) # background inkyphat.rectangle((0, 0, inkyphat.WIDTH, inkyphat.HEIGHT), inkyphat.RED) # draw columns # (assuming get_weather has returned using NUM_COLS) for i in range(0, NUM_COLS): # draw time label time = weather['hours'][i]['time'] w, h = timeFont.getsize(time) draw_shadowed_text(get_x(w, i), 4, time, timeFont) # draw icon try: # This could be optimized to not load the same file more than once img = Image.open('assets/' + weather['hours'][i]['icon'] + '.png') inkyphat.paste(img, (get_x(30, i), 22)) # drawing icons without transparency as it didn't work with whatever gimp was producing except: print 'Error with icon:' + weather['hours'][i]['icon'] # draw temperature label temp = weather['hours'][i]['temperature'] w, h = temperatureFont.getsize(temp) draw_shadowed_text(get_x(w, i), 56, temp, temperatureFont) # TODO multiple lines if too long draw_shadowed_text(5, 84, weather['summary'], summaryFont) inkyphat.show()
def update(self, status_id): try: inkyphat.set_colour("Black") except ValueError: print('Invalid colour "{}" for V{}\n'.format(self.color, inkyphat.get_version())) if inkyphat.get_version() == 2: sys.exit(1) print('Defaulting to "red"') inkyphat.clear() inkyphat.set_border(inkyphat.BLACK) # Load our backdrop image # inkyphat.set_image("resources/backdrop.png") # Let's draw some lines! # And now some text status = statuses[status_id] w, h = inkyphat._draw.multiline_textsize(status, font) x = (inkyphat.WIDTH / 2) - (w / 2) y = (inkyphat.HEIGHT / 2) - (h / 2) inkyphat._draw.multiline_text((x, y), status, inkyphat.BLACK, font) self.display()
# d = json.load(json_data) # READ REMOTE JSON: url = "https://nas.imeuro.io/temperino_v2/data/readings.json" response = urllib.urlopen(url) d = json.loads(response.read()) d = ast.literal_eval(json.dumps(d)) #print(d) Rtime = roundTime(datetime.now(), timedelta(minutes=5)) Rdate = strftime('%a, %d %b', Rtime.timetuple()) Rhour = strftime('%H:%M', Rtime.timetuple()) degSign = u'\N{DEGREE SIGN}' inkyphat.set_colour('red') inkyphat.set_border(inkyphat.BLACK) # Partial update if using Inky pHAT display v1 if inkyphat.get_version() == 1: inkyphat.show() # FONTS font10 = ImageFont.truetype( '/var/www/html/temperino_v2_data/fonts/Bitter-Regular.ttf', 10) font10b = ImageFont.truetype( '/var/www/html/temperino_v2_data/fonts/Bitter-Bold.ttf', 10) font22 = ImageFont.truetype( '/var/www/html/temperino_v2_data/fonts/Bitter-Bold.ttf', 22) font28 = ImageFont.truetype( '/var/www/html/temperino_v2_data/fonts/Bitter-Bold.ttf', 28)
Use Inky pHAT as a personalised name badge! """) #inkyphat.set_rotation(180) if len(sys.argv) < 3: print("""Usage: {} <your name> <colour> Valid colours for v2 are: red, yellow or black Inky pHAT v1 is only available in red. """.format(sys.argv[0])) sys.exit(1) colour = sys.argv[2] inkyphat.set_colour(colour) # Show the backdrop image inkyphat.set_border(inkyphat.RED) inkyphat.set_image("resources/hello-badge.png") # Partial update if using Inky pHAT display v1 if inkyphat.get_version() == 1: inkyphat.show() # Add the text font = ImageFont.truetype(inkyphat.fonts.AmaticSCBold, 38)
#!/usr/bin/env python from PIL import Image import sys import inkyphat inkyphat.set_colour('yellow') print("""Inky pHAT: Logo Displays the Inky pHAT logo. """) if len(sys.argv) < 2: print("""Usage: {} <colour> Valid colours: red, yellow, black """.format(sys.argv[0])) sys.exit(0) colour = sys.argv[1].lower() inkyphat.set_colour(colour) inkyphat.set_border(inkyphat.BLACK) if colour == 'black': inkyphat.set_image(Image.open("InkyPhat-212x104-bw.png")) else: inkyphat.set_image(Image.open("InkyPhat1-212x104.png"))
def image(file): inkyphat.clear() inkyphat.set_colour('red') inkyphat.set_image(Image.open(file)) inkyphat.show()
import inkyphat from PIL import Image, ImageFont, ImageDraw import subprocess import requests import picamera import datetime #import keybdStream as kbd import encryption import qr import returnIDnumbers inkyphat.set_colour("black") font = ImageFont.truetype(inkyphat.fonts.AmaticSCBold, 38) #camera=picamera.PiCamera() def sendImage(idNumber, timeOfCapture, className, filename): #POST request to send images to server url = "http://128.143.67.97:44104/upload/" data = { 'encryptedID': idNumber, 'timeOfCapture': timeOfCapture, 'className': className } files = {'file': open(filename, "rb")} response = requests.request("POST", url, data=data, files=files)
#!/usr/bin/python3.5 import inkyphat from PIL import ImageFont import national_rail_fetcher import time import sys station_from = sys.argv[1] station_to = sys.argv[2] inkyphat.set_colour("yellow") font_services = ImageFont.truetype("./8bitoperator.ttf", 11) font_services_offset = -4 font_times = ImageFont.truetype("./8bitoperator.ttf", 10) font_times_offset = -2 font_errors = font_times UPDATE_PERIOD_SECONDS = 90 UPDATE_PERIOD_AFTER_ERROR_SECONDS = 30 FONT_SIZE = 11 LINE_HEIGHT = inkyphat.HEIGHT // 5 + 1 LEFT_PADDING = 1 TIME_WIDTH = 43 DELAY_TEXT_WIDTH = inkyphat.WIDTH // 4 DELAY_TEXT_PADDING = 5 ROTATE_SCREEN = True if (ROTATE_SCREEN): inkyphat.set_rotation(180)
#!/usr/bin/env python from PIL import Image import sys import inkyphat inkyphat.set_colour('black') inkyphat.set_border(inkyphat.BLACK) inkyphat.set_image(Image.open("screencapture/screen.png")) inkyphat.show()