Added the ability to toggle displaying track information or just album art.

This commit is contained in:
GuardKenzie
2021-04-30 18:10:02 +00:00
parent ac296b1fcc
commit 7628bb37f7

View File

@ -19,6 +19,7 @@ if "player" not in config.sections():
"font_width": 11, "font_width": 11,
"font_height": 24, "font_height": 24,
"image_method": "pixcat", "image_method": "pixcat",
"album_art_only": False,
"volume_step": 5 "volume_step": 5
} }
@ -35,7 +36,8 @@ default_bindings = {">": "next_track",
"-": "volume_down", "-": "volume_down",
"p": "play_pause", "p": "play_pause",
"q": "quit", "q": "quit",
"h": "help" "h": "help",
"i": "toggle_info"
} }
if "keybindings" not in config.sections(): if "keybindings" not in config.sections():
@ -147,6 +149,9 @@ class Player:
# Update needed flag # Update needed flag
self.update_needed = False self.update_needed = False
# Album art only flag
self.album_art_only = player_config.getboolean("album_art_only", False)
def fitText(self): def fitText(self):
""" """
@ -183,18 +188,23 @@ class Player:
return (state, album, artist, song) return (state, album, artist, song)
def updateWindowSize(self): def updateWindowSize(self, force_update=False):
""" """
A function to check if the window size changed A function to check if the window size changed
""" """
new_height, new_width = self.stdscr.getmaxyx() new_height, new_width = self.stdscr.getmaxyx()
if (new_height, new_width) != (self.window_height, self.window_width): if (new_height, new_width) != (self.window_height, self.window_width) or force_update:
self.win.clear() self.win.clear()
# Curses window # Curses window
self.window_height, self.window_width = self.stdscr.getmaxyx() self.window_height, self.window_width = self.stdscr.getmaxyx()
# Check if we are drawing info
if self.album_art_only:
self.text_start = int(self.window_height)
self.album_space = self.text_start - 1
else:
self.text_start = int(self.window_height - 5) self.text_start = int(self.window_height - 5)
self.album_space = self.text_start - 2 self.album_space = self.text_start - 2
@ -303,6 +313,16 @@ class Player:
return 2 return 2
def toggleInfo(self):
"""
A function that toggles the display of track info
"""
self.album_art_only = not self.album_art_only
self.win.clear()
self.updateWindowSize(force_update=True)
self.win.refresh()
def handleKeypress(self): def handleKeypress(self):
""" """
A function to handle keypresses A function to handle keypresses
@ -368,6 +388,10 @@ class Player:
self.cleared = False self.cleared = False
self.update_needed = True self.update_needed = True
elif action == "toggle_info":
self.toggleInfo()
self.update_needed = True
key = self.stdscr.getch() key = self.stdscr.getch()
def drawInfo(self): def drawInfo(self):
@ -536,7 +560,9 @@ class Player:
return return
# Draw the window # Draw the window
if not self.album_art_only:
self.drawInfo() self.drawInfo()
self.drawAlbumArt() self.drawAlbumArt()
@ -553,6 +579,11 @@ class Player:
scaler=ueberzug.ScalerOption.FIT_CONTAIN.value scaler=ueberzug.ScalerOption.FIT_CONTAIN.value
) )
# Check if we need to recalculate window size
# because of album art only initially
if self.album_art_only:
self.updateWindowSize(force_update=True)
try: try:
i = 0 i = 0
while True: while True: