# Bryan Schumaker (2 / 17 / 2011)

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

tiny = gtk.HBox()
hide = tiny.hide
show = tiny.show

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

now_playing = gtk.Label(ocarina.__vers__)
now_playing.set_ellipsize(pango.ELLIPSIZE_END)
now_playing.show()

cur_pos  = gtk.Label()
duration = gtk.Label()
cur_pos.show()
duration.show()

def add_button(name, button_func, show = True):
	b = button_func(show)
	globals()[name] = b
	tiny.pack_start(b, False, False)

tiny.pack_start(now_playing,  True,  True)
tiny.pack_start(    cur_pos, False, False)
tiny.pack_start(   duration, False, False)
add_button( "REWIND", button.rewind_button)
add_button("FORWARD", button.forward_button)
add_button(   "PLAY", button.play_button)
add_button(  "PAUSE", button.pause_button, False)
add_button(   "STOP", button.stop_button)
add_button(   "NEXT", button.next_button)
add_button(     "UP", button.up_button)

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

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

def update_pos(pos):
	cur_pos.set_text(pos)

def on_play():
	PLAY.hide()
	PAUSE.show()

def on_pause():
	PLAY.show()
	PAUSE.hide()

load_attrs = ("title", "artist", "lenstr")
def on_load():
	title, artist, lenstr = libsaria.sources.get_attrs(*load_attrs)
	now_playing.set_text("%s by %s" % (title, artist))
	duration.set_text(" / %s" % lenstr)
	set_art("images/ocarina.png")
