rind: Add runtime label

I add this to the overlay so it doesn't take up space on its own.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2019-04-06 21:18:36 -04:00
parent c2d876b545
commit 7ec500bcd7
3 changed files with 36 additions and 4 deletions

View File

@ -640,6 +640,24 @@ audio-volume-medium-symbolic</property>
</style>
</object>
</child>
<child type="overlay">
<object class="GtkLabel" id="runtime">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">end</property>
<property name="valign">end</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
<style>
<class name="osd"/>
</style>
</object>
<packing>
<property name="pass_through">True</property>
<property name="index">1</property>
</packing>
</child>
</object>
</child>
</object>

View File

@ -3,14 +3,18 @@ from . import gtk
import curds
from gi.repository import GObject, Gtk
Treeview = gtk.Builder.get_object("playlist_treeview")
RandomButton = gtk.Builder.get_object("random_button")
Runtime = gtk.Builder.get_object("runtime")
cols = [ "tracknumber", "title", "length", "artist", "album", "date", "genre" ]
class PlaylistModel(GObject.GObject, Gtk.TreeModel):
def __init__(self, *args, **kwargs):
GObject.GObject.__init__(self)
self.playlist = curds.PlaylistManager.lookup("Collection")
self.set_playlist(curds.PlaylistManager.lookup("Collection"))
curds.notify.register("add-track", self.on_add_track, queue=True)
curds.notify.register("playlist-changed", self.on_playlist_changed, queue=True)
RandomButton.connect("toggled", self.on_random_toggled)
def do_get_column_type(self, col):
@ -63,6 +67,10 @@ class PlaylistModel(GObject.GObject, Gtk.TreeModel):
path = Gtk.TreePath.new_from_indices([ index ])
self.row_inserted(path, self.get_iter(path))
def on_playlist_changed(self, plist):
if plist == self.playlist:
Runtime.set_text(self.playlist.runtime())
def on_random_toggled(self, *args):
active = RandomButton.get_active()
RandomButton.set_active(self.playlist.set_random(active))
@ -71,8 +79,8 @@ class PlaylistModel(GObject.GObject, Gtk.TreeModel):
Treeview.set_model(None)
self.playlist = plist
Treeview.set_model(self)
Runtime.set_text(self.playlist.runtime())
PlistModel = PlaylistModel()
Treeview = gtk.Builder.get_object("playlist_treeview")
Treeview.set_model(PlistModel)

View File

@ -14,9 +14,12 @@ class TestPlaylist(unittest.TestCase):
def test_init(self):
self.assertIsInstance(gtk.Builder.get_object("playlist_treeview"), Gtk.TreeView)
self.assertIsInstance(playlist.PlistModel, Gtk.TreeModel)
self.assertIsInstance(playlist.PlistModel, Gtk.TreeModel)
self.assertIsInstance(playlist.Runtime, Gtk.Label)
self.assertEqual(playlist.Treeview, gtk.Builder.get_object("playlist_treeview"))
self.assertEqual(playlist.Treeview.get_model(), playlist.PlistModel)
self.assertEqual(playlist.Runtime.get_text(), "")
def test_model_init(self):
model = playlist.PlaylistModel()
@ -36,7 +39,8 @@ class TestPlaylist(unittest.TestCase):
self.assertEqual(len(model), 0)
self.assertRaises(ValueError, model.get_iter, path)
self.assertEqual(model.iter_n_children(None), 0)
self.assertIsNone(model.iter_nth_child(None, 1))
self.assertIsNone(model.iter_nth_child(None, 1))
self.assertEqual(playlist.Runtime.get_text(), "")
def test_model(self):
plist = curds.Playlist("Test Playlist")
@ -52,6 +56,8 @@ class TestPlaylist(unittest.TestCase):
tracks.append(track)
plist.add(track)
self.assertEqual(len(model), i)
while curds.notify.run_queued(): continue
self.assertEqual(playlist.Runtime.get_text(), plist.runtime())
iter = model.get_iter(path)
self.assertEqual(iter.user_data, 1)