ocarina/image.py

This adds two new classes.  Image() inherits from a gtk.Image, and adds
set_height(x) to scale an image so it is x pixels high.  AlbumArt()
inherits from Image, and will display the album art of the currently
playing song.
This commit is contained in:
Bryan Schumaker 2010-10-26 22:45:59 -04:00
parent 3a81afdc92
commit ba90106588
1 changed files with 49 additions and 0 deletions

49
ocarina/image.py Normal file
View File

@ -0,0 +1,49 @@
# Bryan Schumaker (10/24/2010)
import libsaria
import gtk
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
w = buf.get_width()
h = buf.get_height()
if h == new_h:
return
new_w = (float(w) / float(h)) * new_h
if new_w>0 and new_h>0:
buf = buf.scale_simple(int(new_w), int(new_h), gtk.gdk.INTERP_HYPER)
self.set_from_pixbuf(buf)
class AlbumArt(Image):
def __init__(self):
Image.__init__(self)
self.hide()
self.file = None
libsaria.event.invite("PRELOAD", self.preload)
libsaria.event.invite("POSTGETART", self.set)
def preload(self, *args):
self.hide()
def set(self, file=None):
if file != None:
self.file = file
if self.file != None:
self.set_from_file(self.file)
self.set_height(64)
self.show()
else:
self.hide()
def set_height(self, new_h):
size = self.size_request()
if size[1] == new_h:
return
Image.set_height(self, new_h)