From 5839190bb4e4ae41b4ef04be5309cf5bd22f216b Mon Sep 17 00:00:00 2001 From: Bryan Schumaker Date: Wed, 3 Nov 2010 22:15:03 -0400 Subject: [PATCH] Image.set_height() should return True or False If set_height() returns False, we know something went wrong and that we should try again using the default image. --- ocarina/image.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/ocarina/image.py b/ocarina/image.py index 951ed9d3..129786a1 100644 --- a/ocarina/image.py +++ b/ocarina/image.py @@ -15,18 +15,22 @@ class Image(gtk.Image): def set_height(self, new_h): buf = self.get_pixbuf() if buf == None: - return + return False w = buf.get_width() h = buf.get_height() if h == new_h: - return + return False if h == 0: h = 1 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) + 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): @@ -42,14 +46,16 @@ class AlbumArt(Image): def set(self, file=None): gdk.threads_enter() - if file != None: + for i in xrange(2): self.file = file - self.set_from_file(self.file) - self.set_height(64) + 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 - Image.set_height(self, new_h) + return Image.set_height(self, new_h)