Fix UI, use DejaVuMono

This commit is contained in:
ABelliqueux 2024-03-24 21:11:20 +01:00
parent 16db9c6309
commit 01e10dbaee
2 changed files with 21 additions and 14 deletions

BIN
DejaVuSansMono.ttf Normal file

Binary file not shown.

View File

@ -15,7 +15,9 @@ import RPi.GPIO as GPIO
from luma.core.interface.serial import i2c
from luma.core.render import canvas
from luma.oled.device import ssd1306
from PIL import Image, ImageDraw
from PIL import Image, ImageDraw, ImageFont
jfont = ImageFont.truetype('DejaVuSansMono.ttf', 10)
# MPD config
off_delay = 3
@ -50,10 +52,10 @@ btn_height = 10
menu_line_width = 1
menu_bar_y = device.height - btn_height - menu_line_width - 1
ui_text_x = 4
ui_vol_width = 6
ui_vol_y = 4
ui_vol_x = device.width - ui_vol_width - 8
ui_vol_icon_coords = (ui_vol_x - 10, 4)
ui_vol_width = 18
ui_vol_y = menu_bar_y - 14
ui_vol_x = device.width - ui_vol_width
ui_vol_icon_coords = (ui_vol_x - 10, ui_vol_y+2)
ui_vol_icon_polygon = [0,3,3,3,8,0,8,8,3,5,0,5]
play_icon = [0,0,8,4,0,8]
# ~ play_icon_ = [0,0,8,4,0,8]
@ -189,24 +191,24 @@ def update_display(device, currentsong:dict, status:dict, mode:str, cursor_pos:i
# Draw dynamic UI
ui = static_ui.copy()
draw = ImageDraw.Draw(ui)
draw.text((ui_vol_x, ui_vol_y), status['volume'], fill="white")
if mode == 'playback':
if len(currentsong):
draw.text((ui_text_x, 2), currentsong['artist'], fill="white")
draw.text((ui_text_x, 14), currentsong['title'], fill="white")
draw.text((ui_text_x, 26), currentsong['album'], fill="white")
draw.text((ui_text_x, 2), currentsong['artist'], fill="white", font=jfont)
draw.text((ui_text_x, 14), currentsong['title'], fill="white", font=jfont)
draw.text((ui_text_x, 26), currentsong['album'], fill="white", font=jfont)
if 'elapsed' in status:
draw.text((ui_text_x, 38), "{}/{}".format(sectomin(status['elapsed']), sectomin(status['duration'])), fill="white")
draw.text((ui_text_x, 38), "{}/{}".format(sectomin(status['elapsed']), sectomin(status['duration'])), fill="white", font=jfont)
elif mode == 'browse':
draw.regular_polygon(bounding_circle=(ui_text_x + 2, 6, 4), n_sides=3, rotation=270, outline="white", fill="black")
if (type(ui_state['current_selection']) is list) and (len(ui_state['current_selection'])):
draw.text((ui_text_x + 10, 1), ui_state['current_selection'][cursor_pos], fill="white")
draw.text((ui_text_x + 10, 1), ui_state['current_selection'][cursor_pos], fill="white", font=jfont)
if (len(ui_state['current_selection']) > 1) and (cursor_pos < len(ui_state['current_selection'])-1):
draw.text((ui_text_x, 14), ui_state['current_selection'][cursor_pos+1], fill="white")
draw.text((ui_text_x, 14), ui_state['current_selection'][cursor_pos+1], fill="white", font=jfont)
if len(ui_state['current_selection']) > 2 and (cursor_pos < len(ui_state['current_selection'])-2):
draw.text((ui_text_x, 26), ui_state['current_selection'][cursor_pos+2], fill="white")
draw.text((ui_text_x, 26), ui_state['current_selection'][cursor_pos+2], fill="white", font=jfont)
else:
draw.text((ui_text_x + 10, 1), ui_state['current_selection'], fill="white")
draw.text((ui_text_x + 10, 1), ui_state['current_selection'], fill="white", font=jfont)
draw.text((ui_vol_x, ui_vol_y), "{:02d}".format(int(status['volume'])), fill="white", font=jfont)
device.contrast(0)
device.display(ui)
@ -257,10 +259,15 @@ def send_mpd_cmd(client, cmd:str, ui_state:dict):
if client.status()['state'] != 'stop':
client.next()
elif cmd == 'toggle':
# ~ global MODES
if client.status()['state'] in idle_states:
client.play()
MODES['playback']['BTN_3']['ICON'] = apply_xy_offset(play_icon, MODES['playback']['BTN_3']['XY'])
static_ui = generate_static_ui('playback')
else:
client.pause()
MODES['playback']['BTN_3']['ICON'] = apply_xy_offset(pause_icon, MODES['playback']['BTN_3']['XY'])
static_ui = generate_static_ui('playback')
elif cmd == 'stop':
client.stop()
elif cmd == 'down':