ocarina: Set text on footer labels

This sets (title, album), position and duration values
This commit is contained in:
Bryan Schumaker 2011-04-20 20:34:14 -04:00
parent 5b5a232b43
commit bce7651be5
6 changed files with 38 additions and 24 deletions

View File

@ -2,6 +2,7 @@
__all__ = ['audio']
import gst
import libsaria
call = libsaria.event.call
expand = libsaria.path.expand
@ -55,9 +56,9 @@ def get_progress():
def get_time():
global audio
global tdelta
pos = audio.position()
if pos == 0:
if audio.get_state() == gst.STATE_NULL:
return ""
pos = audio.position()
pos /= 1000
time = str(tdelta(microseconds=pos))
time = time.rsplit('.', 1)[0]

View File

@ -9,6 +9,7 @@ player = None
time = None
bus = None
length = None
call = libsaria.event.call
# An init function for faster startup
def init():

View File

@ -1,7 +1,10 @@
# Bryan Schumaker (11/25/2010)
import gtk
import gobject
import tiny
from libsaria import audio
footer = gtk.VBox()
hsep = gtk.HSeparator()
@ -11,12 +14,21 @@ footer.pack_start(hsep, True, True)
footer.pack_start(tiny.tiny, True, True)
footer.show()
def update_pos():
time = audio.get_time()
tiny.update_pos(time)
return True
gobject.timeout_add(500, update_pos)
def on_play():
tiny.on_play()
def on_pause():
tiny.on_pause()
def on_load():
tiny.on_load()
#import gtk
#import pango
#import ocarina

View File

@ -3,19 +3,28 @@
import gtk
import pango
import ocarina
import libsaria
from ocarina.body import button
tiny = gtk.HBox()
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(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)
@ -24,6 +33,9 @@ add_button( "STOP", button.stop_button)
add_button( "NEXT", button.next_button)
tiny.show()
def update_pos(pos):
cur_pos.set_text(pos)
def on_play():
PLAY.hide()
PAUSE.show()
@ -31,3 +43,9 @@ def on_play():
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 %s" % (title, artist))
duration.set_text(" / %s" % lenstr)

View File

@ -18,6 +18,7 @@ def on_stop(*args):
footer.on_pause()
invite("POSTSTOP", on_stop)
def on_next(*args):
def on_load(*args):
footer.on_load()
queue.refresh()
invite("POSTNEXT", on_next)
invite("POSTLOAD", on_load)

View File

@ -17,21 +17,6 @@ def set_fns():
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)
@ -74,7 +59,3 @@ class CountLabel(AttrLabel):
class LengthLabel(AttrLabel):
def __init__(self):
AttrLabel.__init__(self, "lenstr", "Length:")
class LengthLabel2(AttrLabel):
def __init__(self):
AttrLabel.__init__(self, "lenstr", "/")