sidebar: Create an AddPlaylistEntry

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2021-11-04 17:37:18 -04:00
parent 0152ba1431
commit 5d18c336d5
2 changed files with 52 additions and 0 deletions

View File

@ -49,3 +49,31 @@ class TestProgressBar(unittest.TestCase):
child = child.get_next_sibling()
self.assertIsInstance(child, Gtk.Label)
self.assertEqual(child.get_text(), " ")
class TestAddPlaylistEntry(unittest.TestCase):
def test_init(self):
entry = widgets.AddPlaylistEntry()
self.assertIsInstance(entry, Gtk.Entry)
self.assertEqual(entry.get_placeholder_text(), "Add new playlist")
self.assertEqual(entry.get_icon_name(Gtk.EntryIconPosition.PRIMARY),
"list-add")
def test_clear(self):
entry = widgets.AddPlaylistEntry()
self.assertIsNone(entry.get_icon_name(Gtk.EntryIconPosition.SECONDARY))
entry.set_text("Test")
self.assertEqual(entry.get_icon_name(Gtk.EntryIconPosition.SECONDARY),
"edit-clear-symbolic")
entry.icon_released(entry, Gtk.EntryIconPosition.SECONDARY)
self.assertEqual(entry.get_text(), "")
def test_activate(self):
entry = widgets.AddPlaylistEntry()
self.assertIsNone(db.user.Table.lookup("Test Playlist"))
entry.set_text("Test Playlist")
entry.icon_released(entry, Gtk.EntryIconPosition.PRIMARY)
self.assertEqual(entry.get_text(), "")
self.assertIsNotNone(db.user.Table.lookup("Test Playlist"))
entry.icon_released(entry, Gtk.EntryIconPosition.PRIMARY)
self.assertIsNone(db.user.Table.lookup(""))

View File

@ -26,3 +26,27 @@ class ProgressBar(Gtk.Box):
self.append(Gtk.Label.new(" "))
self.append(scanner.ProgressBar())
self.append(Gtk.Label.new(" "))
class AddPlaylistEntry(Gtk.Entry):
def __init__(self):
Gtk.Entry.__init__(self)
self.set_placeholder_text("Add new playlist")
self.set_icon_from_icon_name(Gtk.EntryIconPosition.PRIMARY, "list-add")
self.connect("icon-release", self.icon_released)
def icon_released(self, entry, pos):
if pos == Gtk.EntryIconPosition.SECONDARY:
self.set_text("")
else:
self.emit("activate")
def do_activate(self):
if self.get_text() != "":
db.user.Table.find(self.get_text())
scanner.commit()
self.set_text("")
def do_changed(self):
icon = None if self.get_text() == "" else "edit-clear-symbolic"
self.set_icon_from_icon_name(Gtk.EntryIconPosition.SECONDARY, icon)