playlist: Create a sort Factory
For creating SortRows and handling their signals Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
8adfb51082
commit
979071cd14
|
@ -114,3 +114,56 @@ class SortRow(Gtk.Box):
|
|||
|
||||
@GObject.Signal
|
||||
def move_down(self): pass
|
||||
|
||||
|
||||
class Factory(Gtk.SignalListItemFactory):
|
||||
def __init__(self, model):
|
||||
self.model = model
|
||||
Gtk.SignalListItemFactory.__init__(self)
|
||||
self.connect("setup", self.setup)
|
||||
self.connect("bind", self.bind)
|
||||
self.connect("unbind", self.unbind)
|
||||
self.connect("teardown", self.teardown)
|
||||
|
||||
def setup(self, factory, listitem):
|
||||
listitem.set_child(SortRow())
|
||||
|
||||
def bind(self, factory, listitem):
|
||||
child = listitem.get_child()
|
||||
child.set_item(listitem.get_item().get_string(),
|
||||
listitem.get_position(),
|
||||
self.model.get_n_enabled())
|
||||
child.connect("switched", self.row_switched)
|
||||
child.connect("reversed", self.row_reversed)
|
||||
child.connect("move-up", self.move_row_up)
|
||||
child.connect("move-down", self.move_row_down)
|
||||
|
||||
def unbind(self, factory, listitem):
|
||||
child = listitem.get_child()
|
||||
child.disconnect_by_func(self.row_switched)
|
||||
child.disconnect_by_func(self.row_reversed)
|
||||
child.disconnect_by_func(self.move_row_up)
|
||||
child.disconnect_by_func(self.move_row_down)
|
||||
|
||||
def teardown(self, factory, listitem):
|
||||
listitem.set_child(None)
|
||||
|
||||
def row_switched(self, row, enabled):
|
||||
field = row.label.get_field()
|
||||
if enabled:
|
||||
self.model.enable(field)
|
||||
index = self.model.get_enabled_model().get_index(field)
|
||||
else:
|
||||
index = self.model.get_enabled_model().get_index(field)
|
||||
self.model.disable(field)
|
||||
if index > 0:
|
||||
self.model.emit("items-changed", index - 1, 1, 1)
|
||||
|
||||
def row_reversed(self, row):
|
||||
self.model.get_enabled_model().reverse(row.label.get_field())
|
||||
|
||||
def move_row_up(self, row):
|
||||
self.model.get_enabled_model().move_up(row.label.get_field())
|
||||
|
||||
def move_row_down(self, row):
|
||||
self.model.get_enabled_model().move_down(row.label.get_field())
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# Copyright 2021 (c) Anna Schumaker.
|
||||
import unittest
|
||||
from gi.repository import Gtk
|
||||
from . import model
|
||||
from . import sort
|
||||
|
||||
class TestUpDownBox(unittest.TestCase):
|
||||
|
@ -194,3 +195,9 @@ class TestSortRow(unittest.TestCase):
|
|||
|
||||
row.updown.emit("move-down")
|
||||
self.assertTrue(self.move_down)
|
||||
|
||||
|
||||
class TestFactory(unittest.TestCase):
|
||||
def test_init(self):
|
||||
factory = sort.Factory(model.FlatSortModel())
|
||||
self.assertIsInstance(factory, Gtk.SignalListItemFactory)
|
||||
|
|
Loading…
Reference in New Issue