# Bryan Schumaker (4 / 21 / 2011)

import gtk
from libsaria import controls
from ocarina.body import button
from ocarina.body import image

page  = gtk.HBox(False, 5)
label = gtk.Label("Now Playing")

ARTWORK = image.Image()
page.pack_start(ARTWORK, False, False)

def pack_label(box, label):
	a = gtk.Alignment(0, 0.5, 0, 0)
	a.add(label)
	box.pack_start(a)

TITLE   = gtk.Label()
ARTIST  = gtk.Label("by")
ALBUM   = gtk.Label("from")
tag_box = gtk.VBox(True)
view    = gtk.Viewport()
tags    = gtk.ScrolledWindow()
view.set_shadow_type(gtk.SHADOW_NONE)
tags.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
pack_label(tag_box, TITLE)
pack_label(tag_box, ARTIST)
pack_label(tag_box, ALBUM)
view.add(tag_box)
tags.add(view)
page.pack_start(tags)

YEAR     = gtk.Label("Year:")
LENGTH   = gtk.Label("Length:")
COUNT    = gtk.Label("Play count:")
attr_box = gtk.VBox(True)
pack_label(attr_box, YEAR)
pack_label(attr_box, LENGTH)
pack_label(attr_box, COUNT)
page.pack_start(attr_box)

LIKE    = button.like_button(True)
DISLIKE = button.dislike_button(True)
buttons = gtk.HBox(True)
buttons.pack_start(   LIKE, False, False)
buttons.pack_start(DISLIKE, False, False)
page.pack_start(buttons, False, False)

page.show_all()
label.show()

sa_id = None
def resize_art(*args):
	set_art(ARTWORK.get_file())
	page.disconnect(sa_id)
sa_id = page.connect("size-allocate", resize_art)

def set_art(path):
	ARTWORK.set_image(path, 64)

def on_like(like):
	def _on_like1(like):
		LIKE.set_active(like == True)
		DISLIKE.set_active(like == False)
	def _on_like0(like):
		button.toggle_call_unconnected(DISLIKE, _on_like1, like)
	button.toggle_call_unconnected(LIKE, _on_like0, like)

def on_load(attrs):
	TITLE.set_text(attrs["title"])
	ARTIST.set_text("by %s" % attrs["artist"])
	ALBUM.set_text("from %s" % attrs["album"])
	YEAR.set_text("Year: %s" % attrs["year"])
	LENGTH.set_text("Length: %s" % attrs["lenstr"])
	COUNT.set_text("Play count: %s" % attrs["count"])
	set_art(attrs["art"])
	on_like(attrs["like"])
