playlist: Create a TagModel as a custom GListModel
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
eb163b27bb
commit
1fb4c25fc6
|
@ -1,9 +1,11 @@
|
|||
# Copyright 2021 (c) Anna Schumaker.
|
||||
from gi.repository import GObject
|
||||
|
||||
tracks = { }
|
||||
|
||||
class FakeTrack:
|
||||
class FakeTrack(GObject.GObject):
|
||||
def __init__(self, n, tag=None):
|
||||
GObject.GObject.__init__(self)
|
||||
self.trackid = n
|
||||
self.length = n
|
||||
self.tag = tag
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
# Copyright 2021 (c) Anna Schumaker.
|
||||
from gi.repository import GObject, Gio
|
||||
|
||||
class TagModel(GObject.GObject, Gio.ListModel):
|
||||
def __init__(self, tag):
|
||||
GObject.GObject.__init__(self)
|
||||
self.tag = tag
|
||||
|
||||
def do_get_item_type(self):
|
||||
return GObject.TYPE_PYOBJECT
|
||||
|
||||
def do_get_n_items(self):
|
||||
return len(self.tag)
|
||||
|
||||
def do_get_item(self, n):
|
||||
return self.tag[n]
|
||||
|
||||
def do_get_object(self, n):
|
||||
return self.tag[n]
|
|
@ -0,0 +1,23 @@
|
|||
# Copyright 2021 (c) Anna Schumaker.
|
||||
from . import model
|
||||
from lib import fake
|
||||
from lib import tag
|
||||
from gi.repository import GObject, Gio
|
||||
import unittest
|
||||
|
||||
|
||||
class TestTagModel(unittest.TestCase):
|
||||
def test_tag_model_init(self):
|
||||
t = tag.Tag("Test")
|
||||
m = model.TagModel(t)
|
||||
|
||||
self.assertIsInstance(m, GObject.Object)
|
||||
self.assertIsInstance(m, Gio.ListModel)
|
||||
|
||||
self.assertEqual(m.get_item_type(), GObject.TYPE_PYOBJECT)
|
||||
self.assertEqual(m.get_n_items(), 0)
|
||||
self.assertIsNone(m.get_item(0))
|
||||
|
||||
t.add_track(fake.Track(1))
|
||||
self.assertEqual(m.get_n_items(), 1)
|
||||
self.assertEqual(m.get_item(0), fake.Track(1))
|
Loading…
Reference in New Issue