From af8eb41589895614759bea473945e1e5f95868ec Mon Sep 17 00:00:00 2001 From: Bryan Schumaker Date: Sat, 23 Oct 2010 14:03:03 -0400 Subject: [PATCH] Attr labels I created labels that automatically update whenever a song is changed. These labels are used for displaying the artist, album, and title of the currently playing song. They can also be used in the future fir displaying any attribute of a song. --- ocarina/info.py | 26 ++++++++++++------------- ocarina/label.py | 50 +++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 58 insertions(+), 18 deletions(-) diff --git a/ocarina/info.py b/ocarina/info.py index 8b5d82b4..56b46aec 100644 --- a/ocarina/info.py +++ b/ocarina/info.py @@ -108,26 +108,26 @@ class NowPlaying(gtk.Table): self.artist = gtk.Label("") self.album = gtk.Label("") self.title = gtk.Label("") - self.attach(gtk.Label("Artist"), 0, 1, 0, 1, gtk.SHRINK, 5, 5) - self.attach(gtk.Label("Album"), 0, 1, 1, 2, gtk.SHRINK, 5, 5) - self.attach(gtk.Label("Title"), 0, 1, 2, 3, gtk.SHRINK, 5, 5) - self.attach(self.artist, 1, 2, 0, 1, gtk.SHRINK|gtk.EXPAND|gtk.FILL, 5, 5) - self.attach(self.album, 1, 2, 1, 2, gtk.SHRINK|gtk.EXPAND|gtk.FILL, 5, 5) - self.attach(self.title, 1, 2, 2, 3, gtk.SHRINK|gtk.EXPAND|gtk.FILL, 5, 5) + #self.attach(gtk.Label("Artist"), 0, 1, 0, 1, gtk.SHRINK, 5, 5) + #self.attach(gtk.Label("Album"), 0, 1, 1, 2, gtk.SHRINK, 5, 5) + #self.attach(gtk.Label("Title"), 0, 1, 2, 3, gtk.SHRINK, 5, 5) + self.attach(label.ArtistLabel(), 1, 2, 0, 1, gtk.SHRINK|gtk.EXPAND|gtk.FILL, 5, 5) + self.attach(label.AlbumLabel(), 1, 2, 1, 2, gtk.SHRINK|gtk.EXPAND|gtk.FILL, 5, 5) + self.attach(label.TitleLabel(), 1, 2, 2, 3, gtk.SHRINK|gtk.EXPAND|gtk.FILL, 5, 5) self.artist.set_ellipsize(pango.ELLIPSIZE_END) self.album.set_ellipsize(pango.ELLIPSIZE_END) self.title.set_ellipsize(pango.ELLIPSIZE_END) self.show_all() - libsaria.event.invite("POSTLOAD", self.change_labels) + #libsaria.event.invite("POSTLOAD", self.change_labels) - def change_labels(self, filepath): - id = libsaria.collection.lib_find_id(filepath) - if id: - self.title.set_text(lib_get_attr(id, "title")) - self.artist.set_text(lib_get_attr(id, "artist")) - self.album.set_text(lib_get_attr(id, "album")) + #def change_labels(self, filepath): + # id = libsaria.collection.lib_find_id(filepath) + # if id: + # self.title.set_text(lib_get_attr(id, "title")) + # self.artist.set_text(lib_get_attr(id, "artist")) + # self.album.set_text(lib_get_attr(id, "album")) class TwoWayPane(InfoBar): diff --git a/ocarina/label.py b/ocarina/label.py index 01c6f7b4..f80cbfec 100644 --- a/ocarina/label.py +++ b/ocarina/label.py @@ -1,18 +1,26 @@ # Bryan Schumaker (10 / 18 / 2010) import ocarina -gtk = ocarina.gtk -gobject = ocarina.gobject +gtk = ocarina.gtk +gobject = ocarina.gobject +invite = ocarina.libsaria.event.invite +libsaria = ocarina.libsaria #update = None -get_time = None +get_time = None +lib_get_attr = None +lib_find_id = None def set_fns(): #global update global get_time + global lib_get_attr + global lib_find_id #update = ocarina.libsaria.music.get_progress - get_time = ocarina.libsaria.music.get_time -ocarina.libsaria.event.invite("POSTSTART", set_fns) + get_time = ocarina.libsaria.music.get_time + lib_get_attr = libsaria.collection.lib_get_attr + lib_find_id = libsaria.collection.lib_find_id +invite("POSTSTART", set_fns) class TimeLabel(gtk.Label): @@ -25,3 +33,35 @@ class TimeLabel(gtk.Label): global get_time self.set_text(get_time()) return True + +class AttrLabel(gtk.Label): + def __init__(self, attr, other = None): + gtk.Label.__init__(self) + self.attr = attr + self.other = other + self.show() + invite("POSTLOAD", self.update) + + def update(self, filepath): + global lib_find_id + global lib_get_attr + id = lib_find_id(filepath) + if id: + text = str(lib_get_attr(id, self.attr)) + if self.other: + text = "%s %s" % (self.other, text) + self.set_text(text) + else: + self.set_text("") + +class TitleLabel(AttrLabel): + def __init__(self): + AttrLabel.__init__(self, "title") + +class ArtistLabel(AttrLabel): + def __init__(self): + AttrLabel.__init__(self, "artist", "by") + +class AlbumLabel(AttrLabel): + def __init__(self): + AttrLabel.__init__(self, "album", "from")