sidebar: Add selected tracks to the selected playlist

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2021-12-05 12:05:33 -05:00
parent 44f778bdb7
commit 2f1b7b397f
3 changed files with 17 additions and 1 deletions

View File

@ -1,4 +1,5 @@
# Copyright 2021 (c) Anna Schumaker.
import db
from gi.repository import Gtk
from . import stack
@ -7,13 +8,20 @@ class Sidebar(Gtk.Box):
Gtk.Box.__init__(self)
self.panel = panel
switcher = stack.Switcher()
box = stack.Box(switcher.get_stack())
self.append(switcher)
self.append(stack.Box(switcher.get_stack()))
self.append(box)
stak = switcher.get_stack()
stak.connect("playlist-changed", self.playlist_changed)
panel.set_playlist(stak.get_visible_child().get_selected_playlist())
box.get_add_update_button().connect("add-to-playlist", self.add_to_playlist)
def playlist_changed(self, stack, plist):
self.panel.set_playlist(plist)
def add_to_playlist(self, button, playlist):
if playlist.can_add_remove_tracks():
for track in self.panel.selected_tracks():
playlist.add_track(track)

View File

@ -63,3 +63,10 @@ class Box(Gtk.Box):
self.append(widgets.AddUpdateBox())
self.append(Gtk.Separator.new(Gtk.Orientation.HORIZONTAL))
self.append(widgets.ProgressBar())
def get_add_update_button(self):
child = self.get_first_child()
while child:
if isinstance(child, widgets.AddUpdateBox):
return child.get_first_child()
child = child.get_next_sibling()

View File

@ -116,6 +116,7 @@ class TestBox(unittest.TestCase):
child = child.get_next_sibling()
self.assertIsInstance(child, widgets.AddUpdateBox)
self.assertEqual(box.get_add_update_button(), child.get_first_child())
child = child.get_next_sibling()
self.assertIsInstance(child, Gtk.Separator)