rind: Add a random button

We use this to toggle the random property of playlists

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2019-03-20 10:45:28 -04:00
parent ae92da8e82
commit 5885228fd1
3 changed files with 37 additions and 0 deletions

View File

@ -121,6 +121,25 @@
</child>
</object>
</child>
<child>
<object class="GtkToggleButton" id="random_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">media-playlist-shuffle-symbolic</property>
<property name="icon_size">3</property>
</object>
</child>
</object>
<packing>
<property name="pack_type">end</property>
<property name="position">3</property>
</packing>
</child>
</object>
</child>
<child>

View File

@ -3,6 +3,7 @@ from . import gtk
import curds
from gi.repository import GObject, Gtk
RandomButton = gtk.Builder.get_object("random_button")
cols = [ "tracknumber", "title", "length", "artist", "album", "date", "genre" ]
class PlaylistModel(GObject.GObject, Gtk.TreeModel):
@ -10,6 +11,7 @@ class PlaylistModel(GObject.GObject, Gtk.TreeModel):
GObject.GObject.__init__(self)
self.playlist = curds.PlaylistManager["Collection"]
curds.Notify.notify_me("add-track", self.on_add_track)
RandomButton.connect("toggled", self.on_random_toggled)
def do_get_column_type(self, col):
return str
@ -62,6 +64,10 @@ class PlaylistModel(GObject.GObject, Gtk.TreeModel):
iter = self.get_iter(path)
self.row_inserted(path, iter)
def on_random_toggled(self, *args):
active = RandomButton.get_active()
RandomButton.set_active(self.playlist.set_random(active))
def set_playlist(self, plist):
self.playlist = plist

View File

@ -74,3 +74,15 @@ class TestPlaylist(unittest.TestCase):
iter.user_data = 99
self.assertEqual(model.get_value(iter, 0), "")
def test_random(self):
plist = curds.Playlist("Test Playlist")
model = playlist.PlaylistModel()
model.set_playlist(plist)
self.assertFalse(plist.random)
self.assertIsInstance(playlist.RandomButton, Gtk.ToggleButton)
playlist.RandomButton.set_active(True)
self.assertTrue(plist.random)
playlist.RandomButton.set_active(False)
self.assertFalse(plist.random)