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()