ocarina/ocarina/label.py

85 lines
1.9 KiB
Python

# Bryan Schumaker (10 / 18 / 2010)
import ocarina
gtk = ocarina.gtk
gobject = ocarina.gobject
invite = ocarina.libsaria.event.invite
libsaria = ocarina.libsaria
#update = None
get_time = None
get_attrs = None
file_to_id = None
def set_fns():
#global update
global get_time
global get_attrs
global file_to_id
#update = ocarina.libsaria.audio.get_progress
get_time = ocarina.libsaria.audio.get_time
get_attrs = libsaria.sources.get_attrs
file_to_id = libsaria.sources.file_to_id
invite("POSTSTART", set_fns)
class TimeLabel(gtk.Label):
def __init__(self):
gtk.Label.__init__(self)
gobject.timeout_add(500, self.update)
self.show()
def update(self):
global get_time
self.set_text(get_time() + " ")
return True
class AttrLabel(gtk.Alignment):
def __init__(self, attr, other = None):
gtk.Alignment.__init__(self, 0, 0.5, 0, 0)
self.label = gtk.Label()
self.attr = attr
self.other = other
self.add(self.label)
self.show_all()
invite("POSTLOAD", self.update)
def update(self, filepath):
global get_attrs
id = file_to_id(filepath)
if id != None:
text = str(get_attrs(id, self.attr)[0])
if self.other:
text = "%s %s" % (self.other, text)
self.label.set_text(text)
else:
self.label.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")
class YearLabel(AttrLabel):
def __init__(self):
AttrLabel.__init__(self, "year", "Year:")
class CountLabel(AttrLabel):
def __init__(self):
AttrLabel.__init__(self, "count", "Play count:")
class LengthLabel(AttrLabel):
def __init__(self):
AttrLabel.__init__(self, "lenstr", "Length:")
class LengthLabel2(AttrLabel):
def __init__(self):
AttrLabel.__init__(self, "lenstr", "/")