scanner: Create an EnableSwitch
For changing a library path's "enabled" property Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
8f98dfdde7
commit
2ab67258e9
|
@ -22,6 +22,9 @@ def UpdateAllButton():
|
|||
def RemoveButton(library):
|
||||
return widgets.RemoveButton(library, Queue)
|
||||
|
||||
def EnableSwitch(library):
|
||||
return widgets.EnableSwitch(library, Queue)
|
||||
|
||||
|
||||
def commit():
|
||||
Queue.push(task.CommitTask())
|
||||
|
|
|
@ -49,3 +49,5 @@ class TestScanner(unittest.TestCase):
|
|||
scanner.widgets.UpdateAllButton)
|
||||
self.assertIsInstance(scanner.RemoveButton(lib),
|
||||
scanner.widgets.RemoveButton)
|
||||
self.assertIsInstance(scanner.EnableSwitch(lib),
|
||||
scanner.widgets.EnableSwitch)
|
||||
|
|
|
@ -168,3 +168,24 @@ class TestScannerRemoveButton(unittest.TestCase):
|
|||
self.assertEqual(len(q.tasks), 1)
|
||||
self.assertIsInstance(q.tasks[0], task.RemoveLibrarySchedulerTask)
|
||||
q.tasks_finished()
|
||||
|
||||
|
||||
class TestEnableSwitch(unittest.TestCase):
|
||||
def test_init(self):
|
||||
lib = db.library.Table.find("/a/b/c")
|
||||
q = queue.TaskQueue()
|
||||
es = widgets.EnableSwitch(lib, q)
|
||||
|
||||
self.assertIsInstance(es, Gtk.Switch)
|
||||
self.assertEqual(es.library, lib)
|
||||
self.assertEqual(es.queue, q)
|
||||
self.assertEqual(es.get_halign(), Gtk.Align.CENTER)
|
||||
self.assertEqual(es.get_valign(), Gtk.Align.CENTER)
|
||||
self.assertTrue(es.get_active())
|
||||
|
||||
es.set_active(False)
|
||||
self.assertFalse(es.library.enabled)
|
||||
self.assertFalse(widgets.EnableSwitch(lib, q).get_active())
|
||||
|
||||
es.set_active(True)
|
||||
self.assertTrue(lib.enabled)
|
||||
|
|
|
@ -124,3 +124,17 @@ class RemoveButton(ScannerButton):
|
|||
|
||||
def do_clicked(self):
|
||||
self.queue.push(task.RemoveLibrarySchedulerTask(self.library))
|
||||
|
||||
|
||||
class EnableSwitch(Gtk.Switch):
|
||||
def __init__(self, library, queue):
|
||||
Gtk.Switch.__init__(self)
|
||||
self.set_active(library.enabled)
|
||||
self.set_halign(Gtk.Align.CENTER)
|
||||
self.set_valign(Gtk.Align.CENTER)
|
||||
self.connect("notify::active", self.switched)
|
||||
self.library = library
|
||||
self.queue = queue
|
||||
|
||||
def switched(self, switch, param):
|
||||
self.library.enabled = switch.get_active()
|
||||
|
|
Loading…
Reference in New Issue