From ba901065883ef19d4536f35e9838049a44cc30cb Mon Sep 17 00:00:00 2001 From: Bryan Schumaker Date: Tue, 26 Oct 2010 22:45:59 -0400 Subject: [PATCH] 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. --- ocarina/image.py | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 ocarina/image.py diff --git a/ocarina/image.py b/ocarina/image.py new file mode 100644 index 00000000..b5ad48d5 --- /dev/null +++ b/ocarina/image.py @@ -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)