audio: Add widgets for Now Playing information
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
d29f4c1b47
commit
c844aba318
|
@ -0,0 +1,38 @@
|
|||
# Copyright 2021 (c) Anna Schumaker.
|
||||
from gi.repository import GLib, Gtk
|
||||
|
||||
class NowPlaying(Gtk.ScrolledWindow):
|
||||
def __init__(self):
|
||||
Gtk.ScrolledWindow.__init__(self)
|
||||
self.title = Gtk.Label()
|
||||
self.title.add_css_class("title")
|
||||
|
||||
self.subtitle = Gtk.Label()
|
||||
self.subtitle.add_css_class("subtitle")
|
||||
|
||||
self.box = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0)
|
||||
self.box.append(self.title)
|
||||
self.box.append(self.subtitle)
|
||||
|
||||
self.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.NEVER)
|
||||
self.set_valign(Gtk.Align.CENTER)
|
||||
self.set_hexpand(True)
|
||||
self.set_child(self.box)
|
||||
|
||||
self.set_title(None)
|
||||
self.set_subtitle(None)
|
||||
|
||||
def set_artist(self, text):
|
||||
self.set_subtitle(f"by {text}")
|
||||
|
||||
def set_title(self, text):
|
||||
if text == None:
|
||||
text = "Emmental"
|
||||
text = GLib.markup_escape_text(text)
|
||||
self.title.set_markup(f"<big>{text}</big>")
|
||||
|
||||
def set_subtitle(self, text):
|
||||
if text == None:
|
||||
text = "The Cheesy Music Player"
|
||||
text = GLib.markup_escape_text(text)
|
||||
self.subtitle.set_markup(f"<big>{text}</big>")
|
|
@ -0,0 +1,44 @@
|
|||
# Copyright 2021 (c) Anna Schumaker.
|
||||
from . import nowplaying
|
||||
from gi.repository import Gtk
|
||||
import unittest
|
||||
|
||||
class TestNowPlaying(unittest.TestCase):
|
||||
def test_now_playing_init(self):
|
||||
now = nowplaying.NowPlaying()
|
||||
|
||||
self.assertIsInstance(now, Gtk.ScrolledWindow)
|
||||
self.assertIsInstance(now.box, Gtk.Box)
|
||||
self.assertIsInstance(now.title, Gtk.Label)
|
||||
self.assertIsInstance(now.subtitle, Gtk.Label)
|
||||
|
||||
self.assertIn(now.title, now.box)
|
||||
self.assertIn(now.subtitle, now.box)
|
||||
|
||||
viewport = now.get_child()
|
||||
self.assertEqual(viewport.get_child(), now.box)
|
||||
|
||||
self.assertEqual(now.get_valign(), Gtk.Align.CENTER)
|
||||
self.assertEqual(now.get_policy(), (Gtk.PolicyType.AUTOMATIC,
|
||||
Gtk.PolicyType.NEVER))
|
||||
|
||||
self.assertTrue(now.get_hexpand())
|
||||
self.assertTrue(now.title.has_css_class("title"))
|
||||
self.assertTrue(now.subtitle.has_css_class("subtitle"))
|
||||
|
||||
def test_now_playing_text(self):
|
||||
now = nowplaying.NowPlaying()
|
||||
self.assertEqual(now.title.get_text(), "Emmental")
|
||||
self.assertEqual(now.subtitle.get_text(), "The Cheesy Music Player")
|
||||
|
||||
now.set_title("Test Title")
|
||||
now.set_artist("Test Artist")
|
||||
|
||||
self.assertEqual(now.title.get_text(), "Test Title")
|
||||
self.assertEqual(now.subtitle.get_text(), "by Test Artist")
|
||||
|
||||
now.set_title(None)
|
||||
now.set_subtitle(None)
|
||||
|
||||
self.assertEqual(now.title.get_text(), "Emmental")
|
||||
self.assertEqual(now.subtitle.get_text(), "The Cheesy Music Player")
|
Loading…
Reference in New Issue