From 129685718918f351c2a554d3a60ffbaf6e104ff2 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Mon, 10 Jan 2022 11:36:42 -0500 Subject: [PATCH] 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 --- playlist/column.py | 13 ++++++++++--- playlist/test_column.py | 4 +++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/playlist/column.py b/playlist/column.py index d5c64f4..04f55b9 100644 --- a/playlist/column.py +++ b/playlist/column.py @@ -33,13 +33,17 @@ class LabelFactory(Gtk.SignalListItemFactory): def get_track_text(self, track): raise NotImplementedError + def get_track_dim(self, track): + return False + def on_setup(self, factory, listitem): listitem.set_child(TrackLabel(xalign=self.xalign)) def on_bind(self, factory, listitem): item = listitem.get_item() - text = self.get_track_text(item) - listitem.get_child().set_item(item, text) + if child := listitem.get_child(): + child.set_item(item, self.get_track_text(item)) + child.set_sensitive(not self.get_track_dim(item)) def on_unbind(self, factory, listitem): listitem.get_child().unset_item(listitem.get_item()) @@ -77,7 +81,10 @@ class AlbumFactory(LabelFactory): class SubtitleFactory(LabelFactory): 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): diff --git a/playlist/test_column.py b/playlist/test_column.py index 7906f73..b7bcf28 100644 --- a/playlist/test_column.py +++ b/playlist/test_column.py @@ -100,9 +100,11 @@ class TestColumnFactories(unittest.TestCase): def test_subtitle(self): factory = column.SubtitleFactory() 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.assertEqual(factory.get_track_text(self.track), "Test Subtitle") + self.assertFalse(factory.get_track_dim(self.track)) def test_year(self): factory = column.YearFactory()