ocarina: Added album art
I put it on the now playing page for now. Eventually I'll put it in other places, too.
This commit is contained in:
parent
ad734ae8d3
commit
3d1b8773d5
|
@ -90,6 +90,7 @@ def get_artwork_id(id):
|
|||
return get_artwork_tags(artist, album)
|
||||
|
||||
def get_artwork(filepath):
|
||||
id = sources.get_attrs("id")
|
||||
file = get_artwork_id(id)
|
||||
libsaria.event.start("POSTGETART", file)
|
||||
libsaria.event.start("POSTGETART", file, id)
|
||||
libsaria.event.invite("POSTLOAD", get_artwork, True)
|
||||
|
|
|
@ -25,6 +25,7 @@ import queue
|
|||
import library
|
||||
import callbacks
|
||||
|
||||
callbacks.on_getart("images/ocarina.png", 0)
|
||||
libsaria.startup()
|
||||
print "Startup took:", uptime()
|
||||
gtk.main()
|
||||
|
|
|
@ -40,6 +40,9 @@ if up == True:
|
|||
else:
|
||||
show_less()
|
||||
|
||||
def set_art(path):
|
||||
detailed.set_art(path)
|
||||
|
||||
def on_play():
|
||||
tiny.on_play()
|
||||
detailed.on_play()
|
||||
|
|
|
@ -57,6 +57,9 @@ action.show()
|
|||
detailed.set_action_widget(action, gtk.PACK_END)
|
||||
detailed.append_page(nowplaying.page, nowplaying.label)
|
||||
|
||||
def set_art(path):
|
||||
nowplaying.set_art(path)
|
||||
|
||||
def update_pos(time):
|
||||
slider_update(slider)
|
||||
cur_pos.set_text(time)
|
||||
|
|
|
@ -3,10 +3,14 @@
|
|||
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)
|
||||
|
@ -46,6 +50,16 @@ page.pack_start(buttons, False, False)
|
|||
page.show_all()
|
||||
label.show()
|
||||
|
||||
sa_id = None
|
||||
def resize_art(*args):
|
||||
set_art(ARTWORK.path)
|
||||
page.disconnect(sa_id)
|
||||
sa_id = page.connect("size-allocate", resize_art)
|
||||
|
||||
def set_art(path):
|
||||
height = page.get_allocation().height
|
||||
ARTWORK.set_image(path, height)
|
||||
|
||||
def on_like():
|
||||
like = controls.get_like()
|
||||
button.toggle_unconnect(LIKE)
|
||||
|
|
149
ocarina/body/image.py
Normal file
149
ocarina/body/image.py
Normal file
|
@ -0,0 +1,149 @@
|
|||
# Bryan Schumaker (04 / 23 / 2011)
|
||||
|
||||
import gtk
|
||||
|
||||
def find_new_width(buf, new_h):
|
||||
w = buf.get_width()
|
||||
h = buf.get_height()
|
||||
if new_h == 0:
|
||||
return
|
||||
if h == new_h:
|
||||
return
|
||||
if h == 0:
|
||||
h = 1
|
||||
return (float(w) / float(h)) * new_h
|
||||
|
||||
def resize(img, new_h):
|
||||
buf = img.get_pixbuf()
|
||||
if buf == None:
|
||||
return
|
||||
new_w = find_new_width(buf, new_h)
|
||||
if new_w == None:
|
||||
return
|
||||
buf = buf.scale_simple(int(new_w), int(new_h), gtk.gdk.INTERP_HYPER)
|
||||
if buf == None:
|
||||
return
|
||||
img.set_from_pixbuf(buf)
|
||||
|
||||
|
||||
class Image(gtk.Image):
|
||||
def __init__(self):
|
||||
gtk.Image.__init__(self)
|
||||
self.path = None
|
||||
self.show()
|
||||
|
||||
def set_image(self, path, height):
|
||||
if path != None:
|
||||
self.path = path
|
||||
self.set_from_file(path)
|
||||
resize(self, height)
|
||||
|
||||
|
||||
#import libsaria
|
||||
#import gtk
|
||||
#gdk = gtk.gdk
|
||||
|
||||
#sources = libsaria.sources
|
||||
#from libsaria import threads
|
||||
|
||||
#lock = threads.get_mutex("album_art")
|
||||
|
||||
#class Image(gtk.Image):
|
||||
#def __init__(self):
|
||||
#gtk.Image.__init__(self)
|
||||
#self.show()
|
||||
|
||||
#def set_height(self, new_h):
|
||||
#buf = self.get_pixbuf()
|
||||
#if buf == None:
|
||||
#return False
|
||||
#w = buf.get_width()
|
||||
#h = buf.get_height()
|
||||
#if h == new_h:
|
||||
#return False
|
||||
#if h == 0:
|
||||
#h = 1
|
||||
#new_w = (float(w) / float(h)) * new_h
|
||||
#if new_w <= 0 or new_h <= 0:
|
||||
#return False
|
||||
|
||||
#buf = buf.scale_simple(int(new_w), int(new_h), gtk.gdk.INTERP_HYPER)
|
||||
#if buf == None:
|
||||
#return False
|
||||
#self.set_from_pixbuf(buf)
|
||||
#return True
|
||||
|
||||
|
||||
#class AlbumArtImage(Image):
|
||||
#def __init__(self, size):
|
||||
#Image.__init__(self)
|
||||
#self.size = size
|
||||
#self.file = None
|
||||
#self.set("images/ocarina.png")
|
||||
#self.set_has_tooltip(True)
|
||||
#self.connect("query-tooltip", self.tooltip)
|
||||
#self.connect("button-press-event", self.clicked)
|
||||
#libsaria.event.invite("PRELOAD", self.preload)
|
||||
#libsaria.event.invite("POSTGETART", self.set)
|
||||
#libsaria.event.invite("POSTSETART", self.set_locked)
|
||||
|
||||
#def preload(self, *args):
|
||||
#self.file = "images/ocarina.png"
|
||||
|
||||
#def clicked(self, widget, event):
|
||||
#print widget, event
|
||||
|
||||
#def tooltip(self, image, x, y, keyboard, tip):
|
||||
#image = gtk.Image()
|
||||
#image.set_from_file(self.file)
|
||||
#tip.set_icon(image.get_pixbuf())
|
||||
#return True
|
||||
|
||||
#def set(self, file=None):
|
||||
#gdk.threads_enter()
|
||||
#self.set_locked(file)
|
||||
#gdk.threads_leave()
|
||||
|
||||
#def set_locked(self, file=None):
|
||||
#for i in xrange(2):
|
||||
#self.file = file
|
||||
#try:
|
||||
#self.set_from_file(self.file)
|
||||
#if self.set_height(self.size) == True:
|
||||
#break
|
||||
#except:
|
||||
#pass
|
||||
#file = "images/ocarina.png"
|
||||
|
||||
#def set_height(self, new_h):
|
||||
#size = self.size_request()
|
||||
#if size[1] == new_h:
|
||||
#return
|
||||
#return Image.set_height(self, new_h)
|
||||
|
||||
|
||||
#class AlbumArt(gtk.EventBox):
|
||||
#def __init__(self, size=64):
|
||||
#gtk.EventBox.__init__(self)
|
||||
#self.image = AlbumArtImage(size)
|
||||
#self.add(self.image)
|
||||
#self.connect("button-press-event", self.clicked)
|
||||
#self.show_all()
|
||||
|
||||
#def clicked(self, widget, event):
|
||||
#if event.button != 1:
|
||||
#return
|
||||
#if sources.get_attrs("id") == -1:
|
||||
#return
|
||||
#from ocarina import fsselect
|
||||
#path = fsselect.file("Select an image")
|
||||
#if path == None:
|
||||
#return
|
||||
#print "Selected file: %s" % path
|
||||
#try:
|
||||
##self.image.set(path)
|
||||
#sources.library.set_attr(sources.cur_lib_id, "art", path)
|
||||
#except Exception, e:
|
||||
#print e
|
||||
#pass
|
||||
|
|
@ -28,3 +28,10 @@ invite("POSTLOAD", on_load)
|
|||
def on_like(*args):
|
||||
footer.on_like()
|
||||
invite("POSTSETLIKE", on_like)
|
||||
|
||||
def on_getart(path, id):
|
||||
cur_id = libsaria.sources.get_attrs("id")
|
||||
if id != cur_id:
|
||||
path = "images/ocarina.png"
|
||||
footer.set_art(path)
|
||||
invite("POSTGETART", on_getart)
|
||||
|
|
Loading…
Reference in New Issue
Block a user