sidebar: Create a ChildModel list model
This will be used to display the children of some of our playlists. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
f02104a9c1
commit
17391acd4d
|
@ -0,0 +1,16 @@
|
|||
# Copyright 2021 (c) Anna Schumaker.
|
||||
from gi.repository import GObject
|
||||
from gi.repository import Gio
|
||||
|
||||
class ChildModel(GObject.GObject, Gio.ListModel):
|
||||
def __init__(self, parent):
|
||||
GObject.GObject.__init__(self)
|
||||
self.parent = parent
|
||||
self.parent.connect("children-changed", self.children_changed)
|
||||
|
||||
def do_get_item_type(self): return GObject.TYPE_PYOBJECT
|
||||
def do_get_n_items(self): return self.parent.get_n_children()
|
||||
def do_get_item(self, n): return self.parent.get_child(n)
|
||||
|
||||
def children_changed(self, item, pos, rm, add):
|
||||
self.emit("items-changed", pos, rm, add)
|
|
@ -0,0 +1,35 @@
|
|||
# Copyright 2021 (c) Anna Schumaker.
|
||||
import datetime
|
||||
import db
|
||||
import unittest
|
||||
from gi.repository import GObject
|
||||
from gi.repository import Gio
|
||||
from . import model
|
||||
|
||||
class TestChildModel(unittest.TestCase):
|
||||
def items_changed(self, table, pos, rm, add):
|
||||
self.changed = (pos, rm, add)
|
||||
|
||||
def setUp(self):
|
||||
db.reset()
|
||||
|
||||
def test_init(self):
|
||||
artist = db.artist.Table.find("Test Artist", "Test Sort")
|
||||
child = model.ChildModel(artist)
|
||||
|
||||
self.assertIsInstance(child, GObject.GObject)
|
||||
self.assertIsInstance(child, Gio.ListModel)
|
||||
|
||||
self.assertEqual(child.parent, artist)
|
||||
self.assertEqual(child.get_item_type(), GObject.TYPE_PYOBJECT)
|
||||
self.assertEqual(child.get_n_items(), 0)
|
||||
|
||||
def test_children(self):
|
||||
artist = db.artist.Table.find("Test Artist", "Test Sort")
|
||||
child = model.ChildModel(artist)
|
||||
child.connect("items-changed", self.items_changed)
|
||||
|
||||
album = artist.find_album("Test Album", datetime.date.today())
|
||||
self.assertEqual(child.get_n_items(), 1)
|
||||
self.assertEqual(child.get_item(0), album)
|
||||
self.assertEqual(self.changed, (0, 0, 1))
|
Loading…
Reference in New Issue