playlist: Add a Track Number column to the PlaylistView
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
4e24124755
commit
8e7db2c472
|
@ -31,6 +31,11 @@ class LabelFactory(Gtk.SignalListItemFactory):
|
|||
listitem.set_child(None)
|
||||
|
||||
|
||||
class TracknoFactory(LabelFactory):
|
||||
def __init__(self): LabelFactory.__init__(self, xalign=1)
|
||||
def get_track_text(self, track): return f"{track.disc.number}-{track.number:02}"
|
||||
|
||||
|
||||
class Column(Gtk.ColumnViewColumn):
|
||||
def __init__(self, title, factory, width=-1, **kwargs):
|
||||
Gtk.ColumnViewColumn.__init__(self, title=title, **kwargs)
|
||||
|
@ -45,6 +50,9 @@ class Column(Gtk.ColumnViewColumn):
|
|||
lib.settings.set(f"column.{self.get_title()}", self.get_fixed_width())
|
||||
|
||||
|
||||
def TracknoColumn(): return Column("#", TracknoFactory())
|
||||
|
||||
|
||||
class OldColumn(Gtk.ColumnViewColumn):
|
||||
def __init__(self, title, field, width=-1, expand=False, align=0):
|
||||
Gtk.ColumnViewColumn.__init__(self)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
# Copyright 2021 (c) Anna Schumaker.
|
||||
import db
|
||||
import lib
|
||||
import unittest
|
||||
from gi.repository import Gtk
|
||||
|
@ -42,6 +43,18 @@ class TestLabelFactory(unittest.TestCase):
|
|||
self.assertEqual(fake.child.get_text(), "")
|
||||
|
||||
|
||||
class TestColumnFactories(unittest.TestCase):
|
||||
def setUp(self):
|
||||
db.reset()
|
||||
self.track = db.make_fake_track(1, 1, "Test Track", "/a/b/c/1.ogg")
|
||||
|
||||
def test_trackno(self):
|
||||
factory = column.TracknoFactory()
|
||||
self.assertIsInstance(factory, column.LabelFactory)
|
||||
self.assertEqual(factory.get_track_text(self.track), "1-01")
|
||||
self.assertEqual(factory.xalign, 1)
|
||||
|
||||
|
||||
class TestColumn(unittest.TestCase):
|
||||
def test_init(self):
|
||||
factory = column.LabelFactory(0.5)
|
||||
|
@ -68,6 +81,14 @@ class TestColumn(unittest.TestCase):
|
|||
self.assertEqual(col2.get_fixed_width(), 200)
|
||||
|
||||
|
||||
class TestColumns(unittest.TestCase):
|
||||
def test_trackno(self):
|
||||
col = column.TracknoColumn()
|
||||
self.assertIsInstance(col, column.Column)
|
||||
self.assertIsInstance(col.get_factory(), column.TracknoFactory)
|
||||
self.assertEqual(col.get_title(), "#")
|
||||
|
||||
|
||||
class TestPlaylistColumn(unittest.TestCase):
|
||||
def tearDown(self):
|
||||
settings.reset()
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
# Copyright 2021 (c) Anna Schumaker.
|
||||
from gi.repository import Gtk
|
||||
from . import column
|
||||
from . import model
|
||||
|
||||
class PlaylistView(Gtk.ColumnView):
|
||||
|
@ -11,6 +12,8 @@ class PlaylistView(Gtk.ColumnView):
|
|||
self.set_hexpand(True)
|
||||
self.set_vexpand(True)
|
||||
|
||||
self.append_column(column.TracknoColumn())
|
||||
|
||||
def get_filter_model(self): return self.get_model().get_filter_model()
|
||||
def get_playlist(self): return self.get_model().get_playlist()
|
||||
def set_playlist(self, plist): self.get_model().set_playlist(plist)
|
||||
|
|
Loading…
Reference in New Issue
Block a user