playlist: Create a new LabelFactory
For creating the labels used by the ColumnView columns Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
979071cd14
commit
df4074f1de
|
@ -3,6 +3,33 @@ from lib import settings
|
|||
from gi.repository import Gtk, GLib
|
||||
import audio
|
||||
|
||||
|
||||
class LabelFactory(Gtk.SignalListItemFactory):
|
||||
def __init__(self, xalign):
|
||||
Gtk.SignalListItemFactory.__init__(self)
|
||||
self.connect("setup", self.on_setup)
|
||||
self.connect("bind", self.on_bind)
|
||||
self.connect("unbind", self.on_unbind)
|
||||
self.connect("teardown", self.on_teardown)
|
||||
self.xalign = xalign
|
||||
|
||||
def get_track_text(self, track):
|
||||
raise NotImplementedError
|
||||
|
||||
def on_setup(self, factory, listitem):
|
||||
listitem.set_child(Gtk.Label(xalign=self.xalign))
|
||||
|
||||
def on_bind(self, factory, listitem):
|
||||
text = self.get_track_text(listitem.get_item())
|
||||
listitem.get_child().set_text(text)
|
||||
|
||||
def on_unbind(self, factory, listitem):
|
||||
listitem.get_child().set_text("")
|
||||
|
||||
def on_teardown(self, factory, listitem):
|
||||
listitem.set_child(None)
|
||||
|
||||
|
||||
class Column(Gtk.ColumnViewColumn):
|
||||
def __init__(self, title, field, width=-1, expand=False, align=0):
|
||||
Gtk.ColumnViewColumn.__init__(self)
|
||||
|
|
|
@ -4,6 +4,43 @@ from . import column
|
|||
from gi.repository import Gtk
|
||||
import unittest
|
||||
|
||||
class FakeListItem:
|
||||
def __init__(self): self.child = None
|
||||
def get_item(self): return None
|
||||
def get_child(self): return self.child
|
||||
def set_child(self, child): self.child = child
|
||||
|
||||
|
||||
class TestLabelFactory(unittest.TestCase):
|
||||
def test_init(self):
|
||||
factory = column.LabelFactory(0.5)
|
||||
self.assertIsInstance(factory, Gtk.SignalListItemFactory)
|
||||
self.assertEqual(factory.xalign, 0.5)
|
||||
|
||||
def test_setup_teardown(self):
|
||||
fake = FakeListItem()
|
||||
factory = column.LabelFactory(0.5)
|
||||
|
||||
factory.on_setup(factory, fake)
|
||||
self.assertIsInstance(fake.child, Gtk.Label)
|
||||
self.assertEqual(fake.child.get_xalign(), 0.5)
|
||||
|
||||
factory.on_teardown(factory, fake)
|
||||
self.assertIsNone(fake.child)
|
||||
|
||||
def test_bind_unbind(self):
|
||||
fake = FakeListItem()
|
||||
factory = column.LabelFactory(0.5)
|
||||
factory.on_setup(factory, fake)
|
||||
|
||||
with self.assertRaises(NotImplementedError):
|
||||
factory.on_bind(factory, fake)
|
||||
|
||||
fake.child.set_text("abcde")
|
||||
factory.on_unbind(factory, fake)
|
||||
self.assertEqual(fake.child.get_text(), "")
|
||||
|
||||
|
||||
class TestPlaylistColumn(unittest.TestCase):
|
||||
def tearDown(self):
|
||||
settings.reset()
|
||||
|
|
Loading…
Reference in New Issue