ocarina/ocarina/label.py

86 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
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
lib_get_attr = libsaria.collection.lib_get_attr
lib_find_id = libsaria.collection.lib_find_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 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.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, "playcount", "Play count:")
class LengthLabel(AttrLabel):
def __init__(self):
AttrLabel.__init__(self, "lenstr", "Length:")
class LengthLabel2(AttrLabel):
def __init__(self):
AttrLabel.__init__(self, "lenstr", "/")