audio: Add a custom TrackTitle label
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
5c2e4bb016
commit
4ab66ef7ab
|
@ -1,5 +1,18 @@
|
|||
# Copyright 2021 (c) Anna Schumaker.
|
||||
from gi.repository import GLib, Gtk
|
||||
from gi.repository import GLib
|
||||
from gi.repository import Gtk
|
||||
|
||||
class TrackTitle(Gtk.Label):
|
||||
def __init__(self, player):
|
||||
Gtk.Label.__init__(self)
|
||||
player.connect("track-changed", self.on_track_changed)
|
||||
self.on_track_changed(player, None, player.track)
|
||||
self.add_css_class("title")
|
||||
|
||||
def on_track_changed(self, player, old, new):
|
||||
text = new.title if new else "Emmental"
|
||||
self.set_markup(f"<big>{GLib.markup_escape_text(text)}</big>")
|
||||
|
||||
|
||||
class NowPlaying(Gtk.ScrolledWindow):
|
||||
def __init__(self):
|
||||
|
|
|
@ -1,7 +1,35 @@
|
|||
# Copyright 2021 (c) Anna Schumaker.
|
||||
from . import nowplaying
|
||||
from gi.repository import Gtk
|
||||
import unittest
|
||||
from gi.repository import GObject
|
||||
from gi.repository import Gtk
|
||||
from . import nowplaying
|
||||
|
||||
class FakeTrack(GObject.GObject):
|
||||
def __init__(self):
|
||||
GObject.GObject.__init__(self)
|
||||
self.title = "Test Title"
|
||||
|
||||
class FakePlayer(GObject.GObject):
|
||||
def __init__(self):
|
||||
GObject.GObject.__init__(self)
|
||||
self.track = None
|
||||
|
||||
@GObject.Signal(arg_types=(FakeTrack,FakeTrack))
|
||||
def track_changed(self, prev, new): pass
|
||||
|
||||
|
||||
class TestAudioTrackTitle(unittest.TestCase):
|
||||
def test_track_title(self):
|
||||
fake = FakePlayer()
|
||||
title = nowplaying.TrackTitle(fake)
|
||||
|
||||
self.assertIsInstance(title, Gtk.Label)
|
||||
self.assertTrue(title.has_css_class("title"))
|
||||
self.assertEqual(title.get_text(), "Emmental")
|
||||
|
||||
fake.emit("track-changed", None, FakeTrack())
|
||||
self.assertEqual(title.get_text(), "Test Title")
|
||||
|
||||
|
||||
class TestNowPlaying(unittest.TestCase):
|
||||
def test_now_playing_init(self):
|
||||
|
|
Loading…
Reference in New Issue