rind: Select the currently playing track in the playlist
And also scroll so the selected path is visible. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
2d6d4444bf
commit
b0cbcd7f9d
|
@ -14,6 +14,7 @@ class PlaylistModel(GObject.GObject, Gtk.TreeModel):
|
|||
GObject.GObject.__init__(self)
|
||||
self.set_playlist(curds.playlist.Root.lookup("Collection"))
|
||||
curds.notify.register("add-track", self.on_add_track, queue=True)
|
||||
curds.notify.register("next-track", self.on_next_track)
|
||||
curds.notify.register("playlist-changed", self.on_playlist_changed, queue=True)
|
||||
RandomButton.connect("toggled", self.on_random_toggled)
|
||||
|
||||
|
@ -67,6 +68,10 @@ class PlaylistModel(GObject.GObject, Gtk.TreeModel):
|
|||
path = Gtk.TreePath.new_from_indices([ index ])
|
||||
self.row_inserted(path, self.get_iter(path))
|
||||
|
||||
def on_next_track(self, track):
|
||||
if self.playlist == curds.playlist.Root.current[0]:
|
||||
self.scroll_to_current()
|
||||
|
||||
def on_playlist_changed(self, plist):
|
||||
if plist == self.playlist:
|
||||
Runtime.set_text(self.playlist.runtime())
|
||||
|
@ -75,11 +80,18 @@ class PlaylistModel(GObject.GObject, Gtk.TreeModel):
|
|||
active = RandomButton.get_active()
|
||||
RandomButton.set_active(self.playlist.set_random(active))
|
||||
|
||||
def scroll_to_current(self):
|
||||
if self.playlist.current >= 0 and Treeview.get_model() == self:
|
||||
path = Gtk.TreePath([ self.playlist.current ])
|
||||
Treeview.get_selection().select_path(path)
|
||||
Treeview.scroll_to_cell(path, None, True, 0.25, 0)
|
||||
|
||||
def set_playlist(self, plist):
|
||||
Treeview.set_model(None)
|
||||
self.playlist = plist
|
||||
Treeview.set_model(self)
|
||||
Runtime.set_text(self.playlist.runtime())
|
||||
self.scroll_to_current()
|
||||
|
||||
|
||||
PlistModel = PlaylistModel()
|
||||
|
|
|
@ -96,3 +96,18 @@ class TestPlaylist(unittest.TestCase):
|
|||
self.assertTrue(plist.random)
|
||||
playlist.RandomButton.set_active(False)
|
||||
self.assertFalse(plist.random)
|
||||
|
||||
def test_next(self):
|
||||
model = playlist.PlaylistModel()
|
||||
selection = playlist.Treeview.get_selection()
|
||||
playlist.Treeview.set_model(model)
|
||||
|
||||
for i in range(1, 11):
|
||||
curds.Track.lookup(os.path.join(test_album, f"{i:02} - Test Track {i:02}.ogg"))
|
||||
gtk.main_loop()
|
||||
|
||||
for i in range(10):
|
||||
curds.playlist.Root.next()
|
||||
(model, rows) = selection.get_selected_rows()
|
||||
self.assertEqual(len(rows), 1)
|
||||
self.assertEqual(rows[0].get_indices(), [ i ])
|
||||
|
|
Loading…
Reference in New Issue