lib: Give tags a track_selected() function
For use when tracks are manually selected. I use this to wire up a response to double-clicking the playlist view. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
a6c78f55a3
commit
171e8a1829
|
@ -13,6 +13,9 @@ class FakeTrack(GObject.GObject):
|
|||
def __int__(self):
|
||||
return self.trackid
|
||||
|
||||
def add_to_playlist(self, name):
|
||||
self.tag.add_track(self)
|
||||
|
||||
def remove_from_playlist(self, name):
|
||||
self.tag.remove_track(self)
|
||||
|
||||
|
|
|
@ -118,6 +118,11 @@ class Tag:
|
|||
if self.current >= len(self.tracks):
|
||||
self.current = -1
|
||||
|
||||
def track_selected(self, track):
|
||||
with self.lock:
|
||||
self.current = self.tracks.index(track)
|
||||
track.add_to_playlist("Previous")
|
||||
|
||||
|
||||
class SuperTag(Tag):
|
||||
def __init__(self, parent, name, sort=None):
|
||||
|
|
|
@ -180,6 +180,23 @@ class TestTag(unittest.TestCase):
|
|||
self.assertEqual(t.next(), 0)
|
||||
self.assertEqual(t.next(), 1)
|
||||
|
||||
def test_tag_track_selected(self):
|
||||
t = tag.Tag("test")
|
||||
p = tag.Tag("Previous")
|
||||
t.tracks = [ fake.Track(0, p), fake.Track(1, p), fake.Track(2, p) ]
|
||||
|
||||
t.track_selected(fake.Track(2, p))
|
||||
self.assertEqual(t.current, 2)
|
||||
self.assertIn(fake.Track(2, p), p.tracks)
|
||||
|
||||
t.track_selected(fake.Track(1, p))
|
||||
self.assertEqual(t.current, 1)
|
||||
self.assertIn(fake.Track(1, p), p.tracks)
|
||||
|
||||
t.track_selected(fake.Track(0, p))
|
||||
self.assertEqual(t.current, 0)
|
||||
self.assertIn(fake.Track(0, p), p.tracks)
|
||||
|
||||
def test_tag_stacked(self):
|
||||
t = tag.Tag("test")
|
||||
t.tracks = [ 0, 1, 2 ]
|
||||
|
|
|
@ -4,6 +4,8 @@ from . import controls
|
|||
from . import model
|
||||
from . import runtime
|
||||
from gi.repository import Gtk
|
||||
import audio
|
||||
import trackdb
|
||||
|
||||
Model = model.TagModel()
|
||||
|
||||
|
@ -18,7 +20,14 @@ FilterModel.set_model(Model)
|
|||
Selection = Gtk.MultiSelection()
|
||||
Selection.set_model(FilterModel)
|
||||
|
||||
def on_row_activate(view, position):
|
||||
track = FilterModel.get_item(position)
|
||||
if audio.Player.play_track(track) == True:
|
||||
Model.tag.track_selected(track)
|
||||
trackdb.save()
|
||||
|
||||
View = Gtk.ColumnView()
|
||||
View.connect("activate", on_row_activate)
|
||||
View.add_css_class("data-table")
|
||||
View.set_enable_rubberband(True)
|
||||
View.set_hexpand(True)
|
||||
|
|
Loading…
Reference in New Issue