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 mode3(self): # background image img = Image.open(self.config.back_simple) inkyphat.set_image(img) # Add ranking text font = ImageFont.truetype(self.font, 22) inkyphat.text((45, 5), "#" + self.rank, inkyphat.WHITE, font) # Add the price text font = ImageFont.truetype(self.font, 48) price = str("%.3f" % self.price) inkyphat.text((44, 25), price, inkyphat.WHITE, font) # Add ROI Percentage actual_value = self.price * self.coin_amount percentage = (actual_value / self.coin_invest * 100) - 100 font = ImageFont.truetype(self.font, 32) roistr = str("%.2f" % percentage + '%') if percentage > 0.0: inkyphat.text((44, 67), roistr, inkyphat.WHITE, font) else: inkyphat.text((44, 67), roistr, inkyphat.RED, font) 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 printOutIP(): #for debugging, prints out wlan0 IP of Pi to screen out = subprocess.Popen(['hostname', '-I'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) img = Image.new("P", (inkyphat.WIDTH, inkyphat.HEIGHT)) draw = ImageDraw.Draw(img) message = str(out.communicate()[0]) w, h = font.getsize(message) x = (inkyphat.WIDTH / 2) - (w / 2) y = (inkyphat.HEIGHT / 2) - (h / 2) draw.text((x, y), message, inkyphat.BLACK, font) inkyphat.set_image(img) inkyphat.show()
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 show_image(infile, temp_data=None, pressure_data=None, humidity_data=None): font = ImageFont.truetype("/usr/local/share/fonts/DejaVuSans.ttf", 14) temp_info = create_informatics(temp_data) press_info = create_informatics(pressure_data) humidity_info = create_informatics(humidity_data) inkyphat.set_image(Image.open(infile)) inkyphat.text((110, 10), "{0:.1f}°F \n {1}".format(temp_data[-1], temp_info), inkyphat.BLACK, font) inkyphat.text((110, 40), "{0:.0f} hPa \n {1}".format(pressure_data[-1], press_info), inkyphat.BLACK, font) inkyphat.text((110, 70), "{0:.0f} %RH \n {1}".format(humidity_data[-1], humidity_info), inkyphat.BLACK, font) inkyphat.show()
def mode1(self): # background image img = Image.open(self.config.background) inkyphat.set_image(img) # Add the price text font = ImageFont.truetype(self.font, 36) price = str("%.3f" % self.price) inkyphat.text((4, 5), price, inkyphat.RED, font) # Add the day change text font = ImageFont.truetype(self.font, 22) day = "%.2f" % self.day if self.day > 0.0: inkyphat.text((7, 42), str(day), inkyphat.BLACK, font) if self.day < 0.0: inkyphat.text((7, 42), str(day), inkyphat.RED, font) # Add the ROI as FIAT if self.config.show_roi == True: font = ImageFont.truetype(self.font, 34) roi = self.price * self.coin_amount roistr = str("%.2f" % roi) inkyphat.text((4, 75), roistr, inkyphat.WHITE, font) # Add the ROI as percentage else: actual_value = self.price * self.coin_amount percentage = (actual_value / self.coin_invest * 100) - 100 font = ImageFont.truetype(self.font, 34) roistr = str("%.2f" % percentage + '%') inkyphat.text((4, 75), roistr, inkyphat.WHITE, font) inkyphat.show()
def mode2(self): # background image img = Image.open(self.config.back_simple) inkyphat.set_image(img) # Add ranking text font = ImageFont.truetype(self.font, 22) inkyphat.text((45, 5), "#" + self.rank, inkyphat.WHITE, font) # Add the price text font = ImageFont.truetype(self.font, 46) price = str("%.3f" % self.price) inkyphat.text((44, 25), price, inkyphat.WHITE, font) # Add the day change text font = ImageFont.truetype(self.font, 22) day = "%.2f" % self.day if self.day > 0.0: inkyphat.text((46, 62), "24h: " + str(day) + "%", inkyphat.WHITE, font) if self.day < 0.0: inkyphat.text((46, 62), "24h: " + str(day) + "%", inkyphat.RED, font) # Add the week change text font = ImageFont.truetype(self.font, 22) week = "%.2f" % self.week if self.week > 0.0: inkyphat.text((47, 82), "7d: " + str(week) + "%", inkyphat.WHITE, font) if self.week < 0.0: inkyphat.text((47, 82), "7d: " + str(week) + "%", inkyphat.RED, font) inkyphat.show()
"APMA 3080", filename) if __name__ == '__main__': inkyphat.set_colour("black") font = ImageFont.truetype(inkyphat.fonts.AmaticSCBold, 38) printOutIP() while (1): encryptedIDnumber = waitingForID( ) #read encrypted version of the ID number if (returnIDnumbers.findIfIDnumberPresent(encryptedIDnumber)): img = Image.new("P", (inkyphat.WIDTH, inkyphat.HEIGHT)) draw = ImageDraw.Draw(img) message = "Welcome" w, h = font.getsize(message) x = (inkyphat.WIDTH / 2) - (w / 2) y = (inkyphat.HEIGHT / 2) - (h / 2) draw.text((x, y), message, inkyphat.BLACK, font) inkyphat.set_image(img) inkyphat.show() #pass #start scanning else: #not in database, generate QR code to assign encrypted ID to a user qr.printQRcode(encryptedIDnumber) #captureAndUploadLoop()
#!/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()
def show_slideshow(self, delay=30): for image in self.standing_images(): inkyphat.set_image(image) inkyphat.show() time.sleep(delay)
self.offset_x = (inkyphat.WIDTH // 2) - (self.pixel_size // 2) if self.offset_y is None: self.offset_y = (inkyphat.HEIGHT // 2) - (self.pixel_size // 2) box = (self.offset_x, self.offset_y, self.offset_x + self.pixel_size - 1, self.offset_y + self.pixel_size - 1) inkyphat.rectangle(box, fill=inkyphat.WHITE) def pixel_box(self, row, col): x = (col + self.border) * self.box_size y = (row + self.border) * self.box_size x += self.offset_x y += self.offset_y return [(x, y), (x + self.box_size - 1, y + self.box_size - 1)] def drawrect(self, row, col): box = self.pixel_box(row, col) inkyphat.rectangle(box, fill=inkyphat.BLACK) inkyphat.set_image("resources/empty-backdrop.png") qr = qrcode.QRCode(version=1, box_size=2, border=2, image_factory=InkyQR) qr.add_data(text) qr.make(fit=True) qr.make_image() inkyphat.show()
g_font = ImageFont.truetype(inkyphat.fonts.FredokaOne, 15) s_font = ImageFont.truetype(inkyphat.fonts.FredokaOne, 12) b_font = ImageFont.truetype(inkyphat.fonts.FredokaOne, 9) u_font = ImageFont.truetype(inkyphat.fonts.FredokaOne, 8) res = get(PSNPROFILES + user + '/log?page=0') res.raise_for_status() soup = BeautifulSoup(res.text, 'html.parser') level = soup.select('.trophy-count > ul > li') level = level[0].text.strip() bronze_count = db.session.query(func.count(trophies.Number)). \ filter(trophies.Rank == bronze).scalar() silver_count = db.session.query(func.count(trophies.Number)). \ filter(trophies.Rank == silver).scalar() gold_count = db.session.query(func.count(trophies.Number)). \ filter(trophies.Rank == gold).scalar() plat_count = db.session.query(func.count(trophies.Number)). \ filter(trophies.Rank == platinum).scalar() inkyphat.set_image(Image.open("trophies-bw.png")) inkyphat.text((23, 43), str(plat_count), inkyphat.BLACK, p_font) inkyphat.text((72, 64), str(gold_count), inkyphat.BLACK, g_font) inkyphat.text((124, 76), str(silver_count), inkyphat.BLACK, s_font) inkyphat.text((169, 90), str(bronze_count), inkyphat.BLACK, b_font) inkyphat.text((1, 95), updated, inkyphat.BLACK, u_font) inkyphat.text((124, 1), user, inkyphat.WHITE, s_font) inkyphat.text((172, 29), str(level), inkyphat.WHITE, s_font) inkyphat.show()
unit="C" if args.celsius else "F"), red, font=font) y_pos += 11 draw.text((105, y_pos), "{text}: {temp}°{unit}".format(text=max_text, temp=max_temp, unit="C" if args.celsius else "F"), red, font=font) y_pos += 11 draw.text((105, y_pos), "{0}: {1}%".format(pop_text, pop), red, font=font) # Draw the weather icon 4 pixels away from the right of the screen weather_w = draw.textsize(weather_icon, font=weather_font)[0] draw.text((212 - weather_w - 5, 4), weather_icon, black, font=weather_font) # Trick I saw somewhere: Create a new image just to hold our needed palette pal_image = Image.new('P', (1, 1)) # Fill our 256 colors in the palette with: 1. black, 2. white, 3. red, then black until the end. pal_image.putpalette((255, 255, 255, 0, 0, 0, 255, 0, 0) + (0, 0, 0) * 253) # Quantize the image we built down to 3 colors, using palette from the dummy image above finalimage = base.convert("RGB").quantize(palette=pal_image) # Save image because it's cool to see the previous days finalimage.save("PokeInkDis-{0}-#{1}.png".format(today.strftime('%Y-%m-%d'), str(poke_num).zfill(3))) # Finally, use the inkyphat library to draw the image we built to the screen inkyphat.set_border(inkyphat.RED) inkyphat.set_image(finalimage) inkyphat.show()
else: print("Warning, no weather information found!") # Load our icon files and generate masks for icon in glob.glob("resources/icon-*.png"): icon_name = icon.split("icon-")[1].replace(".png", "") icon_image = Image.open(icon) icons[icon_name] = icon_image masks[icon_name] = inkyphat.create_mask(icon_image) # Load the built-in FredokaOne font font = ImageFont.truetype(inkyphat.fonts.FredokaOne, 22) # Load our backdrop image inkyphat.set_image("resources/inkyalfa.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 datetime = time.strftime("%d/%m %H:%M") inkyphat.text((36, 12), datetime, inkyphat.WHITE, font=font) inkyphat.text((72, 34), "T", inkyphat.WHITE, font=font) inkyphat.text((92, 34),
def image(file): inkyphat.clear() inkyphat.set_image(Image.open(file)) inkyphat.show()
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")) inkyphat.show()
box = (self.offset_x, self.offset_y, self.offset_x + self.pixel_size - 1, self.offset_y + self.pixel_size - 1) inkyphat.rectangle(box, fill=inkyphat.WHITE) def pixel_box(self, row, col): x = (col + self.border) * self.box_size y = (row + self.border) * self.box_size x += self.offset_x y += self.offset_y return [(x, y), (x + self.box_size - 1, y + self.box_size - 1)] def drawrect(self, row, col): box = self.pixel_box(row, col) inkyphat.rectangle(box, fill=inkyphat.BLACK) inkyphat.set_image("inky-phat/examples/resources/empty-backdrop.png") qr = qrcode.QRCode( version=1, box_size=2, border=2, image_factory=InkyQR ) qr.add_data(text) qr.make(fit=True) qr.make_image() inkyphat.show()
def main(): mySettings = settingsClass() # get settings from db mySunrise = sunRiseSet() # Get sunrise and sunset from DB mySunrise.getSunriseset(); myWeather = weather() myWeather.getWeather() #inkyphat.set_border(inkyphat.WHITE) if (myWeather.wind_dir in ('South')): inkyphat.set_image("/home/pi/pythonCode/resources/compass_s.png") elif (myWeather.wind_dir in ('SW', 'SSW')): inkyphat.set_image("/home/pi/pythonCode/resources/compass_sw.png") elif (myWeather.wind_dir in ('SE', 'SSE')): inkyphat.set_image("/home/pi/pythonCode/resources/compass_se.png") elif (myWeather.wind_dir in ('North', 'NNW', 'NNE')): inkyphat.set_image("/home/pi/pythonCode/resources/compass_n.png") elif (myWeather.wind_dir in ('West', 'WSW', 'WNW')): inkyphat.set_image("/home/pi/pythonCode/resources/compass_w.png") elif (myWeather.wind_dir in ('East', 'ESE', 'ENE')): inkyphat.set_image("/home/pi/pythonCode/resources/compass_e.png") else: #if (myWeather.wind_dir in ('S', 'SE', 'SW', 'NE', 'N', 'NW', 'W', 'S')): imgFile = "/home/pi/pythonCode/resources/compass_{0}.png".replace('{0}', myWeather.wind_dir.lower()) inkyphat.set_image(imgFile) printTitle("Tank") printText(1, "Sunrise:", mySunrise.sunrise.isoformat()[0:8], '') printText(2, "Sunset:", mySunrise.sunset.isoformat()[0:8], '') printText(3, "Water:", mySettings.settings["pumpduration"], 'min') temp_c = str(myWeather.temp_c) windchill_c = str(myWeather.windchill_c) printText(4, "Temp:", temp_c + 'c w/c ' + windchill_c , 'c') printText(5, "Weather:", myWeather.weather, '') wind_mph = str(myWeather.wind_mph) wind_gust_mph = str(myWeather.wind_gust_mph) printText(6, "Wind:", myWeather.wind_dir + " spd: " + wind_mph + 'g: ' + wind_gust_mph, '') inkyphat.show() # And show it!
def display_happy(filename): inkyphat.set_border(inkyphat.BLACK) inkyphat.set_image(Image.open(filename)) inkyphat.show() return
else: print("Warning, no weather information found!") print("Processing done") # Display font = ImageFont.truetype("/home/pi/Pimoroni/inkyphat/fonts/elec.ttf", 10) fontsm = ImageFont.truetype("/home/pi/Pimoroni/inkyphat/fonts/elec.ttf", 6) fontlg = ImageFont.truetype("/home/pi/Pimoroni/inkyphat/fonts/elec.ttf", 16) inkyphat.set_rotation(180) inkyphat.set_colour('red') inkyphat.set_border(inkyphat.BLACK) # Load the backdrop image inkyphat.set_image( "/home/pi/Pimoroni/inkyphat/examples/resources/inkyphat-bg3.png") # Print text # Top Left inkyphat.text((6, 7), datetime, inkyphat.BLACK, font=font) # Left inkyphat.text((6, 21), ''.join(map(str, get_up_stats())), inkyphat.BLACK, font=font) inkyphat.text( (6, 31), "T" + str(get_temperature()) + "C PR:" + str(get_process_count()), inkyphat.BLACK, font=font) inkyphat.text((6, 41),
import csv from PIL import Image, ImageFont import inkyphat import os # INIT inkyphat.set_border(inkyphat.BLACK) skm_timetable_file = os.path.abspath("/home/pi/inky/examples/skm.csv") calendar_file = os.path.abspath( "/home/pi/inky/examples/resources/calendar.png") background_file = os.path.abspath( "/home/pi/inky/examples/resources/empty-backdrop.png") text = Image.open(calendar_file) text_mask = inkyphat.create_mask(text, [inkyphat.WHITE]) inkyphat.set_image(background_file) col_w = 20 col_h = 13 cols = 3 rows = 6 cal_w = 1 + ((col_w + 1) * cols) cal_h = 1 + ((col_h + 1) * rows) cal_x = inkyphat.WIDTH - cal_w - 2 cal_y = 2 # Paint out a black rectangle onto which we'll draw our canvas inkyphat.rectangle((cal_x, cal_y, cal_x + cal_w - 1, cal_y + cal_h - 1), fill=inkyphat.BLACK,
def on_status(self, tweet): tweet_to_check = tweet.text # checks the tweet does_the_tweet_contain_key_word = tweet_to_check.find( "@Dan_Aldred") ### find MENTIONS replace with your Twitter handle does_the_tweet_contain_STAR_WARS = tweet_to_check.find( "#StarWars") ### find star wars hash tag print(does_the_tweet_contain_key_word) try: if does_the_tweet_contain_key_word >= 0: user = tweet.user.screen_name #gets the user name print(user) ###prints the user's name # responds to a mention @dan_aldred inkyphat.set_image(Image.open("/home/pi/StarWars/MENTION.png")) inkyphat.show() inkyphat.clear() ###### display message #### print(tweet_to_check) message = tweet_to_check txt = textwrap.fill(message, 31) w, h = inkyphat._draw.multiline_textsize(txt, font) x = (inkyphat.WIDTH / 2) - (w / 2) y = (inkyphat.HEIGHT / 2) - (h / 2) inkyphat._draw.multiline_text((x, y), txt, inkyphat.BLACK, font) inkyphat.show() time.sleep(2) inkyphat.clear() ### STAR WARS response elif does_the_tweet_contain_STAR_WARS >= 0: ### display SW intro picture ### print("star wars picture") print("star wars rleated tweet") inkyphat.set_image(Image.open("/home/pi/StarWars/STAR.png")) inkyphat.show() time.sleep(1) inkyphat.clear() # SHOW MESSAGE print(tweet_to_check) message = tweet_to_check txt = textwrap.fill(message, 31) w, h = inkyphat._draw.multiline_textsize(txt, font) x = (inkyphat.WIDTH / 2) - (w / 2) y = (inkyphat.HEIGHT / 2) - (h / 2) inkyphat._draw.multiline_text((x, y), txt, inkyphat.BLACK, font) inkyphat.show() time.sleep(10) inkyphat.clear() else: inkyphat.clear() pass except: ### if there is an emoji and the tweet cannot be displayed print("Cannot render tweet") inkyphat.set_image(Image.open("/home/pi/StarWars/FAIL.png")) inkyphat.show() time.sleep(1) inkyphat.clear()
def viv_display(th, tr, tc, hh): # display readinga and any alerts on inkyphat #logger.debug("Setting inkyphat") iclear(0) # load background image inkyphat.set_image(Image.open("/home/pi/snake-back.png")) # set font sizes font = ImageFont.truetype(inkyphat.fonts.FredokaOne, 28) smallfont = ImageFont.truetype(inkyphat.fonts.FredokaOne, 10) midfont = ImageFont.truetype(inkyphat.fonts.FredokaOne, 16) # Top left box for hot-end temp inkyphat.rectangle([2, 2, 70, 25], fill=inkyphat.BLACK, outline=1) inkyphat.rectangle([2, 2, 70, 70], fill=None, outline=1) #top left message = "HOT" inkyphat.text((20, 3), message, inkyphat.WHITE, midfont) if th > 28 and th < 31: inkyphat.text((8, 25), str(th), inkyphat.BLACK, font) else: inkyphat.text((8, 25), str(th), inkyphat.RED, font) #Middle box for roof temp inkyphat.rectangle([74, 2, 142, 25], fill=inkyphat.BLACK, outline=1) # top middle inkyphat.rectangle([74, 2, 142, 70], fill=None, outline=1) message = "ROOF" inkyphat.text((88, 3), message, inkyphat.WHITE, midfont) if tr > 34 and tr < 37: inkyphat.text((81, 25), str(tr), inkyphat.BLACK, font) else: inkyphat.text((81, 25), str(tr), inkyphat.RED, font) # Right box for cool end temp inkyphat.rectangle([146, 2, 210, 25], fill=inkyphat.BLACK, outline=1) # top middle inkyphat.rectangle([146, 2, 210, 70], fill=None, outline=1) message = "COOL" inkyphat.text((156, 3), message, inkyphat.WHITE, midfont) if tc > 21 and tc < 27: inkyphat.text((152, 25), str(tc), inkyphat.BLACK, font) else: inkyphat.text((152, 25), str(tc), inkyphat.RED, font) # Bottom left box for humidity inkyphat.rectangle([12, 74, 55, 100], fill=inkyphat.BLACK, outline=1) # top middle inkyphat.rectangle([12, 74, 102, 100], fill=None, outline=1) message = "Hum" inkyphat.text((16, 80), message, inkyphat.WHITE, midfont) if hh > 20 and hh < 75: inkyphat.text((62, 78), str(hh) + "%", inkyphat.BLACK, midfont) else: inkyphat.text((62, 78), str(hh) + "%", inkyphat.RED, midfont) # Bottom middle for time rightnow = dt.now() inkyphat.text((110, 70), str("%02d" % (rightnow.hour, )) + ":" + str("%02d" % (rightnow.minute, )), inkyphat.RED, font) #print("Displaying on inkyphat") inkyphat.show()
print('Defaulting to "red"') inkyphat.set_border(inkyphat.BLACK) #inkyphat.set_rotation(180) # Load our sprite sheet and prepare a mask text = Image.open("/home/pi/scripts/resources/calendar.png") text_mask = inkyphat.create_mask(text, [inkyphat.WHITE]) # Note: The mask determines which pixels from our sprite sheet we want # to actually use when calling inkyphat.paste # which uses PIL's Image.paste() method, # See: http://pillow.readthedocs.io/en/3.1.x/reference/Image.html?highlight=paste#PIL.Image.Image.paste # Load our backdrop image inkyphat.set_image("/home/pi/scripts/resources/empty-backdrop.png") # Grab the current date, and prepare our calendar cal = calendar.Calendar() now = datetime.datetime.now() dates = cal.monthdatescalendar(now.year, now.month) col_w = 20 col_h = 13 cols = 7 rows = len(dates) + 1 cal_w = 1 + ((col_w + 1) * cols) cal_h = 1 + ((col_h + 1) * rows)
def image(file): inkyphat.clear() inkyphat.set_colour('red') inkyphat.set_image(Image.open(file)) inkyphat.show()
with io.BytesIO() as f: fig.savefig(f, dpi=dpi, cmap="bwr", interpolation="none", origin="lower", pad_inches=0) #bbox_inches='tight') f.seek(0) i = Image.open(f) #.convert('P', palette=(0,1,2)) d = ImageDraw.Draw(i) ypos = 0 if ymax - last_high > last_low - ymin else h - 6 if not args.output: from inkyphat import RED, BLACK, text, set_image, set_rotation, show set_image(i) if args.flip: set_rotation(180) else: RED = (255, 0, 0) BLACK = (0, 0, 0) text = d.text text((148, ypos), '{:.2f}'.format(last_close), BLACK, font) text((176, ypos), args.pair, RED, font) if args.output: i.save(args.output) raise SystemExit show()
boiler_state = (redthis.get("boiler/req")) except: local_temperature=0 mean_temperature=0 outside_temperature=0 boiler_state = False weather_icon = None bob_icon = None # Load the built-in FredokaOne font font = ImageFont.truetype(inkyphat.fonts.FredokaOne, 20) font2 = ImageFont.truetype(inkyphat.fonts.FredokaOne, 18) # 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 datetime = time.strftime("%d %b %Y") inkyphat.text((50, 3), datetime, inkyphat.WHITE, font=font2) inkyphat.text((160, 24), u"{:.1f}°".format(local_temperature), inkyphat.WHITE if local_temperature < WARNING_TEMP else inkyphat.RED, font=font)
#!/usr/bin/env python3 import sys import sys, subprocess, urllib, time, tweepy from PIL import Image from PIL import ImageFont import time import inkyphat import textwrap font = ImageFont.truetype(inkyphat.fonts.FredokaOne, 12) inkyphat.set_image(Image.open("/home/pi/StarWars/WAIT.png")) inkyphat.show() inkyphat.clear() time.sleep(10) # == OAuth Authentication == # # This mode of authentication is the new preferred way # of authenticating with Twitter. # The consumer keys can be found on your application's Details # page located at https://dev.twitter.com/apps (under "OAuth settings") consumer_key = 'xxxxxxxxxxxxxxxxx' consumer_secret = 'xxxxxxxxxxxxxxxxx' # The access tokens can be found on your applications's Details # page located at https://dev.twitter.com/apps (located # under "Your access token") access_token = 'xxxxxxxxxx'
#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) name = sys.argv[1] w, h = font.getsize(name) # Center the text and align it with the name strip
colour = sys.argv[2] try: inkyphat.set_colour(colour) except ValueError: print('Invalid colour "{}" for V{}\n'.format(sys.argv[2], inkyphat.get_version())) if inkyphat.get_version() == 2: print(USAGE) sys.exit(1) print('Defaulting to "red"') # Show the backdrop image inkyphat.set_border(inkyphat.RED) inkyphat.set_image("/home/pi/scripts/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) name = sys.argv[1] w, h = font.getsize(name) # Center the text and align it with the name strip