changeset 150:0090ecf08544

Use blank placeholder for missing images
author Neil Muller <drnlmuller@gmail.com>
date Fri, 11 May 2012 17:17:44 +0200
parents e49f2dba0ad4
children 372d886f9e70
files gamelib/gui.py
diffstat 1 files changed, 12 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/gamelib/gui.py	Fri May 11 17:13:28 2012 +0200
+++ b/gamelib/gui.py	Fri May 11 17:17:44 2012 +0200
@@ -1,3 +1,5 @@
+import pygame
+
 from gamelib import data
 from gamelib.gui_base import Drawable, TextButton, font_auto, ToggleButton
 
@@ -34,8 +36,12 @@
 
     def __init__(self, pos, name):
         rect = (pos[0], pos[1], self.WIDTH, self.HEIGHT)
-        n_icon = data.load_image('images/icons/%s_normal.png' % name)
-        d_icon = data.load_image('images/icons/%s_down.png' % name)
+        try:
+            n_icon = data.load_image('images/icons/%s_normal.png' % name)
+            d_icon = data.load_image('images/icons/%s_down.png' % name)
+        except:
+            n_icon = pygame.Surface((64, 64), pygame.SRCALPHA)
+            d_icon = pygame.Surface((64, 64), pygame.SRCALPHA)
         n = ImageDrawable(rect, self.BG_IMAGE_NORMAL.copy())
         n.image.blit(n_icon, (0, 0))
         d = ImageDrawable(rect, self.BG_IMAGE_DOWN.copy())
@@ -62,7 +68,10 @@
 
     def _mk_image(self, name, suffix):
         bg = data.load_image('images/button_%s.png' % (suffix,))
-        icon = data.load_image('images/icons/%s_%s.png' % (name, suffix))
+        try:
+            icon = data.load_image('images/icons/%s_%s.png' % (name, suffix))
+        except pygame.error:
+            icon = pygame.Surface((64, 64), pygame.SRCALPHA)
         drawable = ImageDrawable((0, 0, self.WIDTH, self.HEIGHT), bg.copy())
         drawable.image.blit(icon, (0, 0))
         return drawable