# Bryan Schumaker (10 / 18 / 2010)
import ocarina

gtk      = ocarina.gtk
gobject  = ocarina.gobject
invite   = ocarina.libsaria.event.invite
libsaria = ocarina.libsaria

get_time  = None
get_attrs = None

def set_fns():
	global get_time
	global get_attrs
	global file_id
	get_time  = ocarina.libsaria.audio.get_time
	get_attrs = libsaria.sources.get_attrs
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
		time = get_time()
		if time == "":
			time = "00:00"
		self.set_text(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):
		if id != None:
			text = str(get_attrs(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, "count", "Play count:")

class LengthLabel(AttrLabel):
	def __init__(self):
		AttrLabel.__init__(self, "lenstr", "Length:")

class LengthLabel2(AttrLabel):
	def __init__(self):
		AttrLabel.__init__(self, "lenstr", "/")
