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.
This commit is contained in:
Bryan Schumaker 2010-11-03 22:15:03 -04:00
parent 3ed0b10aab
commit 5839190bb4
1 changed files with 15 additions and 9 deletions

View File

@ -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)