playlist: Add a Filter to the controls
And respond when text is typed in the search bar Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
e8fc15dc6c
commit
315312615e
|
@ -1,4 +1,5 @@
|
|||
# Copyright 2021 (c) Anna Schumaker.
|
||||
from . import filter
|
||||
from gi.repository import Gtk
|
||||
import trackdb
|
||||
|
||||
|
@ -6,9 +7,11 @@ class Controls(Gtk.Box):
|
|||
def __init__(self):
|
||||
Gtk.Box.__init__(self)
|
||||
self.tag = None
|
||||
self.filter = filter.Filter()
|
||||
|
||||
self.search = Gtk.SearchEntry()
|
||||
self.search.set_property("placeholder-text", "Type to filter tracks")
|
||||
self.search.connect("search-changed", self.search_changed)
|
||||
self.search.set_hexpand(True)
|
||||
self.append(self.search)
|
||||
|
||||
|
@ -42,3 +45,10 @@ class Controls(Gtk.Box):
|
|||
def loop_toggled(self, toggle):
|
||||
self.tag.loop = toggle.get_active()
|
||||
trackdb.save()
|
||||
|
||||
def search_changed(self, search):
|
||||
try:
|
||||
self.filter.set_search_text(search.get_text())
|
||||
self.search.remove_css_class("warning")
|
||||
except:
|
||||
self.search.add_css_class("warning")
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
# Copyright 2021 (c) Anna Schumaker.
|
||||
from . import controls
|
||||
from . import filter
|
||||
from gi.repository import Gtk
|
||||
import trackdb
|
||||
import unittest
|
||||
|
@ -12,6 +13,7 @@ class TestPlaylistControls(unittest.TestCase):
|
|||
self.assertIsInstance(ctrl.search, Gtk.SearchEntry)
|
||||
self.assertIsInstance(ctrl.random, Gtk.ToggleButton)
|
||||
self.assertIsInstance(ctrl.loop, Gtk.ToggleButton)
|
||||
self.assertIsInstance(ctrl.filter, filter.Filter)
|
||||
|
||||
self.assertEqual(ctrl.random.get_icon_name(), "media-playlist-shuffle")
|
||||
self.assertEqual(ctrl.loop.get_icon_name(), "media-playlist-repeat")
|
||||
|
|
Loading…
Reference in New Issue