playlist: Initialize column widths to some reasonable values
And save / restore through the settings file. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
849503eaf2
commit
fc9b734e38
|
@ -9,13 +9,13 @@ View.set_hexpand(True)
|
|||
View.set_model(Selection)
|
||||
|
||||
View.append_column(column.Column("#"))
|
||||
View.append_column(column.Column("Title"))
|
||||
View.append_column(column.Column("Title", width=250))
|
||||
View.append_column(column.Column("Length"))
|
||||
View.append_column(column.Column("Artist"))
|
||||
View.append_column(column.Column("Album"))
|
||||
View.append_column(column.Column("Artist", width=150))
|
||||
View.append_column(column.Column("Album", width=150))
|
||||
View.append_column(column.Column("Year"))
|
||||
View.append_column(column.Column("Count"))
|
||||
View.append_column(column.Column("Last Played"))
|
||||
View.append_column(column.Column("Last Played", width=150))
|
||||
|
||||
Scroll = Gtk.ScrolledWindow()
|
||||
Scroll.set_child(View)
|
||||
|
|
|
@ -1,9 +1,17 @@
|
|||
# Copyright 2021 (c) Anna Schumaker.
|
||||
from lib import settings
|
||||
from gi.repository import Gtk
|
||||
|
||||
class Column(Gtk.ColumnViewColumn):
|
||||
def __init__(self, title):
|
||||
def __init__(self, title, width=-1):
|
||||
Gtk.ColumnViewColumn.__init__(self)
|
||||
|
||||
settings.initialize(f"column.{title}", width)
|
||||
|
||||
self.set_fixed_width(settings.get_int(f"column.{title}"))
|
||||
self.set_resizable(True)
|
||||
self.set_title(title)
|
||||
self.connect("notify::fixed-width", self.on_width_changed)
|
||||
|
||||
def on_width_changed(self, col, param):
|
||||
settings.set(f"column.{self.get_title()}", self.get_fixed_width())
|
||||
|
|
|
@ -1,12 +1,23 @@
|
|||
# Copyright 2021 (c) Anna Schumaker.
|
||||
from lib import settings
|
||||
from . import column
|
||||
from gi.repository import Gtk
|
||||
import unittest
|
||||
|
||||
class TestPlaylistColumn(unittest.TestCase):
|
||||
def tearDown(self):
|
||||
settings.reset()
|
||||
|
||||
def test_playlist_column_init(self):
|
||||
col = column.Column("Test")
|
||||
self.assertIsInstance(col, Gtk.ColumnViewColumn)
|
||||
|
||||
self.assertEqual(col.get_title(), "Test")
|
||||
self.assertTrue(col.get_resizable())
|
||||
|
||||
def test_playlist_column_width(self):
|
||||
col = column.Column("Test", width=100)
|
||||
|
||||
self.assertEqual(settings.get_int("column.Test"), 100)
|
||||
col.set_fixed_width(200)
|
||||
self.assertEqual(settings.get_int("column.Test"), 200)
|
||||
|
|
|
@ -3,9 +3,9 @@ from gi.repository import Gtk
|
|||
import playlist
|
||||
import unittest
|
||||
|
||||
|
||||
columns = [ "#", "Title", "Length", "Artist", "Album",
|
||||
"Year", "Count", "Last Played" ]
|
||||
columns = [ ("#", -1), ("Title", 250), ("Length", -1),
|
||||
("Artist", 150), ("Album", 150),
|
||||
("Year", -1), ("Count", -1), ("Last Played", 150) ]
|
||||
|
||||
class TestPlaylist(unittest.TestCase):
|
||||
def test_playlist_init(self):
|
||||
|
@ -19,4 +19,5 @@ class TestPlaylist(unittest.TestCase):
|
|||
self.assertTrue(playlist.View.get_hexpand())
|
||||
|
||||
for (i, c) in enumerate(playlist.View.get_columns()):
|
||||
self.assertEqual(c.get_title(), columns[i])
|
||||
self.assertEqual(c.get_title(), columns[i][0])
|
||||
self.assertEqual(c.get_fixed_width(), columns[i][1])
|
||||
|
|
Loading…
Reference in New Issue