Skip to content

Instantly share code, notes, and snippets.

@stonecharioteer
Created September 30, 2018 16:40
Show Gist options
  • Save stonecharioteer/99efcd42eb8a305afd2b6e69e0760b53 to your computer and use it in GitHub Desktop.
Save stonecharioteer/99efcd42eb8a305afd2b6e69e0760b53 to your computer and use it in GitHub Desktop.
Function to print the kana question to WaveShare screen.
def test_romaji_hiragana(romaji, options):
"""Prints a question to the screen, asking which of the
printed hiragana correspond to the given romaji."""
from epd import epd2in7b as epdlib
from PIL import Image, ImageDraw, ImageFont
# TODO: Make a library for this.
canvas_width, canvas_height = 264, 176
canvas_black = Image.new(
"L",
(canvas_width, canvas_height),
"#ffffff")
canvas_red = Image.new(
"L",
(canvas_width, canvas_height),
"#ffffff")
font_path = "fonts/rounded-mgenplus-1p-regular.ttf"
font_en = ImageFont.truetype(font_path, 20)
font_nh = ImageFont.truetype(font_path, 18)
draw = ImageDraw.Draw(canvas_black)
msg_1 = u"What is the hiragana for\n'{}'?".format(romaji)
logging.debug(msg_1)
draw.text(
(2, 5),
msg_1,
fill = "#000000",
font=font_en
)
msg_2 = u"[1] {0} [2] {1}\n\n[3] {2} [4] {3}".format(*options)
logging.debug(msg_2)
draw.text(
(40,70),
msg_2,
fill = "#000000",
font=font_nh
)
epd = epdlib.EPD()
epd.init()
canvas_black = canvas_black.transpose(Image.ROTATE_90)
canvas_red = canvas_red.transpose(Image.ROTATE_90)
frame_black = epd.get_frame_buffer(canvas_black)
frame_red = epd.get_frame_buffer(canvas_red)
epd.display_frame(frame_black, frame_red)
answer = get_input()
return options[answer-1] if answer is not None else None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment