Commits

Marcus von Appen committed db2e3b5

- fixed issue #12: remove confusing try/except on import
- follow PEP8 more closely

Comments (0)

Files changed (12)

doc/tutorial/pong.rst

 to close the window and exit the game. ::
 
     import sys
-
     import sdl2
     import sdl2.ext
 

examples/colorpalettes.py

 """A simple example for filling rectangular areas."""
 import sys
 
-try:
-    # Try to import SDL2. The import might fail, if the SDL2 DLL could not be
-    # loaded. In that case, just print the error and exit with a proper
-    # error code.
-    from sdl2 import SDL_QUIT, SDL_MOUSEBUTTONDOWN
-    import sdl2.ext as sdl2ext
-    # Import the pre-defined color palettes
-    import sdl2.ext.colorpalettes as colorpalettes
-except ImportError:
-    import traceback
-    traceback.print_exc()
-    sys.exit(1)
+import sdl2
+import sdl2.ext
+import sdl2.ext.colorpalettes
 
 
 # This function will draw the passed palette colors onto the window surface.
     # Fill the entire surface with a black color. This is done by simply
     # passing a 0 value to the fill argument. We could also create a
     # Color(0, 0, 0) instance here, but this would be the same.
-    sdl2ext.fill(surface, 0)
+    sdl2.ext.fill(surface, 0)
 
     # Calculate the average width (roughly cut) to be used for each palette
     # value. When running the example, you will notice a black gap on the
     # surface. Instead, the provided area makes sure, that we only fill a
     # certain part.
     for color in palette:
-        sdl2ext.fill(surface, color, rect)
+        sdl2.ext.fill(surface, color, rect)
         rect[0] += rw
 
 
 def run():
     # You know those from the helloworld.py example.
     # Initialize the video subsystem, create a window and make it visible.
-    sdl2ext.init()
-    window = sdl2ext.Window("Color Palettes", size=(800, 600))
+    sdl2.ext.init()
+    window = sdl2.ext.Window("Color Palettes", size=(800, 600))
     window.show()
 
     # Explicitly acquire the window's surface to draw on. We used the
     # A simple mapping table for the builtin color palettes. We will use
     # the table to look up the color palette to draw an the title to set below.
     palettes = (
-        ("Mono Palette", colorpalettes.MONOPALETTE),
-        ("2-bit Gray Palette", colorpalettes.GRAY2PALETTE),
-        ("4-bit Gray Palette", colorpalettes.GRAY4PALETTE),
-        ("8-bit Gray Palette", colorpalettes.GRAY8PALETTE),
-        ("3-bit RGB Palette", colorpalettes.RGB3PALETTE),
-        ("CGA Palette", colorpalettes.CGAPALETTE),
-        ("EGA Palette", colorpalettes.EGAPALETTE),
-        ("VGA Palette", colorpalettes.VGAPALETTE),
-        ("Web Palette", colorpalettes.WEBPALETTE),
+        ("Mono Palette", sdl2.ext.colorpalettes.MONOPALETTE),
+        ("2-bit Gray Palette", sdl2.ext.colorpalettes.GRAY2PALETTE),
+        ("4-bit Gray Palette", sdl2.ext.colorpalettes.GRAY4PALETTE),
+        ("8-bit Gray Palette", sdl2.ext.colorpalettes.GRAY8PALETTE),
+        ("3-bit RGB Palette", sdl2.ext.colorpalettes.RGB3PALETTE),
+        ("CGA Palette", sdl2.ext.colorpalettes.CGAPALETTE),
+        ("EGA Palette", sdl2.ext.colorpalettes.EGAPALETTE),
+        ("VGA Palette", sdl2.ext.colorpalettes.VGAPALETTE),
+        ("Web Palette", sdl2.ext.colorpalettes.WEBPALETTE),
         )
 
     # A storage variable for the palette we are currently on, so that we know
         # This will check for any events that piled up since the last check.
         # If one or multiple events were  found (such as a click, a mouse
         # movement, keyboard input, etc.), we will retrieve them.
-        events = sdl2ext.get_events()
+        events = sdl2.ext.get_events()
 
         # In case there was no event, we do not need to do anything. This
         # might happen, if  e.g. the user works with another application. Since
             # application, just as you are used to closing an editor.
             # If the user wants to quit the application, we should let him do
             # so. This is done by breaking out of the while loop.
-            if event.type == SDL_QUIT:
+            if event.type == sdl2.SDL_QUIT:
                 running = False
                 break
 
             # type, the user pressed the mouse button, but did not necesarily
             # release  it. As such, it is not a typical click, but only 50% of
             # it, which is sufficient for our case here.
-            if event.type == SDL_MOUSEBUTTONDOWN:
+            if event.type == sdl2.SDL_MOUSEBUTTONDOWN:
                 # If the user pressed the button, we want to draw the next
                 # palette and update the window title accordingly. We do this
                 # by increasing the storage variable and - in case it reached
         # Comment this line out to see what happens!
         window.refresh()
 
-    # As for helloworld.py, we have to call sdl2ext.quit(), since we also
-    # called sdl2ext.init().
-    sdl2ext.quit()
+    # As for helloworld.py, we have to call sdl2.ext.quit(), since we also
+    # called sdl2.ext.init().
+    sdl2.ext.quit()
     return 0
 
 
 """2D drawing examples."""
 import sys
 from random import randint
-
-# Try to import SDL2. The import might fail, if the SDL2 DLL could not be
-# loaded. In that case, just print the error and exit with a proper
-# error code.
-try:
-    from sdl2 import SDL_QUIT, SDL_MOUSEBUTTONDOWN
-    import sdl2.ext as sdl2ext
-except ImportError:
-    import traceback
-    traceback.print_exc()
-    sys.exit(1)
-
+import sdl2
+import sdl2.ext
 
 # Draws random lines on the passed surface
 def draw_lines(surface, width, height):
     # Fill the whole surface with a black color.
-    sdl2ext.fill(surface, 0)
+    sdl2.ext.fill(surface, 0)
     for x in range(15):
         # Create a set of four random points for drawing the line.
         x1, x2 = randint(0, width), randint(0, width)
         y1, y2 = randint(0, height), randint(0, height)
         # Create a random color.
-        color = sdl2ext.Color(randint(0, 255),
-                              randint(0, 255),
-                              randint(0, 255))
+        color = sdl2.ext.Color(randint(0, 255),
+                               randint(0, 255),
+                               randint(0, 255))
         # Draw the line with the specified color on the surface.
         # We also could create a set of points to be passed to the function
         # in the form
         # line(surface, color, (x1, y1, x2, y2, x3, y3, x4, y4, ...))
         #                       ^^^^^^^^^^^^^^  ^^^^^^^^^^^^^^
         #                         first line     second line
-        sdl2ext.line(surface, color, (x1, y1, x2, y2))
+        sdl2.ext.line(surface, color, (x1, y1, x2, y2))
 
 
 # Draws random, filled rectangles on the passed surface
 def draw_rects(surface, width, height):
     # Fill the whole surface with a black color.
-    sdl2ext.fill(surface, 0)
+    sdl2.ext.fill(surface, 0)
     for k in range(15):
         # Create a set of four random points for the edges of the rectangle.
         x, y = randint(0, width), randint(0, height)
         w, h = randint(1, width // 2), randint(1, height // 2)
         # Create a random color.
-        color = sdl2ext.Color(randint(0, 255),
-                              randint(0, 255),
-                              randint(0, 255))
+        color = sdl2.ext.Color(randint(0, 255),
+                               randint(0, 255),
+                               randint(0, 255))
         # Draw the filled rect with the specified color on the surface.
         # We also could create a set of points to be passed to the function
         # in the form
         # fill(surface, color, ((x1, y1, x2, y2), (x3, y3, x4, y4), ...))
         #                        ^^^^^^^^^^^^^^    ^^^^^^^^^^^^^^
         #                          first rect        second rect
-        sdl2ext.fill(surface, color, (x, y, w, h))
+        sdl2.ext.fill(surface, color, (x, y, w, h))
 
 
 def run():
     # You know those from the helloworld.py example.
     # Initialize the video subsystem, create a window and make it visible.
-    sdl2ext.init()
-    window = sdl2ext.Window("2D drawing primitives", size=(800, 600))
+    sdl2.ext.init()
+    window = sdl2.ext.Window("2D drawing primitives", size=(800, 600))
     window.show()
 
     # As in colorpalettes.py, explicitly acquire the window's surface to
     # detailled description.
     running = True
     while running:
-        events = sdl2ext.get_events()
+        events = sdl2.ext.get_events()
         for event in events:
-            if event.type == SDL_QUIT:
+            if event.type == sdl2.SDL_QUIT:
                 running = False
                 break
-            if event.type == SDL_MOUSEBUTTONDOWN:
+            if event.type == sdl2.SDL_MOUSEBUTTONDOWN:
                 curindex += 1
                 if curindex >= len(functions):
                     curindex = 0
                 func(*args)
                 break
         window.refresh()
-    sdl2ext.quit()
+    sdl2.ext.quit()
     return 0
 
 

examples/gfxdrawing.py

 import ctypes
 from random import randint
 
-# Try to import SDL2 and SDL2_gfx. The import might fail, if either of the
-# libraries could not be loaded. In that case, just print the error and exit
-# with a proper error code.
-try:
-    from sdl2 import SDL_QUIT, SDL_MOUSEBUTTONDOWN, Sint16
-    import sdl2.sdlgfx as sdlgfx
-    import sdl2.ext as sdl2ext
-except ImportError:
-    import traceback
-    traceback.print_exc()
-    sys.exit(1)
+import sdl2
+import sdl2.sdlgfx
+import sdl2.ext
 
 
 # Draws random lines using the passed rendering context
     lw = 5
     x0, x1 = whalf, whalf
     y0, y1 = 0, height
-    sdlgfx.thickLineColor(context.renderer, x0, y0, x1, y1, lw, 0xFFFFFFFF)
+    sdl2.sdlgfx.thickLineColor(context.renderer, x0, y0, x1, y1, lw,
+                               0xFFFFFFFF)
     x0, x1 = 0, width
     y0, y1 = hhalf, hhalf
-    sdlgfx.thickLineColor(context.renderer, x0, y0, x1, y1, lw, 0xFFFFFFFF)
+    sdl2.sdlgfx.thickLineColor(context.renderer, x0, y0, x1, y1, lw,
+                               0xFFFFFFFF)
     for x in range(15):
         # In the first quadrant, draw normal lines
         color = randint(0, 0xFFFFFFFF)
         x0, x1 = randint(0, whalf), randint(0, whalf)
         y0, y1 = randint(0, hhalf), randint(0, hhalf)
-        sdlgfx.lineColor(context.renderer, x0, y0, x1, y1, color)
+        sdl2.sdlgfx.lineColor(context.renderer, x0, y0, x1, y1, color)
         # In the second quadrant, draw aa lines
         color = randint(0, 0xFFFFFFFF)
         x0, x1 = randint(whalf + lw, width), randint(whalf + lw, width)
         y0, y1 = randint(0, hhalf), randint(0, hhalf)
-        sdlgfx.aalineColor(context.renderer, x0, y0, x1, y1, color)
+        sdl2.sdlgfx.aalineColor(context.renderer, x0, y0, x1, y1, color)
         # In the third quadrant, draw horizontal lines
         color = randint(0, 0xFFFFFFFF)
         x0, x1 = randint(0, whalf), randint(0, whalf)
         y0 = randint(hhalf + lw, height)
-        sdlgfx.hlineColor(context.renderer, x0, x1, y0, color)
+        sdl2.sdlgfx.hlineColor(context.renderer, x0, x1, y0, color)
         # In the fourth quadrant, draw vertical lines
         color = randint(0, 0xFFFFFFFF)
         x0 = randint(whalf + lw, width)
         y0, y1 = randint(hhalf + lw, height), randint(hhalf + lw, height)
-        sdlgfx.vlineColor(context.renderer, x0, y0, y1, color)
+        sdl2.sdlgfx.vlineColor(context.renderer, x0, y0, y1, color)
 
 
 # Draws random circles using the passed rendering context
     # Split the visible area
     wthird = width // 3 - 1
     lw = 3
-    sdlgfx.thickLineColor(context.renderer, wthird, 0, wthird, height, lw,
-                          0xFFFFFFFF)
-    sdlgfx.thickLineColor(context.renderer, (2 * wthird + lw), 0,
-                          (2 * wthird + lw), height, lw, 0xFFFFFFFF)
+    sdl2.sdlgfx.thickLineColor(context.renderer, wthird, 0, wthird, height,
+                               lw, 0xFFFFFFFF)
+    sdl2.sdlgfx.thickLineColor(context.renderer, (2 * wthird + lw), 0,
+                               (2 * wthird + lw), height, lw, 0xFFFFFFFF)
     for x in range(15):
         # In the first part, draw circles
         color = randint(0, 0xFFFFFFFF)
         x, y = randint(0, wthird), randint(0, height)
         r = randint(1, max(min(x, wthird - x), 2))
-        sdlgfx.circleColor(context.renderer, x, y, r, color)
+        sdl2.sdlgfx.circleColor(context.renderer, x, y, r, color)
         # In the second part, draw aa circles
         color = randint(0, 0xFFFFFFFF)
         x, y = randint(0, wthird), randint(0, height)
         r = randint(1, max(min(x, wthird - x), 2))
-        sdlgfx.aacircleColor(context.renderer, x + wthird + lw, y, r, color)
+        sdl2.sdlgfx.aacircleColor(context.renderer, x + wthird + lw, y, r,
+                                  color)
         # In the third part, draw filled circles
         color = randint(0, 0xFFFFFFFF)
         x, y = randint(0, wthird), randint(0, height)
         r = randint(1, max(min(x, wthird - x), 2))
-        sdlgfx.filledCircleColor(context.renderer, x + 2 * (wthird + lw), y, r,
-                                 color)
+        sdl2.sdlgfx.filledCircleColor(context.renderer, x + 2 * (wthird + lw),
+                                      y, r, color)
 
 
 # Draws random ellipsis using the passed rendering context
     wthird = width // 3 - 1
     eheight = height // 4
     lw = 3
-    sdlgfx.thickLineColor(context.renderer, wthird, 0, wthird, height, lw,
-                          0xFFFFFFFF)
-    sdlgfx.thickLineColor(context.renderer, (2 * wthird + lw), 0,
-                          (2 * wthird + lw), height, lw, 0xFFFFFFFF)
+    sdl2.sdlgfx.thickLineColor(context.renderer, wthird, 0, wthird, height,
+                               lw, 0xFFFFFFFF)
+    sdl2.sdlgfx.thickLineColor(context.renderer, (2 * wthird + lw), 0,
+                               (2 * wthird + lw), height, lw, 0xFFFFFFFF)
     for x in range(15):
         # In the first part, draw ellipsis
         color = randint(0, 0xFFFFFFFF)
         x, y = randint(0, wthird), randint(0, height)
         rx, ry = randint(1, max(min(x, wthird - x), 2)), randint(0, eheight)
-        sdlgfx.ellipseColor(context.renderer, x, y, rx, ry, color)
+        sdl2.sdlgfx.ellipseColor(context.renderer, x, y, rx, ry, color)
         # In the second part, draw aa ellipsis
         color = randint(0, 0xFFFFFFFF)
         x, y = randint(0, wthird), randint(0, height)
         rx, ry = randint(1, max(min(x, wthird - x), 2)), randint(0, eheight)
-        sdlgfx.aaellipseColor(context.renderer, x + wthird + lw, y, rx, ry,
-                              color)
+        sdl2.sdlgfx.aaellipseColor(context.renderer, x + wthird + lw, y,
+                                   rx, ry, color)
         # In the third part, draw filled ellipsis
         color = randint(0, 0xFFFFFFFF)
         x, y = randint(0, wthird), randint(0, height)
         rx, ry = randint(1, max(min(x, wthird - x), 2)), randint(0, eheight)
-        sdlgfx.filledEllipseColor(context.renderer, x + 2 * (wthird + lw), y,
-                                  rx, ry, color)
+        sdl2.sdlgfx.filledEllipseColor(context.renderer,
+                                       x + 2 * (wthird + lw), y, rx, ry,
+                                       color)
 
 
 # Draws random rectangles using the passed rendering context
     lw = 5
     x0, x1 = whalf, whalf
     y0, y1 = 0, height
-    sdlgfx.thickLineColor(context.renderer, x0, y0, x1, y1, lw, 0xFFFFFFFF)
+    sdl2.sdlgfx.thickLineColor(context.renderer, x0, y0, x1, y1, lw,
+                               0xFFFFFFFF)
     x0, x1 = 0, width
     y0, y1 = hhalf, hhalf
-    sdlgfx.thickLineColor(context.renderer, x0, y0, x1, y1, lw, 0xFFFFFFFF)
+    sdl2.sdlgfx.thickLineColor(context.renderer, x0, y0, x1, y1, lw,
+                               0xFFFFFFFF)
     for x in range(15):
         # In the first quadrant, draw normal rectangles
         color = randint(0, 0xFFFFFFFF)
         x0, x1 = randint(0, whalf), randint(0, whalf)
         y0, y1 = randint(0, hhalf), randint(0, hhalf)
-        sdlgfx.rectangleColor(context.renderer, x0, y0, x1, y1, color)
+        sdl2.sdlgfx.rectangleColor(context.renderer, x0, y0, x1, y1, color)
         # In the second quadrant, draw rounded rectangles
         color = randint(0, 0xFFFFFFFF)
         x0, x1 = randint(whalf + lw, width), randint(whalf + lw, width)
         y0, y1 = randint(0, hhalf), randint(0, hhalf)
         r = randint(0, max(x1 - x0, x0 - x1))
-        sdlgfx.roundedRectangleColor(context.renderer, x0, y0, x1, y1, r,
-                                     color)
+        sdl2.sdlgfx.roundedRectangleColor(context.renderer, x0, y0, x1, y1, r,
+                                          color)
         # In the third quadrant, draw horizontal lines
         color = randint(0, 0xFFFFFFFF)
         x0, x1 = randint(0, whalf), randint(0, whalf)
         y0, y1 = randint(hhalf + lw, height), randint(hhalf + lw, height)
-        sdlgfx.boxColor(context.renderer, x0, y0, x1, y1, color)
+        sdl2.sdlgfx.boxColor(context.renderer, x0, y0, x1, y1, color)
         # In the fourth quadrant, draw vertical lines
         color = randint(0, 0xFFFFFFFF)
         x0, x1 = randint(whalf + lw, width), randint(whalf + lw, width)
         y0, y1 = randint(hhalf + lw, height), randint(hhalf + lw, height)
         r = randint(1, max(x1 - x0, x0 - x1))
-        sdlgfx.roundedBoxColor(context.renderer, x0, y0, x1, y1, r, color)
+        sdl2.sdlgfx.roundedBoxColor(context.renderer, x0, y0, x1, y1, r,
+                                    color)
 
 
 # Draws random triangles using the passed rendering context
     # Split the visible area
     wthird = width // 3 - 1
     lw = 3
-    sdlgfx.thickLineColor(context.renderer, wthird, 0, wthird, height, lw,
-                          0xFFFFFFFF)
-    sdlgfx.thickLineColor(context.renderer, (2 * wthird + lw), 0,
-                          (2 * wthird + lw), height, lw, 0xFFFFFFFF)
+    sdl2.sdlgfx.thickLineColor(context.renderer, wthird, 0, wthird, height,
+                               lw, 0xFFFFFFFF)
+    sdl2.sdlgfx.thickLineColor(context.renderer, (2 * wthird + lw), 0,
+                               (2 * wthird + lw), height, lw, 0xFFFFFFFF)
     for x in range(15):
         # In the first part, draw triangles
         color = randint(0, 0xFFFFFFFF)
         x0, y0 = randint(0, wthird), randint(0, height)
         x1, y1 = randint(0, wthird), randint(0, height)
         x2, y2 = randint(0, wthird), randint(0, height)
-        sdlgfx.trigonColor(context.renderer, x0, y0, x1, y1, x2, y2, color)
+        sdl2.sdlgfx.trigonColor(context.renderer, x0, y0, x1, y1, x2, y2,
+                                color)
         # In the second part, draw aa triangles
         color = randint(0, 0xFFFFFFFF)
         x0, y0 = randint(0, wthird) + wthird + lw, randint(0, height)
         x1, y1 = randint(0, wthird) + wthird + lw, randint(0, height)
         x2, y2 = randint(0, wthird) + wthird + lw, randint(0, height)
-        sdlgfx.aatrigonColor(context.renderer, x0, y0, x1, y1, x2, y2, color)
+        sdl2.sdlgfx.aatrigonColor(context.renderer, x0, y0, x1, y1, x2, y2,
+                                  color)
         # In the third part, draw filled triangles
         color = randint(0, 0xFFFFFFFF)
         x0, y0 = randint(0, wthird) + 2 * (wthird + lw), randint(0, height)
         x1, y1 = randint(0, wthird) + 2 * (wthird + lw), randint(0, height)
         x2, y2 = randint(0, wthird) + 2 * (wthird + lw), randint(0, height)
-        sdlgfx.filledTrigonColor(context.renderer, x0, y0, x1, y1, x2, y2,
-                                 color)
+        sdl2.sdlgfx.filledTrigonColor(context.renderer, x0, y0, x1, y1,
+                                      x2, y2, color)
 
 
 # Draws random polygons using the passed rendering context
     # Split the visible area
     wthird = width // 3 - 1
     lw = 3
-    sdlgfx.thickLineColor(context.renderer, wthird, 0, wthird, height, lw,
-                          0xFFFFFFFF)
-    sdlgfx.thickLineColor(context.renderer, (2 * wthird + lw), 0,
-                          (2 * wthird + lw), height, lw, 0xFFFFFFFF)
+    sdl2.sdlgfx.thickLineColor(context.renderer, wthird, 0, wthird, height,
+                               lw, 0xFFFFFFFF)
+    sdl2.sdlgfx.thickLineColor(context.renderer, (2 * wthird + lw), 0,
+                               (2 * wthird + lw), height, lw, 0xFFFFFFFF)
     for x in range(5):
         # In the first part, draw polygons
         color = randint(0, 0xFFFFFFFF)
         ptcount = randint(3, 10)
-        xlist, ylist = (Sint16 * ptcount)(), (Sint16 * ptcount)()
+        xlist, ylist = (sdl2.Sint16 * ptcount)(), (sdl2.Sint16 * ptcount)()
         for k in range(ptcount):
             xlist[k] = randint(0, wthird)
             ylist[k] = randint(0, height)
-        xptr = ctypes.cast(xlist, ctypes.POINTER(Sint16))
-        yptr = ctypes.cast(ylist, ctypes.POINTER(Sint16))
-        sdlgfx.polygonColor(context.renderer, xptr, yptr, ptcount, color)
+        xptr = ctypes.cast(xlist, ctypes.POINTER(sdl2.Sint16))
+        yptr = ctypes.cast(ylist, ctypes.POINTER(sdl2.Sint16))
+        sdl2.sdlgfx.polygonColor(context.renderer, xptr, yptr, ptcount, color)
         # In the second part, draw aa polygons
         color = randint(0, 0xFFFFFFFF)
         ptcount = randint(3, 10)
-        xlist, ylist = (Sint16 * ptcount)(), (Sint16 * ptcount)()
+        xlist, ylist = (sdl2.Sint16 * ptcount)(), (sdl2.Sint16 * ptcount)()
         for k in range(ptcount):
             xlist[k] = randint(0, wthird) + wthird + lw
             ylist[k] = randint(0, height)
-        xptr = ctypes.cast(xlist, ctypes.POINTER(Sint16))
-        yptr = ctypes.cast(ylist, ctypes.POINTER(Sint16))
-        sdlgfx.aapolygonColor(context.renderer, xptr, yptr, ptcount, color)
+        xptr = ctypes.cast(xlist, ctypes.POINTER(sdl2.Sint16))
+        yptr = ctypes.cast(ylist, ctypes.POINTER(sdl2.Sint16))
+        sdl2.sdlgfx.aapolygonColor(context.renderer, xptr, yptr, ptcount,
+                                   color)
         # In the third part, draw filled polygons
         color = randint(0, 0xFFFFFFFF)
         ptcount = randint(3, 10)
-        xlist, ylist = (Sint16 * ptcount)(), (Sint16 * ptcount)()
+        xlist, ylist = (sdl2.Sint16 * ptcount)(), (sdl2.Sint16 * ptcount)()
         for k in range(ptcount):
             xlist[k] = randint(0, wthird) + 2 * (wthird + lw)
             ylist[k] = randint(0, height)
-        xptr = ctypes.cast(xlist, ctypes.POINTER(Sint16))
-        yptr = ctypes.cast(ylist, ctypes.POINTER(Sint16))
-        sdlgfx.filledPolygonColor(context.renderer, xptr, yptr, ptcount, color)
+        xptr = ctypes.cast(xlist, ctypes.POINTER(sdl2.Sint16))
+        yptr = ctypes.cast(ylist, ctypes.POINTER(sdl2.Sint16))
+        sdl2.sdlgfx.filledPolygonColor(context.renderer, xptr, yptr, ptcount,
+                                       color)
 
 
 # Draw random elements using the passed rendering context
     lw = 5
     x0, x1 = whalf, whalf
     y0, y1 = 0, height
-    sdlgfx.thickLineColor(context.renderer, x0, y0, x1, y1, lw, 0xFFFFFFFF)
+    sdl2.sdlgfx.thickLineColor(context.renderer, x0, y0, x1, y1, lw,
+                               0xFFFFFFFF)
     x0, x1 = 0, width
     y0, y1 = hhalf, hhalf
-    sdlgfx.thickLineColor(context.renderer, x0, y0, x1, y1, lw, 0xFFFFFFFF)
+    sdl2.sdlgfx.thickLineColor(context.renderer, x0, y0, x1, y1, lw,
+                               0xFFFFFFFF)
     for x in range(15):
         # In the first quadrant, draw arcs
         color = randint(0, 0xFFFFFFFF)
         x0, y0 = randint(0, whalf), randint(0, hhalf)
         rad = randint(0, min(whalf - x0, hhalf - y0))
         start, end = randint(0, 360), randint(0, 360)
-        sdlgfx.arcColor(context.renderer, x0, y0, rad, start, end, color)
+        sdl2.sdlgfx.arcColor(context.renderer, x0, y0, rad, start, end, color)
         # In the second quadrant, draw bezier curves
         color = randint(0, 0xFFFFFFFF)
         ptcount = randint(3, 10)
-        xlist, ylist = (Sint16 * ptcount)(), (Sint16 * ptcount)()
+        xlist, ylist = (sdl2.Sint16 * ptcount)(), (sdl2.Sint16 * ptcount)()
         for k in range(ptcount):
             xlist[k] = randint(whalf, width)
             ylist[k] = randint(0, hhalf)
         steps = randint(2, 10)
-        xptr = ctypes.cast(xlist, ctypes.POINTER(Sint16))
-        yptr = ctypes.cast(ylist, ctypes.POINTER(Sint16))
-        sdlgfx.bezierColor(context.renderer, xptr, yptr, ptcount, steps, color)
+        xptr = ctypes.cast(xlist, ctypes.POINTER(sdl2.Sint16))
+        yptr = ctypes.cast(ylist, ctypes.POINTER(sdl2.Sint16))
+        sdl2.sdlgfx.bezierColor(context.renderer, xptr, yptr, ptcount, steps,
+                                color)
         # In the third quadrant, draw pies
         color = randint(0, 0xFFFFFFFF)
         x0, y0 = randint(0, whalf), randint(hhalf + lw, height)
         rad = randint(0, min(whalf - x0, y0 - (hhalf + lw)))
         start, end = randint(0, 360), randint(0, 360)
-        sdlgfx.pieColor(context.renderer, x0, y0, rad, start, end, color)
+        sdl2.sdlgfx.pieColor(context.renderer, x0, y0, rad, start, end, color)
         # In the fourth quadrant, draw filled pies
         color = randint(0, 0xFFFFFFFF)
         x0, y0 = randint(whalf + lw, width), randint(hhalf + lw, height)
         rad = randint(0, min(x0 - (whalf + lw), y0 - (hhalf + lw)))
         start, end = randint(0, 360), randint(0, 360)
-        sdlgfx.filledPieColor(context.renderer, x0, y0, rad, start, end, color)
+        sdl2.sdlgfx.filledPieColor(context.renderer, x0, y0, rad, start, end,
+                                   color)
 
 
 def run():
     # You know those from the helloworld.py example.
     # Initialize the video subsystem, create a window and make it visible.
-    sdl2ext.init()
-    window = sdl2ext.Window("sdlgfx drawing examples", size=(800, 600))
+    sdl2.ext.init()
+    window = sdl2.ext.Window("sdlgfx drawing examples", size=(800, 600))
     window.show()
 
     # Create a rendering context for the window. The sdlgfx module requires it.
-    context = sdl2ext.RenderContext(window)
+    context = sdl2.ext.RenderContext(window)
 
     # We implement the functionality as it was done in colorpalettes.py and
     # utilise a mapping table to look up the function to be executed, together
     # detailed description.
     running = True
     while running:
-        events = sdl2ext.get_events()
+        events = sdl2.ext.get_events()
         for event in events:
-            if event.type == SDL_QUIT:
+            if event.type == sdl2.SDL_QUIT:
                 running = False
                 break
-            if event.type == SDL_MOUSEBUTTONDOWN:
+            if event.type == sdl2.SDL_MOUSEBUTTONDOWN:
                 curindex += 1
                 if curindex >= len(functions):
                     curindex = 0
                 func(*args)
                 break
         context.present()
-    sdl2ext.quit()
+    sdl2.ext.quit()
     return 0
 
 
 """User interface examples."""
 import sys
-from sdl2.events import SDL_TEXTINPUT
-
-# Try to import SDL2. The import might fail, if the SDL2 DLL could not be
-# loaded. In that case, just print the error and exit with a proper
-# error code.
-try:
-    from sdl2 import SDL_QUIT
-    import sdl2.ext as sdl2ext
-except ImportError:
-    import traceback
-    traceback.print_exc()
-    sys.exit(1)
-
+import sdl2
+import sdl2.ext
 
 # Define some global color constants
-WHITE = sdl2ext.Color(255, 255, 255)
-GREY = sdl2ext.Color(200, 200, 200)
-RED = sdl2ext.Color(255, 0, 0)
-GREEN = sdl2ext.Color(0, 255, 0)
+WHITE = sdl2.ext.Color(255, 255, 255)
+GREY = sdl2.ext.Color(200, 200, 200)
+RED = sdl2.ext.Color(255, 0, 0)
+GREEN = sdl2.ext.Color(0, 255, 0)
 
 # Create a resource, so we have easy access to the example images.
-RESOURCES = sdl2ext.Resources(__file__, "resources")
+RESOURCES = sdl2.ext.Resources(__file__, "resources")
 
 
 # A callback for the Button.motion event.
         color = GREEN
     else:
         color = RED
-    if button.factory.sprite_type == sdl2ext.SOFTWARE:
-        sdl2ext.fill(button.surface, color)
+    if button.factory.sprite_type == sdl2.ext.SOFTWARE:
+        sdl2.ext.fill(button.surface, color)
     else:
         # SDL textures do not support color manipulation operation as easy
         # as software surface (since the texture is ideally stored somwhere
 def run():
     # You know those from the helloworld.py example.
     # Initialize the video subsystem, create a window and make it visible.
-    sdl2ext.init()
-    window = sdl2ext.Window("UI Elements", size=(800, 600))
+    sdl2.ext.init()
+    window = sdl2.ext.Window("UI Elements", size=(800, 600))
     window.show()
 
     # Create a sprite factory that allows us to create visible 2D elements
     # (or SDL_Renderer), which will create the underlying textures for us.
     if "-hardware" in sys.argv:
         print("Using hardware acceleration")
-        renderer = sdl2ext.RenderContext(window)
-        factory = sdl2ext.SpriteFactory(sdl2ext.TEXTURE, renderer=renderer)
+        renderer = sdl2.ext.RenderContext(window)
+        factory = sdl2.ext.SpriteFactory(sdl2.ext.TEXTURE, renderer=renderer)
     else:
         print("Using software rendering")
-        factory = sdl2ext.SpriteFactory(sdl2ext.SOFTWARE)
+        factory = sdl2.ext.SpriteFactory(sdl2.ext.SOFTWARE)
 
     # Create a UI factory, which will handle several defaults for
     # us. Also, the UIFactory can utilises software-based UI elements as
     # well as hardware-accelerated ones; this allows us to keep the UI
     # creation code clean.
-    uifactory = sdl2ext.UIFactory(factory)
+    uifactory = sdl2.ext.UIFactory(factory)
 
     # Create a simple Button sprite, which reacts on mouse movements and
     # button presses and fill it with a white color. All UI elements
     # inherit directly from the TextureSprite (for TEXTURE) or SoftwareSprite
     # (for SOFTWARE), so everything you can do with those classes is also
     # possible for the UI elements.
-    button = uifactory.from_image(sdl2ext.BUTTON,
+    button = uifactory.from_image(sdl2.ext.BUTTON,
                                    RESOURCES.get_path("button.bmp"))
     button.position = 50, 50
 
     # Create a TextEntry sprite, which reacts on keyboard presses and
     # text input.
-    entry = uifactory.from_image(sdl2ext.TEXTENTRY,
+    entry = uifactory.from_image(sdl2.ext.TEXTENTRY,
                                  RESOURCES.get_path("textentry.bmp"))
     entry.position = 50, 200
 
     # Create a CheckButton sprite. The CheckButton is a specialised
     # Button, which can switch its state, identified by the 'checked'
     # attribute by clicking.
-    checkbutton = uifactory.from_color(sdl2ext.CHECKBUTTON, RED, size=(50, 50))
+    checkbutton = uifactory.from_color(sdl2.ext.CHECKBUTTON, RED, size=(50, 50))
     checkbutton.position = 200, 50
 
     # Bind some actions to the button's event handlers. Whenever a click
 
     # Create a new UIProcessor, which will handle the user input events
     # and pass them on to the relevant user interface elements.
-    uiprocessor = sdl2ext.UIProcessor()
+    uiprocessor = sdl2.ext.UIProcessor()
 
     running = True
     while running:
-        events = sdl2ext.get_events()
+        events = sdl2.ext.get_events()
         for event in events:
-            if event.type == SDL_QUIT:
+            if event.type == sdl2.SDL_QUIT:
                 running = False
                 break
             # Pass the SDL2 events to the UIProcessor, which takes care of
         # Render all user interface elements on the window.
         spriterenderer.render((button, entry, checkbutton))
 
-    sdl2ext.quit()
+    sdl2.ext.quit()
     return 0
 
 

examples/helloworld.py

 """The almighty Hello World! example"""
 # We'll use sys to properly exit with an error code.
 import sys
-
-# Try to import the video system. Since sdl2.ext makes use of sdl2, the
-# import might fail, if the SDL DLL could not be loaded. In that case, just
-# print the error and exit with a proper error code.
-try:
-    import sdl2.ext as sdl2ext
-except ImportError:
-    import traceback
-    traceback.print_exc()
-    sys.exit(1)
+import sdl2.ext
 
 # Create a resource container, so that we can easily access all
 # resource, we bundle with our application. We are using the current
 # file's location and define the "resources" subdirectory as the
 # location, in which we keep all data.
-RESOURCES = sdl2ext.Resources(__file__, "resources")
+RESOURCES = sdl2.ext.Resources(__file__, "resources")
 
 
 def run():
     #
     # You SHOULD call this before using any video related methods or
     # classes.
-    sdl2ext.init()
+    sdl2.ext.init()
 
     # Create a new window (like your browser window or editor window,
     # etc.) and give it a meaningful title and size. We definitely need
     # this, if we want to present something to the user.
-    window = sdl2ext.Window("Hello World!", size=(592, 460))
+    window = sdl2.ext.Window("Hello World!", size=(592, 460))
 
     # By default, every Window is hidden, not shown on the screen right
     # after creation. Thus we need to tell it to be shown now.
     # (or SDL_Renderer), which will create the underlying textures for us.
     if "-hardware" in sys.argv:
         print("Using hardware acceleration")
-        renderer = sdl2ext.RenderContext(window)
-        factory = sdl2ext.SpriteFactory(sdl2ext.TEXTURE, renderer=renderer)
+        renderer = sdl2.ext.RenderContext(window)
+        factory = sdl2.ext.SpriteFactory(sdl2.ext.TEXTURE, renderer=renderer)
     else:
         print("Using software rendering")
-        factory = sdl2ext.SpriteFactory(sdl2ext.SOFTWARE)
+        factory = sdl2.ext.SpriteFactory(sdl2.ext.SOFTWARE)
 
     # Creates a simple rendering system for the Window. The
     # SpriteRenderer can draw Sprite objects on the window.
     # testing purposes and does not do anything meaningful.  Take a look
     # at its code to better understand how the event processing can be
     # done and customized!
-    processor = sdl2ext.TestEventProcessor()
+    processor = sdl2.ext.TestEventProcessor()
 
     # Start the event processing. This will run in an endless loop, so
     # everything following after processor.run() will not be executed
 
     # We called video.init(), so we have to call video.quit() as well to
     # release the resources hold by the SDL DLL.
-    sdl2ext.quit()
-
+    sdl2.ext.quit()
+    return 0
 
 if __name__ == "__main__":
     sys.exit(run())

examples/opengl.py

 import sys
 import ctypes
 
-try:
-    from OpenGL import GL, GLU
-    from sdl2 import *
-except ImportError:
-    import traceback
-    traceback.print_exc()
-    sys.exit(1)
-
+from OpenGL import GL, GLU
+import sdl2
 
 def run():
-    if SDL_Init(SDL_INIT_VIDEO) != 0:
-        print(SDL_GetError())
+    if sdl2.SDL_Init(sdl2.SDL_INIT_VIDEO) != 0:
+        print(sdl2.SDL_GetError())
         return -1
 
-    window = SDL_CreateWindow(b"OpenGL demo", SDL_WINDOWPOS_UNDEFINED,
-                              SDL_WINDOWPOS_UNDEFINED, 800, 600,
-                              SDL_WINDOW_OPENGL)
+    window = sdl2.SDL_CreateWindow(b"OpenGL demo",
+                                   sdl2.SDL_WINDOWPOS_UNDEFINED,
+                                   sdl2.SDL_WINDOWPOS_UNDEFINED, 800, 600,
+                                   sdl2.SDL_WINDOW_OPENGL)
     if not window:
-        print(SDL_GetError())
+        print(sdl2.SDL_GetError())
         return -1
 
-    context = SDL_GL_CreateContext(window)
+    context = sdl2.SDL_GL_CreateContext(window)
 
     GL.glMatrixMode(GL.GL_PROJECTION | GL.GL_MODELVIEW)
     GL.glLoadIdentity()
     x = 0.0
     y = 30.0
 
-    event = SDL_Event()
+    event = sdl2.SDL_Event()
     running = True
     while running:
-        while SDL_PollEvent(ctypes.byref(event)) != 0:
-            if event.type == SDL_QUIT:
+        while sdl2.SDL_PollEvent(ctypes.byref(event)) != 0:
+            if event.type == sdl2.SDL_QUIT:
                 running = False
 
         GL.glClearColor(0, 0, 0, 1)
         GL.glVertex2f(x - 90.0, y - 90.0)
         GL.glEnd()
 
-        SDL_GL_SwapWindow(window)
-        SDL_Delay(10)
-    SDL_GL_DeleteContext(context)
-    SDL_DestroyWindow(window)
-    SDL_Quit()
+        sdl2.SDL_GL_SwapWindow(window)
+        sdl2.SDL_Delay(10)
+    sdl2.SDL_GL_DeleteContext(context)
+    sdl2.SDL_DestroyWindow(window)
+    sdl2.SDL_Quit()
     return 0
 
 if __name__ == "__main__":

examples/particles.py

 """Particle simulation"""
 import sys
 import random
-
-# Try to import SDL2. The import might fail, if the SDL2 DLL could
-# not be loaded. In that case, just print the error and exit with a
-# proper error code.
-try:
-    from sdl2 import SDL_QUIT, SDL_MOUSEMOTION, SDL_FlushEvent, SDL_Delay, \
-        SDL_WarpMouseInWindow, SDL_ShowCursor, SDL_Rect, SDL_RenderCopy
-    import sdl2.ext as sdl2ext
-except ImportError:
-    import traceback
-    traceback.print_exc()
-    sys.exit(1)
-
-# Import the particles module, so we have access to all relevant parts
-# for dealing with particles.
-import sdl2.ext.particles as particles
+import sdl2
+import sdl2.ext
+import sdl2.ext.particles
 
 # Create a resource, so we have easy access to the example images.
-RESOURCES = sdl2ext.Resources(__file__, "resources")
+RESOURCES = sdl2.ext.Resources(__file__, "resources")
 
 
 # The Particle class offered by sdl2.ext.particles only contains the life
 # want to flood our world with unused entities. Thus, we store a
 # reference to the entity, the particle belongs to, too. This allows use
 # to remove them easily later on.
-class CParticle(particles.Particle):
+class CParticle(sdl2.ext.particles.Particle):
     def __init__(self, entity, x, y, vx, vy, ptype, life):
         super(CParticle, self).__init__(x, y, life)
         self.entity = entity
 
 # A simple Entity class, that contains the particle information. This
 # represents our living particle object.
-class EParticle(sdl2ext.Entity):
+class EParticle(sdl2.ext.Entity):
     def __init__(self, world, x, y, vx, vy, ptype, life):
         self.cparticle = CParticle(self, x, y, vx, vy, ptype, life)
 
 # Create a simple rendering system for particles. This is somewhat
 # similar to the TextureSprinteRenderer from sdl2.ext. Since we operate on
 # particles rather than sprites, we need to provide our own rendering logic.
-class ParticleRenderer(sdl2ext.System):
+class ParticleRenderer(sdl2.ext.System):
     def __init__(self, renderer, images):
         # Create a new particle renderer. The surface argument will be
         # the targets surface to do the rendering on. images is a set of
         #
         # The SDL_Rect is used for the blit operation below and is used
         # as destination position for rendering the particle.
-        r = SDL_Rect()
+        r = sdl2.SDL_Rect()
 
         # The SDL2 blit function to use. This will take an image
         # (SDL_Texture) as source and copies it on the target.
-        dorender = SDL_RenderCopy
+        dorender = sdl2.SDL_RenderCopy
 
         # And some more shortcuts.
         sdlrenderer = self.renderer.renderer
 
 def run():
     # Create the environment, in which our particles will exist.
-    world = sdl2ext.World()
+    world = sdl2.ext.World()
 
     # Set up the globally available information about the current mouse
     # position. We use that information to determine the emitter
 
     # Create the particle engine. It is just a simple System that uses
     # callback functions to update a set of components.
-    engine = particles.ParticleEngine()
+    engine = sdl2.ext.particles.ParticleEngine()
 
     # Bind the callback functions to the particle engine. The engine
     # does the following on processing:
     createparticles(world, None, 300)
 
     # Initialize the video subsystem, create a window and make it visible.
-    sdl2ext.init()
-    window = sdl2ext.Window("Particles", size=(800, 600))
+    sdl2.ext.init()
+    window = sdl2.ext.Window("Particles", size=(800, 600))
     window.show()
 
     # Create a hardware-accelerated sprite factory. The sprite factory requires
     # a rendering context, which enables it to create the underlying textures
     # that serve as the visual parts for the sprites.
-    renderer = sdl2ext.RenderContext(window)
-    factory = sdl2ext.SpriteFactory(sdl2ext.TEXTURE, renderer=renderer)
+    renderer = sdl2.ext.RenderContext(window)
+    factory = sdl2.ext.SpriteFactory(sdl2.ext.TEXTURE, renderer=renderer)
 
     # Create a set of images to be used as particles on rendering. The
     # images are used by the ParticleRenderer created below.
     # Center the mouse on the window. We use the SDL2 functions directly
     # here. Since the SDL2 functions do not know anything about the
     # sdl2.ext.Window class, we have to pass the window's SDL_Window to it.
-    SDL_WarpMouseInWindow(window.window, world.mousex, world.mousey)
+    sdl2.SDL_WarpMouseInWindow(window.window, world.mousex, world.mousey)
 
     # Hide the mouse cursor, so it does not show up - just show the
     # particles.
-    SDL_ShowCursor(0)
+    sdl2.SDL_ShowCursor(0)
 
     # Create the rendering system for the particles. This is somewhat
     # similar to the SoftSpriteRenderer, but since we only operate with
     # The almighty event loop. You already know several parts of it.
     running = True
     while running:
-        for event in sdl2ext.get_events():
-            if event.type == SDL_QUIT:
+        for event in sdl2.ext.get_events():
+            if event.type == sdl2.SDL_QUIT:
                 running = False
                 break
 
-            if event.type == SDL_MOUSEMOTION:
+            if event.type == sdl2.SDL_MOUSEMOTION:
                 # Take care of the mouse motions here. Every time the
                 # mouse is moved, we will make that information globally
                 # available to our application environment by updating
                 # queue (10ths to 100ths!), and we do not want to handle
                 # each of them. For this example, it is enough to handle
                 # one per update cycle.
-                SDL_FlushEvent(SDL_MOUSEMOTION)
+                sdl2.SDL_FlushEvent(sdl2.SDL_MOUSEMOTION)
                 break
         world.process()
-        SDL_Delay(1)
+        sdl2.SDL_Delay(1)
 
-    sdl2ext.quit()
+    sdl2.ext.quit()
     return 0
 
 if __name__ == "__main__":

examples/pixelaccess.py

 """Direct pixel access examples."""
 import sys
-
-# Try to import SDL2. The import might fail, if the SDL2 DLL could not be
-# loaded. In that case, just print the error and exit with a proper
-# error code.
-try:
-    from sdl2 import SDL_QUIT, SDL_MOUSEBUTTONDOWN
-    import sdl2.ext as sdl2ext
-except ImportError:
-    import traceback
-    traceback.print_exc()
-    sys.exit(1)
+import sdl2
+import sdl2.ext
 
 # Define black and white as global values, so we can access them throughout
 # the code.
-BLACK = sdl2ext.Color(0, 0, 0)
-WHITE = sdl2ext.Color(255, 255, 255)
+BLACK = sdl2.ext.Color(0, 0, 0)
+WHITE = sdl2.ext.Color(255, 255, 255)
 
 
 # This function will use a rectangular area and fill each second horizontal
     # Fill the entire surface with a black color. In contrast to
     # colorpalettes.py we use a Color() value here, just to demonstrate that
     # it really works.
-    sdl2ext.fill(surface, BLACK)
+    sdl2.ext.fill(surface, BLACK)
 
     # Create a 2D view that allows us to directly access each individual pixel
     # of the surface. The PixelView class is quite slow, since it uses an non-
-    # optimised read-write access to each individual pixel and offset. It works
-    # on every platform, though.
-    pixelview = sdl2ext.PixelView(surface)
+    # optimised read-write access to each individual pixel and offset. It
+    # works on every platform, though.
+    pixelview = sdl2.ext.PixelView(surface)
 
     # Loop over the area bounds, considering each fourth line and every column
     # on the 2D view. The PixelView uses a y-x alignment to access pixels.
 
 # as draw_horizontal_stripes(), but vertical
 def draw_vertical_stripes(surface, x1, x2, y1, y2):
-    sdl2ext.fill(surface, BLACK)
-    pixelview = sdl2ext.PixelView(surface)
+    sdl2.ext.fill(surface, BLACK)
+    pixelview = sdl2.ext.PixelView(surface)
     for x in range(x1, x2, 4):
         for y in range(y1, y2):
             pixelview[y][x] = WHITE
 def run():
     # You know those from the helloworld.py example.
     # Initialize the video subsystem, create a window and make it visible.
-    sdl2ext.init()
-    window = sdl2ext.Window("Pixel Access", size=(800, 600))
+    sdl2.ext.init()
+    window = sdl2.ext.Window("Pixel Access", size=(800, 600))
     window.show()
 
     # As in colorpalettes.py, explicitly acquire the window's surface to
     # detailled description.
     running = True
     while running:
-        events = sdl2ext.get_events()
+        events = sdl2.ext.get_events()
         for event in events:
-            if event.type == SDL_QUIT:
+            if event.type == sdl2.SDL_QUIT:
                 running = False
                 break
-            if event.type == SDL_MOUSEBUTTONDOWN:
+            if event.type == sdl2.SDL_MOUSEBUTTONDOWN:
                 curindex += 1
                 if curindex >= len(functions):
                     curindex = 0
                 func(*args)
                 break
         window.refresh()
-    sdl2ext.quit()
+    sdl2.ext.quit()
     return 0
 
 
 """The Pong Game."""
 import sys
+import sdl2
+import sdl2.ext
 
-try:
-    import sdl2.ext as sdl2ext
-    import sdl2.events as sdlevents
-    import sdl2.timer as sdltimer
-    import sdl2.keycode as sdlkc
-except ImportError:
-    import traceback
-    traceback.print_exc()
-    sys.exit(1)
-from sdl2.ext.ebs import Applicator, Entity, World
-
-BLACK = sdl2ext.Color(0, 0, 0)
-WHITE = sdl2ext.Color(255, 255, 255)
+BLACK = sdl2.ext.Color(0, 0, 0)
+WHITE = sdl2.ext.Color(255, 255, 255)
 PADDLE_SPEED = 3
 BALL_SPEED = 3
 
 
-class CollisionSystem(Applicator):
+class CollisionSystem(sdl2.ext.Applicator):
     def __init__(self, minx, miny, maxx, maxy):
         super(CollisionSystem, self).__init__()
-        self.componenttypes = (Velocity, sdl2ext.Sprite)
+        self.componenttypes = Velocity, sdl2.ext.Sprite
         self.ball = None
         self.minx = minx
         self.miny = miny
         left, top, right, bottom = sprite.area
         bleft, btop, bright, bbottom = self.ball.sprite.area
 
-        return bleft < right and bright > left and \
-            btop < bottom and bbottom > top
+        return (bleft < right and bright > left and
+                btop < bottom and bbottom > top)
 
     def process(self, world, componentsets):
         collitems = [comp for comp in componentsets if self._overlap(comp)]
             self.ball.velocity.vx = -self.ball.velocity.vx
 
             sprite = collitems[0][1]
-            ballcentery = self.ball.sprite.y + \
-                self.ball.sprite.size[1] // 2
+            ballcentery = self.ball.sprite.y + self.ball.sprite.size[1] // 2
             halfheight = sprite.size[1] // 2
             stepsize = halfheight // 10
             degrees = 0.7
             else:
                 self.ball.velocity.vy = -self.ball.velocity.vy
 
-        if self.ball.sprite.y <= self.miny or \
-                self.ball.sprite.y + self.ball.sprite.size[1] >= self.maxy:
+        if (self.ball.sprite.y <= self.miny or
+            self.ball.sprite.y + self.ball.sprite.size[1] >= self.maxy):
             self.ball.velocity.vy = -self.ball.velocity.vy
 
-        if self.ball.sprite.x <= self.minx or \
-                self.ball.sprite.x + self.ball.sprite.size[0] >= self.maxx:
+        if (self.ball.sprite.x <= self.minx or
+            self.ball.sprite.x + self.ball.sprite.size[0] >= self.maxx):
             self.ball.velocity.vx = -self.ball.velocity.vx
 
 
-class MovementSystem(Applicator):
+class MovementSystem(sdl2.ext.Applicator):
     def __init__(self, minx, miny, maxx, maxy):
         super(MovementSystem, self).__init__()
-        self.componenttypes = (Velocity, sdl2ext.Sprite)
+        self.componenttypes = Velocity, sdl2.ext.Sprite
         self.minx = minx
         self.miny = miny
         self.maxx = maxx
                 sprite.y = self.maxy - sheight
 
 
-class TrackingAIController(Applicator):
+class TrackingAIController(sdl2.ext.Applicator):
     def __init__(self, miny, maxy):
         super(TrackingAIController, self).__init__()
-        self.componenttypes = (PlayerData, Velocity, sdl2ext.Sprite)
+        self.componenttypes = PlayerData, Velocity, sdl2.ext.Sprite
         self.miny = miny
         self.maxy = maxy
         self.ball = None
                     vel.vy = 0
 
 
-class SoftwareRenderer(sdl2ext.SoftwareSpriteRenderer):
+class SoftwareRenderer(sdl2.ext.SoftwareSpriteRenderer):
     def __init__(self, window):
         super(SoftwareRenderer, self).__init__(window)
 
     def render(self, components):
-        sdl2ext.fill(self.surface, BLACK)
+        sdl2.ext.fill(self.surface, BLACK)
         super(SoftwareRenderer, self).render(components)
 
 
-class TextureRenderer(sdl2ext.TextureSpriteRenderer):
+class TextureRenderer(sdl2.ext.TextureSpriteRenderer):
     def __init__(self, renderer):
         super(TextureRenderer, self).__init__(renderer)
         self.renderer = renderer
         self.points = 0
 
 
-class Player(Entity):
+class Player(sdl2.ext.Entity):
     def __init__(self, world, sprite, posx=0, posy=0, ai=False):
         self.sprite = sprite
         self.sprite.position = posx, posy
         self.playerdata.ai = ai
 
 
-class Ball(Entity):
+class Ball(sdl2.ext.Entity):
     def __init__(self, world, sprite, posx=0, posy=0):
         self.sprite = sprite
         self.sprite.position = posx, posy
 
 
 def run():
-    sdl2ext.init()
-    window = sdl2ext.Window("The Pong Game", size=(800, 600))
+    sdl2.ext.init()
+    window = sdl2.ext.Window("The Pong Game", size=(800, 600))
     window.show()
 
     if "-hardware" in sys.argv:
         print("Using hardware acceleration")
-        renderer = sdl2ext.RenderContext(window)
-        factory = sdl2ext.SpriteFactory(sdl2ext.TEXTURE, renderer=renderer)
+        renderer = sdl2.ext.RenderContext(window)
+        factory = sdl2.ext.SpriteFactory(sdl2.ext.TEXTURE, renderer=renderer)
     else:
         print("Using software rendering")
-        factory = sdl2ext.SpriteFactory(sdl2ext.SOFTWARE)
+        factory = sdl2.ext.SpriteFactory(sdl2.ext.SOFTWARE)
 
     # Create the paddles - we want white ones. To keep it easy enough for us,
     # we create a set of surfaces that can be used for Texture- and
     sp_paddle2 = factory.from_color(WHITE, size=(20, 100))
     sp_ball = factory.from_color(WHITE, size=(20, 20))
 
-    world = World()
+    world = sdl2.ext.World()
 
     movement = MovementSystem(0, 0, 800, 600)
     collision = CollisionSystem(0, 0, 800, 600)
     aicontroller = TrackingAIController(0, 600)
-    if factory.sprite_type == sdl2ext.SOFTWARE:
+    if factory.sprite_type == sdl2.ext.SOFTWARE:
         spriterenderer = SoftwareRenderer(window)
     else:
         spriterenderer = TextureRenderer(renderer)
 
     running = True
     while running:
-        for event in sdl2ext.get_events():
-            if event.type == sdlevents.SDL_QUIT:
+        for event in sdl2.ext.get_events():
+            if event.type == sdl2.SDL_QUIT:
                 running = False
                 break
-            if event.type == sdlevents.SDL_KEYDOWN:
-                if event.key.keysym.sym == sdlkc.SDLK_UP:
+            if event.type == sdl2.SDL_KEYDOWN:
+                if event.key.keysym.sym == sdl2.SDLK_UP:
                     player1.velocity.vy = -PADDLE_SPEED
-                elif event.key.keysym.sym == sdlkc.SDLK_DOWN:
+                elif event.key.keysym.sym == sdl2.SDLK_DOWN:
                     player1.velocity.vy = PADDLE_SPEED
-            elif event.type == sdlevents.SDL_KEYUP:
-                if event.key.keysym.sym in (sdlkc.SDLK_UP, sdlkc.SDLK_DOWN):
+            elif event.type == sdl2.SDL_KEYUP:
+                if event.key.keysym.sym in (sdl2.SDLK_UP, sdl2.SDLK_DOWN):
                     player1.velocity.vy = 0
-        sdltimer.SDL_Delay(10)
+        sdl2.SDL_Delay(10)
         world.process()
 
 

examples/sdl2hello.py

 import os
 import sys
 import ctypes
-
-from sdl2 import *
+import sdl2
 
 
 def run():
-    SDL_Init(SDL_INIT_VIDEO)
-    window = SDL_CreateWindow(b"Hello World",
-                              SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
-                              592, 460, SDL_WINDOW_SHOWN)
+    sdl2.SDL_Init(sdl2.SDL_INIT_VIDEO)
+    window = sdl2.SDL_CreateWindow(b"Hello World",
+                                   sdl2.SDL_WINDOWPOS_CENTERED,
+                                   sdl2.SDL_WINDOWPOS_CENTERED,
+                                   592, 460, sdl2.SDL_WINDOW_SHOWN)
     fname = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                          "resources", "hello.bmp")
-    image = SDL_LoadBMP(fname.encode("utf-8"))
-    windowsurface = SDL_GetWindowSurface(window)
-    SDL_BlitSurface(image, None, windowsurface, None)
-    SDL_UpdateWindowSurface(window)
-    SDL_FreeSurface(image)
+    image = sdl2.SDL_LoadBMP(fname.encode("utf-8"))
+    windowsurface = sdl2.SDL_GetWindowSurface(window)
+    sdl2.SDL_BlitSurface(image, None, windowsurface, None)
+    sdl2.SDL_UpdateWindowSurface(window)
+    sdl2.SDL_FreeSurface(image)
 
     running = True
-    event = SDL_Event()
+    event = sdl2.SDL_Event()
     while running:
-        while SDL_PollEvent(ctypes.byref(event)) != 0:
-            if event.type == SDL_QUIT:
+        while sdl2.SDL_PollEvent(ctypes.byref(event)) != 0:
+            if event.type == sdl2.SDL_QUIT:
                 running = False
                 break
+        sdl2.SDL_Delay(10)
 
-    SDL_DestroyWindow(window)
-    SDL_Quit()
+    sdl2.SDL_DestroyWindow(window)
+    sdl2.SDL_Quit()
     return 0
 
 

sdl2/test/version_test.py

         self.assertEqual(type(v), version.SDL_version)
         self.assertEqual(v.major, 2)
         self.assertEqual(v.minor, 0)
-        self.assertEqual(v.patch, 2)
+        self.assertEqual(v.patch, 3)
 
     def test_SDL_VERSIONNUM(self):
         self.assertEqual(version.SDL_VERSIONNUM(1, 2, 3), 1203)