playlist: Create a new Column class
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
df4074f1de
commit
296f0c53b4
|
@ -34,14 +34,14 @@ View.set_hexpand(True)
|
|||
View.set_vexpand(True)
|
||||
View.set_model(Selection)
|
||||
|
||||
View.append_column(column.Column("#", "tracknumber"))
|
||||
View.append_column(column.Column("Title", "title", width=250, expand=True))
|
||||
View.append_column(column.Column("Length", "length", align=100))
|
||||
View.append_column(column.Column("Artist", "artist", width=150))
|
||||
View.append_column(column.Column("Album", "album", width=150))
|
||||
View.append_column(column.Column("Year", "year"))
|
||||
View.append_column(column.Column("Count", "playcount"))
|
||||
View.append_column(column.Column("Last Played", "lastplayed", width=150))
|
||||
View.append_column(column.OldColumn("#", "tracknumber"))
|
||||
View.append_column(column.OldColumn("Title", "title", width=250, expand=True))
|
||||
View.append_column(column.OldColumn("Length", "length", align=100))
|
||||
View.append_column(column.OldColumn("Artist", "artist", width=150))
|
||||
View.append_column(column.OldColumn("Album", "album", width=150))
|
||||
View.append_column(column.OldColumn("Year", "year"))
|
||||
View.append_column(column.OldColumn("Count", "playcount"))
|
||||
View.append_column(column.OldColumn("Last Played", "lastplayed", width=150))
|
||||
|
||||
Scroll = Gtk.ScrolledWindow()
|
||||
Scroll.set_child(View)
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
# Copyright 2021 (c) Anna Schumaker.
|
||||
from lib import settings
|
||||
from gi.repository import Gtk, GLib
|
||||
import audio
|
||||
import lib
|
||||
from gi.repository import Gtk, GLib
|
||||
from lib import settings
|
||||
|
||||
|
||||
class LabelFactory(Gtk.SignalListItemFactory):
|
||||
|
@ -31,6 +32,20 @@ class LabelFactory(Gtk.SignalListItemFactory):
|
|||
|
||||
|
||||
class Column(Gtk.ColumnViewColumn):
|
||||
def __init__(self, title, factory, width=-1, **kwargs):
|
||||
Gtk.ColumnViewColumn.__init__(self, title=title, **kwargs)
|
||||
self.set_factory(factory)
|
||||
self.set_resizable(True)
|
||||
|
||||
lib.settings.initialize(f"column.{title}", width)
|
||||
self.set_fixed_width(settings.get_int(f"column.{title}"))
|
||||
self.connect("notify::fixed-width", self.width_changed)
|
||||
|
||||
def width_changed(self, col, param):
|
||||
lib.settings.set(f"column.{self.get_title()}", self.get_fixed_width())
|
||||
|
||||
|
||||
class OldColumn(Gtk.ColumnViewColumn):
|
||||
def __init__(self, title, field, width=-1, expand=False, align=0):
|
||||
Gtk.ColumnViewColumn.__init__(self)
|
||||
self.field = field
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
# Copyright 2021 (c) Anna Schumaker.
|
||||
import lib
|
||||
import unittest
|
||||
from gi.repository import Gtk
|
||||
from lib import settings
|
||||
from . import column
|
||||
from gi.repository import Gtk
|
||||
import unittest
|
||||
|
||||
class FakeListItem:
|
||||
def __init__(self): self.child = None
|
||||
|
@ -41,12 +42,38 @@ class TestLabelFactory(unittest.TestCase):
|
|||
self.assertEqual(fake.child.get_text(), "")
|
||||
|
||||
|
||||
class TestColumn(unittest.TestCase):
|
||||
def test_init(self):
|
||||
factory = column.LabelFactory(0.5)
|
||||
col = column.Column("Test", factory)
|
||||
|
||||
self.assertIsInstance(col, Gtk.ColumnViewColumn)
|
||||
self.assertEqual(col.get_title(), "Test")
|
||||
self.assertEqual(col.get_factory(), factory)
|
||||
self.assertFalse(col.get_expand())
|
||||
self.assertTrue(col.get_resizable())
|
||||
|
||||
col = column.Column("Test2", factory, expand=True)
|
||||
self.assertTrue(col.get_expand())
|
||||
|
||||
def test_width(self):
|
||||
factory = column.LabelFactory(0.5)
|
||||
col = column.Column("Test", factory, width=-1)
|
||||
|
||||
self.assertEqual(lib.settings.get_int("column.Test"), -1)
|
||||
col.set_fixed_width(200)
|
||||
self.assertEqual(lib.settings.get_int("column.Test"), 200)
|
||||
|
||||
col2 = column.Column("Test", factory, width=-1)
|
||||
self.assertEqual(col2.get_fixed_width(), 200)
|
||||
|
||||
|
||||
class TestPlaylistColumn(unittest.TestCase):
|
||||
def tearDown(self):
|
||||
settings.reset()
|
||||
|
||||
def test_playlist_column_init(self):
|
||||
col = column.Column("Test", "test")
|
||||
col = column.OldColumn("Test", "test")
|
||||
self.assertIsInstance(col, Gtk.ColumnViewColumn)
|
||||
self.assertIsInstance(col.factory, Gtk.SignalListItemFactory)
|
||||
|
||||
|
@ -57,11 +84,11 @@ class TestPlaylistColumn(unittest.TestCase):
|
|||
self.assertTrue(col.get_resizable())
|
||||
self.assertFalse(col.get_expand())
|
||||
|
||||
col = column.Column("Test2", "test", expand=True)
|
||||
col = column.OldColumn("Test2", "test", expand=True)
|
||||
self.assertTrue(col.get_expand())
|
||||
|
||||
def test_playlist_column_width(self):
|
||||
col = column.Column("Test", "test", width=100)
|
||||
col = column.OldColumn("Test", "test", width=100)
|
||||
|
||||
self.assertEqual(settings.get_int("column.Test"), 100)
|
||||
col.set_fixed_width(200)
|
||||
|
|
Loading…
Reference in New Issue