Commits

Marcus von Appen committed a1b919a

- fixed issue #21: sdl2.ext.load_image() raises a proper
UnsupportedError, if neither SDL_image nor PIL are usable
- improved UnsupportedError messages

Comments (0)

Files changed (4)

     top, bottom = clip_rect.y, clip_rect.y + clip_rect.h - 1
 
     if bpp == 3:
-        raise UnsupportedError("24bpp are currently not supported")
+        raise UnsupportedError(line, "24bpp are currently not supported")
     if bpp == 2:
         pxbuf = ctypes.cast(rtarget.pixels, ctypes.POINTER(ctypes.c_uint16))
     elif bpp == 4:
             fillrect(rtarget, varea, color)
             continue
         if width != 1:
-            raise UnsupportedError
+            raise UnsupportedError(line, "width > 1 is not supported")
         if width == 1:
             # Bresenham
             x1, y1, x2, y2 = clipline(left, top, right, bottom, x1, y1, x2, y2)
     """
     def __init__(self, sender, maxprocs=None):
         if not _HASMP:
-            raise UnsupportedError("no multiprocessing support found")
+            raise UnsupportedError(MPEventHandler,
+                                   "no multiprocessing support found")
         super(MPEventHandler, self).__init__(sender)
         self.maxprocs = maxprocs
 
         font size in pixels.
         """
         if not _HASSDLTTF:
-            raise UnsupportedError("FontManager requires sdlttf support")
+            raise UnsupportedError(FontManager,
+                                   "FontManager requires sdlttf support")
         if sdlttf.TTF_WasInit() == 0 and sdlttf.TTF_Init() != 0:
             raise SDLError()
         self.fonts = {}  # fonts = {alias: {size:font_ptr}}
     if enforce is not None and enforce not in ("PIL", "SDL"):
         raise ValueError("enforce must be either 'PIL' or 'SDL', if set")
 
+    if not _HASPIL and not _HASSDLIMAGE:
+        raise UnsupportedError(load_image,
+                               "cannot use PIL or SDL for image loading")
     if enforce == "PIL" and not _HASPIL:
-        raise UnsupportedError("PIL loading")
+        raise UnsupportedError(load_image, "cannot use PIL (not found)")
     if enforce == "SDL" and not _HASSDLIMAGE:
-        raise UnsupportedError("SDL loading")
+        raise UnsupportedError(load_image, "cannot use SDL_image (not found)")
 
     imgsurface = None
     if enforce != "PIL" and _HASSDLIMAGE: