playlist: Don't leave the Subtitle column blank

Instead, fill in something generated from the disc number but make it
dimmed.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2022-01-10 11:36:42 -05:00
parent 73ba296d74
commit 1296857189
2 changed files with 13 additions and 4 deletions

View File

@ -33,13 +33,17 @@ class LabelFactory(Gtk.SignalListItemFactory):
def get_track_text(self, track): def get_track_text(self, track):
raise NotImplementedError raise NotImplementedError
def get_track_dim(self, track):
return False
def on_setup(self, factory, listitem): def on_setup(self, factory, listitem):
listitem.set_child(TrackLabel(xalign=self.xalign)) listitem.set_child(TrackLabel(xalign=self.xalign))
def on_bind(self, factory, listitem): def on_bind(self, factory, listitem):
item = listitem.get_item() item = listitem.get_item()
text = self.get_track_text(item) if child := listitem.get_child():
listitem.get_child().set_item(item, text) child.set_item(item, self.get_track_text(item))
child.set_sensitive(not self.get_track_dim(item))
def on_unbind(self, factory, listitem): def on_unbind(self, factory, listitem):
listitem.get_child().unset_item(listitem.get_item()) listitem.get_child().unset_item(listitem.get_item())
@ -77,7 +81,10 @@ class AlbumFactory(LabelFactory):
class SubtitleFactory(LabelFactory): class SubtitleFactory(LabelFactory):
def __init__(self): LabelFactory.__init__(self, xalign=0) def __init__(self): LabelFactory.__init__(self, xalign=0)
def get_track_text(self, track): return track.disc.subtitle def get_track_dim(self, track): return len(track.disc.subtitle) == 0
def get_track_text(self, track):
subtitle = track.disc.subtitle
return subtitle if len(subtitle) > 0 else track.disc.name
class YearFactory(LabelFactory): class YearFactory(LabelFactory):

View File

@ -100,9 +100,11 @@ class TestColumnFactories(unittest.TestCase):
def test_subtitle(self): def test_subtitle(self):
factory = column.SubtitleFactory() factory = column.SubtitleFactory()
self.assertIsInstance(factory, column.LabelFactory) self.assertIsInstance(factory, column.LabelFactory)
self.assertEqual(factory.get_track_text(self.track), "") self.assertEqual(factory.get_track_text(self.track), "Disc 1")
self.assertTrue(factory.get_track_dim(self.track))
self.track.disc._subtitle = "Test Subtitle" self.track.disc._subtitle = "Test Subtitle"
self.assertEqual(factory.get_track_text(self.track), "Test Subtitle") self.assertEqual(factory.get_track_text(self.track), "Test Subtitle")
self.assertFalse(factory.get_track_dim(self.track))
def test_year(self): def test_year(self):
factory = column.YearFactory() factory = column.YearFactory()