|
@@ -1,13 +1,17 @@
|
|
|
#!./bin/python3
|
|
|
|
|
|
+import os
|
|
|
+
|
|
|
import yaml
|
|
|
import pygame # type: ignore
|
|
|
from typing import Dict
|
|
|
+import random
|
|
|
|
|
|
# Color constants
|
|
|
|
|
|
BLACK = (0, 0, 0)
|
|
|
GREEN = (0, 255, 0)
|
|
|
+WHITE = (255, 255, 255)
|
|
|
|
|
|
class Display:
|
|
|
'''
|
|
@@ -29,6 +33,7 @@ class Display:
|
|
|
self._selection_pointer = 0 # Current selected value
|
|
|
self._line_offset = 0 # Drawing offset in playlist
|
|
|
self._current_item = None
|
|
|
+ self._bgImg = None
|
|
|
|
|
|
|
|
|
def getPlaylist(self) -> Dict:
|
|
@@ -72,12 +77,12 @@ class Display:
|
|
|
|
|
|
if drawline == self._selection_pointer:
|
|
|
text = font.render(item["name"], True, BLACK, GREEN)
|
|
|
- img = item.get("img")
|
|
|
|
|
|
- if img is not None:
|
|
|
- pass
|
|
|
- else:
|
|
|
- pygame.draw.rect(self._pydsp, GREEN, (0,0,self._dx,50))
|
|
|
+ pygame.draw.rect(self._pydsp, BLACK, (0,0,self._dx,50))
|
|
|
+ try:
|
|
|
+ self.drawArt(item)
|
|
|
+ except Exception as e:
|
|
|
+ print("Error while drawing art:", e)
|
|
|
|
|
|
self._current_item = item
|
|
|
else:
|
|
@@ -91,6 +96,38 @@ class Display:
|
|
|
if drawline > self._drawlines:
|
|
|
break
|
|
|
|
|
|
+ def drawArt(self, item):
|
|
|
+ '''
|
|
|
+ Beautify the display.
|
|
|
+ '''
|
|
|
+ font = pygame.font.Font('freesansbold.ttf', self._fontsize)
|
|
|
+
|
|
|
+ # Draw a background image
|
|
|
+
|
|
|
+ if self._bgImg is None:
|
|
|
+ bg = os.listdir("web/background")
|
|
|
+ bg = bg[random.randint(0, len(bg)-1)]
|
|
|
+ self._bgImg = pygame.image.load(os.path.join("web/background", bg))
|
|
|
+ pygame.transform.scale(self._bgImg, (self._dx, 50))
|
|
|
+
|
|
|
+ self._pydsp.blit(self._bgImg, (0,0), (0, 0, self._dx, 50))
|
|
|
+
|
|
|
+ path = item.get("path")
|
|
|
+ title = item.get("name", "")
|
|
|
+ artist = item.get("artist", "")
|
|
|
+
|
|
|
+ # Try to extract meta data
|
|
|
+
|
|
|
+ if path is not None:
|
|
|
+ pass
|
|
|
+
|
|
|
+ s = title
|
|
|
+ if artist != "":
|
|
|
+ s = "%s (%s)" % (s, artist)
|
|
|
+
|
|
|
+ text = font.render(s, True, WHITE, BLACK)
|
|
|
+ self._pydsp.blit(text, (0, 38))
|
|
|
+
|
|
|
|
|
|
def currentItem(self) -> Dict:
|
|
|
'''
|