playlist: Add a Controls instance above the ColumnView
And set up a FilterListModel so we can filter tracks Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
315312615e
commit
d2362368f3
|
@ -1,16 +1,27 @@
|
|||
# Copyright 2021 (c) Anna Schumaker.
|
||||
from . import column
|
||||
from . import controls
|
||||
from . import model
|
||||
from . import runtime
|
||||
from gi.repository import Gtk
|
||||
|
||||
Model = model.TagModel()
|
||||
|
||||
def on_filter_pending(filter, pending):
|
||||
runtime.set_visible_count(FilterModel.get_n_items())
|
||||
|
||||
FilterModel = Gtk.FilterListModel()
|
||||
FilterModel.connect("notify::pending", on_filter_pending)
|
||||
FilterModel.set_filter(Model.Controls.filter)
|
||||
FilterModel.set_model(Model)
|
||||
|
||||
Selection = Gtk.SingleSelection()
|
||||
Selection.set_model(Model)
|
||||
Selection.set_model(FilterModel)
|
||||
|
||||
View = Gtk.ColumnView()
|
||||
View.add_css_class("data-table")
|
||||
View.set_hexpand(True)
|
||||
View.set_vexpand(True)
|
||||
View.set_model(Selection)
|
||||
|
||||
View.append_column(column.Column("#", "tracknumber"))
|
||||
|
@ -24,3 +35,7 @@ View.append_column(column.Column("Last Played", "lastplayed", width=150))
|
|||
|
||||
Scroll = Gtk.ScrolledWindow()
|
||||
Scroll.set_child(View)
|
||||
|
||||
Box = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0)
|
||||
Box.append(Model.Controls)
|
||||
Box.append(Scroll)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
# Copyright 2021 (c) Anna Schumaker.
|
||||
from . import controls
|
||||
from . import runtime
|
||||
from lib import bus
|
||||
from gi.repository import GObject, Gio
|
||||
|
@ -6,6 +7,7 @@ from gi.repository import GObject, Gio
|
|||
class TagModel(GObject.GObject, Gio.ListModel):
|
||||
def __init__(self, tag=None):
|
||||
GObject.GObject.__init__(self)
|
||||
self.Controls = controls.Controls()
|
||||
self.bus = bus.Bus(1)
|
||||
self.items = [ ]
|
||||
self.__set_tag__(tag)
|
||||
|
@ -16,6 +18,7 @@ class TagModel(GObject.GObject, Gio.ListModel):
|
|||
self.items = self.tag.tracks.copy()
|
||||
self.tag.TrackAdded.register(self.track_added)
|
||||
self.tag.TrackRemoved.register(self.track_removed)
|
||||
self.Controls.set_tag(tag)
|
||||
return len(self.items)
|
||||
|
||||
def __unset_tag__(self):
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
# Copyright 2021 (c) Anna Schumaker.
|
||||
from . import controls
|
||||
from . import model
|
||||
from . import runtime
|
||||
from lib import bus
|
||||
|
@ -22,6 +23,7 @@ class TestTagModel(unittest.TestCase):
|
|||
self.assertIsInstance(m, GObject.Object)
|
||||
self.assertIsInstance(m, Gio.ListModel)
|
||||
self.assertIsInstance(m.bus, bus.Bus)
|
||||
self.assertIsInstance(m.Controls, controls.Controls)
|
||||
|
||||
self.assertEqual(m.tag, t)
|
||||
self.assertEqual(m.items, [ ])
|
||||
|
|
|
@ -22,15 +22,20 @@ columns = [ ColumnEV("#", -1, False),
|
|||
class TestPlaylist(unittest.TestCase):
|
||||
def test_playlist_init(self):
|
||||
self.assertIsInstance(playlist.Model, playlist.model.TagModel)
|
||||
self.assertIsInstance(playlist.FilterModel, Gtk.FilterListModel)
|
||||
self.assertIsInstance(playlist.Selection, Gtk.SingleSelection)
|
||||
self.assertIsInstance(playlist.View, Gtk.ColumnView)
|
||||
self.assertIsInstance(playlist.Scroll, Gtk.ScrolledWindow)
|
||||
|
||||
self.assertEqual(playlist.Selection.get_model(), playlist.Model)
|
||||
self.assertEqual(playlist.FilterModel.get_model(), playlist.Model)
|
||||
self.assertEqual(playlist.FilterModel.get_filter(),
|
||||
playlist.Model.Controls.filter)
|
||||
self.assertEqual(playlist.Selection.get_model(), playlist.FilterModel)
|
||||
self.assertEqual(playlist.View.get_model(), playlist.Selection)
|
||||
self.assertEqual(playlist.Scroll.get_child(), playlist.View)
|
||||
|
||||
self.assertTrue(playlist.View.get_hexpand())
|
||||
self.assertTrue(playlist.View.get_vexpand())
|
||||
self.assertTrue(playlist.View.has_css_class("data-table"))
|
||||
|
||||
for (i, c) in enumerate(playlist.View.get_columns()):
|
||||
|
|
|
@ -12,7 +12,7 @@ initialize()
|
|||
|
||||
Pane.set_position(settings.get_int("sidebar.width"))
|
||||
Pane.set_start_child(sidebar.Box)
|
||||
Pane.set_end_child(playlist.Scroll)
|
||||
Pane.set_end_child(playlist.Box)
|
||||
Pane.set_vexpand(True)
|
||||
|
||||
def on_change_position(pane, position):
|
||||
|
|
|
@ -13,7 +13,7 @@ class TestUIPane(unittest.TestCase):
|
|||
def test_pane_init(self):
|
||||
self.assertIsInstance(pane.Pane, Gtk.Paned)
|
||||
self.assertEqual(pane.Pane.get_start_child(), sidebar.Box)
|
||||
self.assertEqual(pane.Pane.get_end_child(), playlist.Scroll)
|
||||
self.assertEqual(pane.Pane.get_end_child(), playlist.Box)
|
||||
self.assertTrue(pane.Pane.get_vexpand())
|
||||
|
||||
self.assertEqual(pane.Pane.get_position(), 250)
|
||||
|
|
Loading…
Reference in New Issue