playlist: Add a Length column to the PlaylistView
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
0cdc83c21e
commit
2ac2ce04aa
|
@ -41,6 +41,13 @@ class TitleFactory(LabelFactory):
|
|||
def get_track_text(self, track): return track.title
|
||||
|
||||
|
||||
class LengthFactory(LabelFactory):
|
||||
def __init__(self): LabelFactory.__init__(self, xalign=1)
|
||||
def get_track_text(self, track):
|
||||
(m, s) = divmod(int(track.length), 60)
|
||||
return f"{m}:{s:02}"
|
||||
|
||||
|
||||
class Column(Gtk.ColumnViewColumn):
|
||||
def __init__(self, title, factory, width=-1, **kwargs):
|
||||
Gtk.ColumnViewColumn.__init__(self, title=title, **kwargs)
|
||||
|
@ -57,6 +64,7 @@ class Column(Gtk.ColumnViewColumn):
|
|||
|
||||
def TracknoColumn(): return Column("#", TracknoFactory())
|
||||
def TitleColumn(): return Column("Title", TitleFactory(), width=250, expand=True)
|
||||
def LengthColumn(): return Column("Length", LengthFactory())
|
||||
|
||||
|
||||
class OldColumn(Gtk.ColumnViewColumn):
|
||||
|
|
|
@ -59,6 +59,12 @@ class TestColumnFactories(unittest.TestCase):
|
|||
self.assertIsInstance(factory, column.LabelFactory)
|
||||
self.assertEqual(factory.get_track_text(self.track), "Test Track")
|
||||
|
||||
def test_length(self):
|
||||
factory = column.LengthFactory()
|
||||
self.assertIsInstance(factory, column.LabelFactory)
|
||||
self.assertEqual(factory.get_track_text(self.track), "0:01")
|
||||
self.assertEqual(factory.xalign, 1)
|
||||
|
||||
|
||||
class TestColumn(unittest.TestCase):
|
||||
def test_init(self):
|
||||
|
@ -101,6 +107,12 @@ class TestColumns(unittest.TestCase):
|
|||
self.assertEqual(col.get_fixed_width(), 250)
|
||||
self.assertTrue(col.get_expand())
|
||||
|
||||
def test_length(self):
|
||||
col = column.LengthColumn()
|
||||
self.assertIsInstance(col, column.Column)
|
||||
self.assertIsInstance(col.get_factory(), column.LengthFactory)
|
||||
self.assertEqual(col.get_title(), "Length")
|
||||
|
||||
|
||||
class TestPlaylistColumn(unittest.TestCase):
|
||||
def tearDown(self):
|
||||
|
|
|
@ -14,6 +14,7 @@ class PlaylistView(Gtk.ColumnView):
|
|||
|
||||
self.append_column(column.TracknoColumn())
|
||||
self.append_column(column.TitleColumn())
|
||||
self.append_column(column.LengthColumn())
|
||||
|
||||
def get_filter_model(self): return self.get_model().get_filter_model()
|
||||
def get_playlist(self): return self.get_model().get_playlist()
|
||||
|
|
Loading…
Reference in New Issue
Block a user