59 lines
2.2 KiB
Python
59 lines
2.2 KiB
Python
# Copyright 2022 (c) Anna Schumaker.
|
|
"""A Footer widget to display below the TrackView."""
|
|
from gi.repository import GObject
|
|
from gi.repository import Gtk
|
|
|
|
|
|
class Footer(Gtk.CenterBox):
|
|
"""Footer labels for the Tracklist card."""
|
|
|
|
count = GObject.Property(type=int)
|
|
selected = GObject.Property(type=int)
|
|
runtime = GObject.Property(type=float)
|
|
|
|
def __init__(self, **kwargs):
|
|
"""Initialize a Footer widget."""
|
|
super().__init__(**kwargs)
|
|
self._count = Gtk.Label(label="Showing 0 tracks", xalign=0.0)
|
|
self._selected = Gtk.Label()
|
|
self._runtime = Gtk.Label(label="0 seconds", xalign=1.0)
|
|
|
|
self.set_start_widget(self._count)
|
|
self.set_center_widget(self._selected)
|
|
self.set_end_widget(self._runtime)
|
|
|
|
self.connect("notify", self.__update_labels)
|
|
self.add_css_class("dim-label")
|
|
|
|
def __update_labels(self, footer: Gtk.CenterBox, param) -> None:
|
|
match param.name:
|
|
case "count":
|
|
s_count = "s" if self.count != 1 else ""
|
|
self._count.set_text(f"Showing {self.count} track{s_count}")
|
|
case "selected":
|
|
match self.selected:
|
|
case 0: text = ""
|
|
case _:
|
|
s_count = "s" if self.selected != 1 else ""
|
|
text = f"{self.selected} track{s_count} selected"
|
|
self._selected.set_text(text)
|
|
case "runtime":
|
|
res = []
|
|
(min, sec) = divmod(round(self.runtime), 60)
|
|
(hour, min) = divmod(min, 60)
|
|
(day, hour) = divmod(hour, 24)
|
|
(week, day) = divmod(day, 7)
|
|
|
|
if week > 0:
|
|
res.append(f"{week} week{'s' if week != 1 else ''}")
|
|
if day > 0:
|
|
res.append(f"{day} day{'s' if day != 1 else ''}")
|
|
if hour > 0:
|
|
res.append(f"{hour} hour{'s' if hour != 1 else ''}")
|
|
if min > 0:
|
|
res.append(f"{min} minute{'s' if min != 1 else ''}")
|
|
if sec > 0:
|
|
res.append(f"{sec} second{'s' if sec != 1 else ''}")
|
|
|
|
self._runtime.set_text(", ".join(res))
|