sidebar: Create a custom listrow for User playlists
With a button that deletes the user-created playlist when clicked Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
6c8903e7fd
commit
00d43547e5
|
@ -1,15 +1,17 @@
|
|||
# Copyright 2021 (c) Anna Schumaker.
|
||||
from . import tagbox
|
||||
from . import tagrow
|
||||
from . import user
|
||||
from gi.repository import Gtk
|
||||
import trackdb
|
||||
import unittest
|
||||
|
||||
Expected = [ ("Collection", "media-playback-start"),
|
||||
("Favorites", "emblem-favorites"),
|
||||
("New Tracks", "starred"),
|
||||
("Previous", "edit-undo"),
|
||||
("Test", "audio-x-generic"),
|
||||
("Up Next", "edit-redo") ]
|
||||
Expected = [ ("Collection", "media-playback-start", tagrow.TagRow),
|
||||
("Favorites", "emblem-favorites", tagrow.TagRow),
|
||||
("New Tracks", "starred", tagrow.TagRow),
|
||||
("Previous", "edit-undo", tagrow.TagRow),
|
||||
("Test", "audio-x-generic", user.UserTagRow),
|
||||
("Up Next", "edit-redo", tagrow.TagRow) ]
|
||||
|
||||
class TestUserSidebar(unittest.TestCase):
|
||||
def test_user_sidebar_init(self):
|
||||
|
@ -22,11 +24,23 @@ class TestUserSidebar(unittest.TestCase):
|
|||
self.assertEqual(user.Icons["Previous"], "edit-undo")
|
||||
self.assertEqual(user.Icons["Up Next"], "edit-redo")
|
||||
|
||||
def test_user_sidebar_row(self):
|
||||
tag = trackdb.tags.User.add("Test")
|
||||
row = user.UserTagRow(tag, "audio-x-generic")
|
||||
|
||||
self.assertIsInstance(row.remove, Gtk.Button)
|
||||
self.assertEqual(row.remove.get_icon_name(), "list-remove")
|
||||
self.assertIn(row.remove, row.grid)
|
||||
|
||||
row.remove_tag(row.remove)
|
||||
self.assertIsNone(trackdb.tags.User["Test"])
|
||||
|
||||
def test_user_sidebar(self):
|
||||
user.TagBox = user.UserTagBox(trackdb.tags.User, "audio-x-generic")
|
||||
tag = trackdb.tags.User.add("Test")
|
||||
user.TagBox.bus.complete()
|
||||
|
||||
for (i, (tag, icon)) in enumerate(Expected):
|
||||
for (i, (tag, icon, type)) in enumerate(Expected):
|
||||
self.assertIsInstance(user.TagBox[i], type)
|
||||
self.assertEqual(user.TagBox[i].tag, trackdb.tags.User[tag])
|
||||
self.assertEqual(user.TagBox[i].image.get_icon_name(), icon)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# Copyright 2021 (c) Anna Schumaker.
|
||||
from . import tagbox
|
||||
from . import tagrow
|
||||
from gi.repository import Gtk
|
||||
import trackdb
|
||||
|
||||
Icons = { "Collection" : "media-playback-start",
|
||||
|
@ -10,8 +11,21 @@ Icons = { "Collection" : "media-playback-start",
|
|||
"Up Next" : "edit-redo" }
|
||||
|
||||
|
||||
class UserTagRow(tagrow.TagRow):
|
||||
def __init__(self, tag, icon):
|
||||
tagrow.TagRow.__init__(self, tag, icon)
|
||||
self.remove = Gtk.Button.new_from_icon_name("list-remove")
|
||||
self.remove.connect("clicked", self.remove_tag)
|
||||
self.grid.attach(self.remove, 2, 0, 1, 1)
|
||||
|
||||
def remove_tag(self, button):
|
||||
trackdb.tags.User.remove(self.tag)
|
||||
|
||||
|
||||
class UserTagBox(tagbox.TagBox):
|
||||
def __alloc_tagrow__(self, tag):
|
||||
if tag.name not in Icons.keys():
|
||||
return UserTagRow(tag, self.icon)
|
||||
return tagrow.TagRow(tag, Icons.get(tag.name, self.icon))
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue