emmental/playlist/footer.py

50 lines
1.4 KiB
Python

# Copyright 2021 (c) Anna Schumaker.
from gi.repository import Gtk
class VisibleTracks(Gtk.Label):
def __init__(self):
Gtk.Label.__init__(self)
self.set_halign(Gtk.Align.START)
self.set_hexpand(True)
def set_count(self, n):
s = 's' if n != 1 else ''
self.set_text(f"Showing {n} track{s}")
class Runtime(Gtk.Label):
def __init__(self):
Gtk.Label.__init__(self)
self.set_halign(Gtk.Align.END)
self.set_hexpand(True)
def set_runtime(self, seconds):
(min, sec) = divmod(seconds, 60)
(hour, min) = divmod(min, 60)
(day, hour) = divmod(hour, 24)
(week, day) = divmod(day, 7)
vals = [ ("week", week), ("day", day), ("hour", hour),
("minute", min), ("second", sec) ]
text = [ f"{v} {k}{'s' if v != 1 else ''}" for (k, v) in vals if v != 0 ]
self.set_text(', '.join(text) if len(text) > 0 else "0 seconds")
class Footer(Gtk.Box):
def __init__(self, filter):
Gtk.Box.__init__(self)
self.visible = VisibleTracks()
self.runtime = Runtime()
self.append(self.visible)
self.append(self.runtime)
filter.connect("notify::pending", self.update_visible)
self.set_margin_start(5)
self.set_margin_end(5)
def update_visible(self, model, param):
self.visible.set_count(model.get_n_items())
self.runtime.set_runtime(model.get_runtime())