sets up weather pane with UI and time data
This commit is contained in:
parent
0d46227f8b
commit
b830c98fa3
7
.gitignore
vendored
7
.gitignore
vendored
@ -1 +1,8 @@
|
|||||||
/__pycache__/
|
/__pycache__/
|
||||||
|
|
||||||
|
# Effie's python environment
|
||||||
|
/bin
|
||||||
|
/include
|
||||||
|
/lib
|
||||||
|
/lib64
|
||||||
|
pyvenv.cfg
|
||||||
BIN
NETWORKSANS-2019-REGULAR.TTF
Normal file
BIN
NETWORKSANS-2019-REGULAR.TTF
Normal file
Binary file not shown.
87
__main__.py
87
__main__.py
@ -9,64 +9,47 @@ BLACK = 0x000000 # 00 BGR
|
|||||||
WHITE = 0xffffff # 01
|
WHITE = 0xffffff # 01
|
||||||
YELLOW = 0x00ffff # 10
|
YELLOW = 0x00ffff # 10
|
||||||
RED = 0x0000ff # 11
|
RED = 0x0000ff # 11
|
||||||
font18 = ImageFont.truetype('Font.ttc', 18)
|
fontmm = ImageFont.truetype('NETWORKSANS-2019-REGULAR.TTF', 20)
|
||||||
font24 = ImageFont.truetype('Font.ttc', 24)
|
font24 = ImageFont.truetype('NETWORKSANS-2019-REGULAR.TTF', 24)
|
||||||
font40 = ImageFont.truetype('Font.ttc', 40)
|
font42 = ImageFont.truetype('NETWORKSANS-2019-REGULAR.TTF', 42)
|
||||||
font64 = ImageFont.truetype('Font.ttc', 64)
|
font64 = ImageFont.truetype('NETWORKSANS-2019-REGULAR.TTF', 64)
|
||||||
font100 = ImageFont.truetype('Font.ttc', 100)
|
fonttime = ImageFont.truetype('NETWORKSANS-2019-REGULAR.TTF', 92)
|
||||||
|
|
||||||
image = Image.new('RGB', (800, 480), WHITE)
|
image = Image.new('RGB', (800, 480), WHITE)
|
||||||
draw = ImageDraw.Draw(image)
|
draw = ImageDraw.Draw(image)
|
||||||
|
|
||||||
# Date/time
|
|
||||||
|
# Backing image
|
||||||
|
with Image.open('ui test 2.png').convert('RGBA') as bg:
|
||||||
|
image.paste(bg, (0, 0))
|
||||||
|
|
||||||
|
# Time
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
draw.text((10, 480-10-64), f'{now:%y/%m/%d}', font=font64, fill=BLACK)
|
draw.text((-3, 480-3), f'{now:%H:%M}', font=fonttime, anchor="ls", fill=WHITE)
|
||||||
draw.text((10, 480-10-64-10-100), f'{now:%I:%M}', font=font100, fill=BLACK)
|
|
||||||
|
|
||||||
# TODO: weather
|
# Date
|
||||||
draw.text((10, 10), '?mm', font=font64, fill=BLACK)
|
dateday = f'{now:%d}'
|
||||||
draw.text((10, 10+64), '20°', font=font100, fill=BLACK)
|
draw.text((-3, 320), dateday, font=font64, anchor="ls", fill=WHITE)
|
||||||
draw.text((10, 10+64+100), '6° - 24°', font=font64, fill=BLACK)
|
datedaylength = draw.textlength(dateday, font=font64)
|
||||||
|
draw.text((datedaylength + 5, 320), f'{now:%b}', font=font64, anchor="lt", fill=WHITE)
|
||||||
|
|
||||||
# Bus
|
# Temperature
|
||||||
y = 0
|
temp = 6
|
||||||
with Image.open('icon_bus.png') as icon:
|
temphigh = 12
|
||||||
image.paste(scale_to_height(icon), (230, y+50))
|
draw.text((-3, 200), f'{temp}°', font=font64, anchor="ls", fill=WHITE)
|
||||||
draw.polygon((200, 0, 475, 0, 475, 50, 212.5, 50), fill=BLACK)
|
draw.text((123, 237), f'{temphigh}', font=font42, anchor="ms", fill=WHITE)
|
||||||
draw.text((215, y+5+16), 'Camberwell', font=font24, fill=WHITE)
|
|
||||||
draw.text((400, y+5), '612 S', font=font40, fill=WHITE, anchor='ma')
|
|
||||||
draw.text((400, y+55), '15', font=font64, fill=BLACK, anchor='ma')
|
|
||||||
draw.text((550, y+5), '612 N', font=font40, fill=BLACK, anchor='ma')
|
|
||||||
draw.text((550, y+55), '5', font=font64, fill=BLACK, anchor='ma')
|
|
||||||
draw.text((700, y+5), '766 N', font=font40, fill=BLACK, anchor='ma')
|
|
||||||
draw.text((700, y+55), '20', font=font64, fill=BLACK, anchor='ma')
|
|
||||||
|
|
||||||
# Train
|
# Rainfall
|
||||||
y = 160
|
rainfall = 3
|
||||||
with Image.open('icon_train.png') as icon:
|
rainthreshold = 5
|
||||||
image.paste(scale_to_height(icon), (280, y+50))
|
if rainfall > rainthreshold:
|
||||||
draw.polygon((240, 160, 595, 160, 595, 210, 252.5, 210), fill=BLACK)
|
rainimgpath = 'rain.png'
|
||||||
draw.text((255, y+5+16), 'City', font=font24, fill=WHITE)
|
else:
|
||||||
draw.text((400, y+5), 'Express', font=font40, fill=WHITE, anchor='ma')
|
rainimgpath = 'sun.png'
|
||||||
draw.text((400, y+55), '15', font=font64, fill=BLACK, anchor='ma')
|
draw.text((40, 0), f'{rainfall}', font=font64, anchor="mt")
|
||||||
draw.text((550, y+5), 'All', font=font40, fill=WHITE, anchor='ma')
|
with Image.open(rainimgpath) as rainimg:
|
||||||
draw.text((550, y+55), '5', font=font64, fill=BLACK, anchor='ma')
|
image.paste(rainimg,mask=rainimg)
|
||||||
draw.text((700, y+5), 'Outbound', font=font40, fill=BLACK, anchor='ma')
|
draw.text((40, 55), f'mm', font=fontmm, anchor="mt")
|
||||||
draw.text((700, y+55), '20', font=font64, fill=BLACK, anchor='ma')
|
|
||||||
|
|
||||||
# Tram (y=320 to 470)
|
|
||||||
y = 320
|
|
||||||
with Image.open('icon_tram.png') as icon:
|
|
||||||
image.paste(scale_to_height(icon), (310, y+50))
|
|
||||||
draw.polygon((280, 320, 800, 320, 800, 370, 292.5, 370), fill=BLACK)
|
|
||||||
draw.text((295, y+5+16), 'City', font=font24, fill=WHITE)
|
|
||||||
draw.text((550, y+5), '109', font=font40, fill=WHITE, anchor='ma')
|
|
||||||
draw.text((550, y+55), '7', font=font64, fill=BLACK, anchor='ma')
|
|
||||||
draw.text((700, y+5), '70', font=font40, fill=WHITE, anchor='ma')
|
|
||||||
draw.text((700, y+55), '14', font=font64, fill=BLACK, anchor='ma')
|
|
||||||
|
|
||||||
# Line between left and right
|
|
||||||
draw.line((200, 0, 400, 800), fill=BLACK)
|
|
||||||
|
|
||||||
image.save('test_before_palette.png')
|
image.save('test_before_palette.png')
|
||||||
|
|
||||||
@ -74,8 +57,8 @@ image.save('test_before_palette.png')
|
|||||||
pal_image = Image.new('P', (1, 1))
|
pal_image = Image.new('P', (1, 1))
|
||||||
pal_image.putpalette((0x00,0x00,0x00, 0xff,0xff,0xff, 0xff,0xff,0x00, 0xff,0x00,0x00) + (0x00,0x00,0x00)*252)
|
pal_image.putpalette((0x00,0x00,0x00, 0xff,0xff,0xff, 0xff,0xff,0x00, 0xff,0x00,0x00) + (0x00,0x00,0x00)*252)
|
||||||
# Convert the source image to the 4 colors, dithering if needed
|
# Convert the source image to the 4 colors, dithering if needed
|
||||||
image_4color = image.quantize(palette=pal_image)
|
image_4color = image.quantize(palette=pal_image, dither=Image.NONE)
|
||||||
image_4color.save('test.png')
|
image_4color.save('test_after_palette.png')
|
||||||
|
|
||||||
show_on_screen = False
|
show_on_screen = False
|
||||||
if show_on_screen:
|
if show_on_screen:
|
||||||
|
|||||||
1
requirements.txt
Normal file
1
requirements.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
pillow==11.2.1
|
||||||
BIN
test_after_palette.png
Normal file
BIN
test_after_palette.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 10 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 100 KiB After Width: | Height: | Size: 42 KiB |
Loading…
Reference in New Issue
Block a user