123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- #!./bin/python3
- import yaml
- import pygame # type: ignore
- # Color constants
- BLACK = (0, 0, 0)
- GREEN = (0, 255, 0)
- class Display:
- '''
- Display object
- '''
- def __init__(self, config, pydsp):
-
- # Set config values
-
- self._dx = config.get("dimx", 128)
- self._dy = config.get("dimy", 160)
- self._playlistFile = config.get("playlist", "music.yml")
- self._pydsp = pydsp # Pygame display object
- self._fontsize = config.get("fontsize", 12)
- # Set initialisation values
- self._selection_pointer = 0 # Current selected value
- def update(self):
- '''
- Load the data from the given config file.
- '''
- playlist = yaml.safe_load(open(self._playlistFile))
- font = pygame.font.Font('freesansbold.ttf', self._fontsize)
- drawline = 0 # Line currently drawm
- for i, item in enumerate(playlist.get("playlist", [])):
- print(item["name"])
- if drawline == self._selection_pointer:
- text = font.render(item["name"], True, BLACK, GREEN)
- else:
- text = font.render(item["name"], True, GREEN, BLACK)
-
- self._pydsp.blit(text, (0, drawline * self._fontsize))
- drawline += 1
|