5839190bb4
If set_height() returns False, we know something went wrong and that we should try again using the default image.
62 lines
1.3 KiB
Python
62 lines
1.3 KiB
Python
# Bryan Schumaker (10/24/2010)
|
|
import libsaria
|
|
import gtk
|
|
gdk = gtk.gdk
|
|
|
|
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 AlbumArt(Image):
|
|
def __init__(self):
|
|
Image.__init__(self)
|
|
self.hide()
|
|
self.file = None
|
|
self.set("images/ocarina.png")
|
|
libsaria.event.invite("PRELOAD", self.preload)
|
|
libsaria.event.invite("POSTGETART", self.set)
|
|
|
|
def preload(self, *args):
|
|
self.file = "images/ocarina.png"
|
|
|
|
def set(self, file=None):
|
|
gdk.threads_enter()
|
|
for i in xrange(2):
|
|
self.file = file
|
|
self.set_from_file(self.file)
|
|
if self.set_height(64) == True:
|
|
break
|
|
file = "images/ocarina.png"
|
|
gdk.threads_leave()
|
|
|
|
def set_height(self, new_h):
|
|
size = self.size_request()
|
|
if size[1] == new_h:
|
|
return
|
|
return Image.set_height(self, new_h)
|