Skip to content

Instantly share code, notes, and snippets.

@emceeaich
Created March 11, 2019 06:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emceeaich/73834e4cf63ea95e11dea618955dc723 to your computer and use it in GitHub Desktop.
Save emceeaich/73834e4cf63ea95e11dea618955dc723 to your computer and use it in GitHub Desktop.
Namebadge Controller
from inky import InkyPHAT
from PIL import Image, ImageFont, ImageDraw
from font_fredoka_one import FredokaOne
from flask import Flask
index_str = """\
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
%s<br>
<a href="/she">Feminine pronouns</a><br>
<a href="/they">Non-binary pronouns</a>
</body>
</html>
"""
app = Flask(__name__)
@app.route("/")
@app.route("/index")
def index():
return index_str % "Pick your pronouns"
@app.route("/she")
def she():
update("she/her")
return index_str % "Set feminine pronouns"
@app.route("/they")
def they():
update("they/their")
return index_str % "Set non-binary pronouns"
return redirect(url_for('index'))
def update(str):
inky_display = InkyPHAT("red");
inky_display.set_border(inky_display.WHITE)
img = Image.new("P", (inky_display.WIDTH, inky_display.HEIGHT))
draw = ImageDraw.Draw(img)
font = ImageFont.truetype(FredokaOne, 22)
# section the display into two parts
offset = inky_display.HEIGHT / 2
# do the first line of text
line1 = "@triagegirl"
w1, h1 = font.getsize(line1)
x = (inky_display.WIDTH / 2) - (w1 / 2)
y = ((inky_display.HEIGHT - offset) / 2) - (h1 / 2) + offset
draw.text((x, y), line1, inky_display.RED, font)
# do the second line of text
line2 = 'Emma (%s)' % str
w2, h2 = font.getsize(line2)
x = (inky_display.WIDTH / 2) - (w2 / 2)
y = ((inky_display.HEIGHT - offset) / 2) - (h2 / 2)
draw.text((x, y), line2, inky_display.BLACK, font)
inky_display.set_image(img)
inky_display.show()
if __name__ == "__main__":
app.run(host='0.0.0.0', port=8080, debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment