This commit is contained in:
2025-02-06 09:52:08 +00:00
parent 19c2950ae4
commit 3333871947
3 changed files with 72 additions and 60 deletions

6
.gitignore vendored
View File

@@ -171,4 +171,8 @@ cython_debug/
.ruff_cache/ .ruff_cache/
# PyPI configuration file # PyPI configuration file
.pypirc .pypirc
*.bmp
*.png

View File

@@ -1,48 +1,8 @@
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
from datetime import datetime
from time import gmtime, strftime
import time
black = '#000000'
white = '#ffffff'
image = Image.new("P", (400, 300))
draw = ImageDraw.Draw(image)
fontSymbols = ImageFont.truetype("SymbolsNerdFont-Regular.ttf", 18)
fontTitle = ImageFont.truetype("Nunito-SemiBold.ttf", 24)
fontLarge = ImageFont.truetype ("Nunito-ExtraLight.ttf", 18)
fontSmall = ImageFont.truetype ("Nunito-ExtraLight.ttf", 16)
fontVerySmall = ImageFont.truetype("Nunito-ExtraLight.ttf", 10)
# Draw the top bar
draw.rectangle((0, 0, 400, 300), fill=white)
draw.rectangle((0, 0, 400, 40), fill=black)
# Add the clock
timeStr = strftime("%H:%M", time.localtime())
draw.text((10, 10), timeStr, white, fontSmall)
# Add indoor tempriture
draw.text((350, 10), "19c", white, fontSmall)
# Add tasks
draw.text((10, 50), 'Tasks', black, fontTitle)
draw.text((10, 90), '󰄱', black, fontSymbols)
draw.text((30, 87), 'Do a thing', black, fontLarge)
draw.text((10, 120), '󰄵', black, fontSymbols)
draw.text((30, 117), 'Done a thing', black, fontLarge)
# image.save('built.bmp')
from inky import InkyWHAT from inky import InkyWHAT
from inky.auto import auto from inky.auto import auto
from building import draw_image
display = auto(verbose = True) display = auto(verbose = True)
image = draw_image()
display.set_image(image) display.set_image(image)
display.show() display.show()

View File

@@ -8,8 +8,6 @@ import time
black = '#000000' black = '#000000'
white = '#ffffff' white = '#ffffff'
image = Image.new("P", (400, 300))
draw = ImageDraw.Draw(image)
fontSymbols = ImageFont.truetype("SymbolsNerdFont-Regular.ttf", 18) fontSymbols = ImageFont.truetype("SymbolsNerdFont-Regular.ttf", 18)
fontTitle = ImageFont.truetype("Nunito-SemiBold.ttf", 24) fontTitle = ImageFont.truetype("Nunito-SemiBold.ttf", 24)
@@ -17,26 +15,76 @@ fontLarge = ImageFont.truetype ("Nunito-ExtraLight.ttf", 18)
fontSmall = ImageFont.truetype ("Nunito-ExtraLight.ttf", 16) fontSmall = ImageFont.truetype ("Nunito-ExtraLight.ttf", 16)
fontVerySmall = ImageFont.truetype("Nunito-ExtraLight.ttf", 10) fontVerySmall = ImageFont.truetype("Nunito-ExtraLight.ttf", 10)
# Draw the top bar def getsize(font, text):
draw.rectangle((0, 0, 400, 300), fill=white) _, _, right, bottom = font.getbbox(text)
draw.rectangle((0, 0, 400, 40), fill=black) return (right, bottom)
# Add the clock def reflow_quote(quote, width, font):
timeStr = strftime("%H:%M", time.localtime()) words = quote.split(" ")
draw.text((10, 10), timeStr, white, fontSmall) reflowed = ''
line_length = 0
# Add indoor tempriture for i in range(len(words)):
draw.text((350, 10), "19c", white, fontSmall) word = words[i] + " "
word_length = getsize(font, word)[0]
line_length += word_length
# Add tasks if line_length < width:
draw.text((10, 50), 'Tasks', black, fontTitle) reflowed += word
else:
line_length = word_length
reflowed = reflowed[:-1] + "\n " + word
draw.text((10, 90), '󰄱', black, fontSymbols) reflowed = reflowed.rstrip()
draw.text((30, 87), 'Do a thing', black, fontLarge)
return reflowed
draw.text((10, 120), '󰄵', black, fontSymbols) def draw_image():
draw.text((30, 117), 'Done a thing', black, fontLarge) image = Image.new("P", (400, 300))
draw = ImageDraw.Draw(image)
# Draw the top bar
draw.rectangle((0, 0, 400, 300), fill=white)
draw.rectangle((0, 0, 400, 40), fill=black)
image.save('built.bmp') # Add the clock
timeStr = strftime("%H:%M", time.localtime())
draw.text((10, 10), timeStr, white, fontSmall)
# Add indoor tempriture
draw.text((350, 10), "19c", white, fontSmall)
# Add sections
ep = 5
draw.rounded_rectangle((ep, 40+ep, (400/2)-ep, 300-ep), 10, outline=black)
draw.rounded_rectangle(((400/2) + ep, 40+ep, 400-ep, 300-ep), 10, outline=black)
# Add tasks
draw.text((15, 50), 'Tasks', black, fontTitle)
tasks = [
{'done': False, 'title': 'Something'},
{'done': True, 'title': 'Get the Modus and Audi MOTs organised'},
{'done': False, 'title': 'Something else'},
{'done': False, 'title': 'Call locksmith'},
]
taskStart = 90
for task in tasks:
if task['done']:
draw.text((15, taskStart), '󰄵', black, fontSymbols)
else:
draw.text((15, taskStart), '󰄱', black, fontSymbols)
reflowedTitle = reflow_quote(task['title'], 170, fontLarge)
titleSizeW, titleSizeH = getsize(fontLarge, reflowedTitle)
titleSizeH *= (reflowedTitle.count('\n') + 1)
draw.text((35, taskStart - 3), reflowedTitle, black, fontLarge)
taskStart += titleSizeH + (2*ep)
return image
if __name__ == "__main__":
img = draw_image()
img.save('built.bmp')