Commits

Anonymous committed 3fa9f89

Added pygame2.examples documentation.
Added pygame2.sdlext examples (moved examples around).
Fixed pygame2.examples package data installation.

  • Participants
  • Parent commits f3d6c8e
  • Branches pgreloaded

Comments (0)

Files changed (15)

 	@echo "  linkcheck to check all external links for integrity"
 
 docclean:
-	-rm -rf sphinx/build *~ *.pyc *.orig ref
+	-rm -rf sphinx/build *~ *.pyc *.orig ref/pygame2_*
 	-rm -f builddarwin.rst buildmingw.rst buildunix.rst buildvc.rst
 	-rm -f newmodules.rst module_faq.rst news.rst
 
    :maxdepth: 2
 
    ref/pygame2_base.rst
+   ref/examples.rst
    ref/pygame2_font.rst
    ref/pygame2_freetype_base.rst
    ref/pygame2_mask.rst

doc/ref/examples.rst

+:mod:`pygame2.examples` -- examples for Pygame2
+===============================================
+
+Examples package for Pygame2.
+
+This package contains code snippets demonstrating the aspects of the
+various Pygame2 modules. Each example is an module of its own and can be
+easily executed using ::
+
+    python -m pygame2.examples.<module>.<example>
+
+To run the drawing pygame2.sdlext example, you would type ::
+
+    python -m pygame2.examples.sdlext.draw
+
+Currently the following examples exists:
+
++------------------------------------+----------------------------------------+
+| Example                            | Description                            |
++====================================+========================================+
+| pygame2.examples.import            | Simple import example for all Pygame2  |
+|                                    | modules.                               |
++------------------------------------+----------------------------------------+
+| pygame2.examples.py2exe_setup      | Win32 standalone executable creation   |
+|                                    | example using Pygame2.                 |
++------------------------------------+----------------------------------------+
+| pygame2.examples.physics.simple    | Simple physics example                 |
++------------------------------------+----------------------------------------+
+| pygame2.examples.sdl.cdrom         | Demonstrates the features of the       |
+|                                    | :mod:`pygame2.sdl.cdrom` module.       |
++------------------------------------+----------------------------------------+
+| pygame2.examples.sdl.hello_world   | The almighty "Hello World" example     |
+|                                    | using the :mod:`pygame2.sdl` module.   |
++------------------------------------+----------------------------------------+
+| pygame2.examples.sdl.keyboard      | Demonstrates keyboard input and event  |
+|                                    | handling for the                       |
+|                                    | :mod:`pygame2.sdl.keyboard` module.    |
++------------------------------------+----------------------------------------+
+| pygame2.examples.sdl.mouse         | Demonstrates mouse input and event     |
+|                                    | handling for the                       |
+|                                    | :mod:`pygame2.sdl.mouse` module.       |
++------------------------------------+----------------------------------------+
+| pygame2.examples.sdl.surface_blit  | Demonstrates supported blitting        |
+|                                    | operations for                         |
+|                                    | :class:`pygame2.sdl.video.Surface`     |
+|                                    | objects.                               |
++------------------------------------+----------------------------------------+
+| pygame2.examples.sdl.surface_fill  | Demonstrates supported filling         |
+|                                    | operations for                         |
+|                                    | :class:`pygame2.sdl.video.Surface`     |
+|                                    | objects.                               |
++------------------------------------+----------------------------------------+
+| pygame2.examples.sdlext.draw       | Demonstrates the features of the       |
+|                                    | :mod:`pygame2.sdlext.draw` module.     |
++------------------------------------+----------------------------------------+
+| pygame2.examples.sdlext.pixelarray | Demonstrates the features of the       |
+|                                    | :class:`pygame2.sdlext.PixelArray`     |
+|                                    | class.                                 |
++------------------------------------+----------------------------------------+

examples/__init__.py

+"""Examples package for Pygame2.
+
+This package contains code snippets demonstrating the aspects of the
+various Pygame2 modules. Each example is an module of its own and can be
+easily executed using
+
+    python -m pygame2.examples.<module>.<example>
+
+To run the drawing pygame2.sdlext example, you would type
+
+    python -m pygame2.examples.sdlext.draw
+
+"""

examples/physics/__init__.py

+"""Examples for pygame2.physics."""

examples/py2exe_setup.py

 import os, py2exe
 import pygame2
 
-# This will include the necessary pygame2 DLL dependencies, that are available.
-# By default they will be taken from the pygame2.dll module directory.
-#
-# If you have your own SDL.dll, SDL_mixer.dll, ... to ship, remove the line
-# below.
-os.environ['PATH'] += ";%s" % pygame2.DLLPATH
+def run ():
+    # This will include the necessary pygame2 DLL dependencies, that are
+    # available. By default they will be taken from the pygame2.dll
+    # module directory.
+    #
+    # If you have your own SDL.dll, SDL_mixer.dll, ... to ship, remove
+    # the line below.
+    os.environ['PATH'] += ";%s" % pygame2.DLLPATH
 
-# ALWAYS include pygame2.sdl.rwops if you are using some pygame2.sdl or related
-# module that can load or save files or file-like objects. Otherwise it might
-# happen that pygame2.sdl.rwops is not included in the final exe/Library.zip,
-# which in turn causes the application to fail badly.
+    # ALWAYS include pygame2.sdl.rwops if you are using some pygame2.sdl
+    # or related module that can load or save files or file-like
+    # objects. Otherwise it might happen that pygame2.sdl.rwops is not
+    # included in the final exe/Library.zip, which in turn causes the
+    # application to fail badly.
 
-setup (windows = [os.path.join ('sdl', 'hello_world.py')], 
-       options = { "py2exe" : { "bundle_files" : 1,
-                   "compressed" : 1,
-                   "includes" : [ "pygame2.sdl.rwops" ] }
-                 },
-       data_files = [ ('.', ["sdl/logo.gif"]), ('.', ["sdl/logo.bmp"]) ]
-)
+    setup (windows = [os.path.join ('sdl', 'hello_world.py')], 
+           options = { "py2exe" : { "bundle_files" : 1,
+                                    "compressed" : 1,
+                                    "includes" : [ "pygame2.sdl.rwops" ] }
+                       },
+           data_files = [ ('.', ["sdl/logo.gif"]), ('.', ["sdl/logo.bmp"]) ]
+           )
+
+if __name__ == "__main__":
+    run ()

examples/sdl/__init__.py

+"""Examples for pygame2.sdl."""

examples/sdl/array.bmp

Removed
Old image

examples/sdl/draw.py

-import sys
-import pygame2
-try:
-    import pygame2.sdl.constants as sdlconst
-    import pygame2.sdl.event as event
-    import pygame2.sdl.video as video
-    import pygame2.sdlext.draw as draw
-except ImportError:
-    print ("No pygame2.sdl support")
-    sys.exit ()
-
-white = pygame2.Color (255, 255, 255)
-black = pygame2.Color (0, 0, 0)
-red = pygame2.Color (255, 0, 0)
-green = pygame2.Color (0, 255, 0)
-blue = pygame2.Color (0, 0, 255)
-
-def draw_rect (screen):
-    draw.rect (screen, black, pygame2.Rect (20, 20, 100, 100))
-    draw.rect (screen, red, pygame2.Rect (160, 100, 160, 60))
-    draw.rect (screen, green, pygame2.Rect (180, 190, 180, 200))
-    draw.rect (screen, blue, pygame2.Rect (390, 120, 200, 140))
-
-def draw_circle (screen):
-    draw.circle (screen, black, (100, 100), 50)
-    draw.circle (screen, red, (200, 160), 80, 4)
-    draw.circle (screen, green, (370, 210), 100, 12)
-    draw.circle (screen, blue, (400, 400), 45, 40)
-
-def draw_arc (screen):
-    draw.arc (screen, black, pygame2.Rect (80, 100, 100, 100), 0, 30)
-
-def run ():
-    drawtypes = [ draw_rect, draw_circle, draw_arc ]
-    curtype = 0
-    video.init ()
-
-    screen = video.set_mode (640, 480)
-    screen.fill (white)
-    draw_rect (screen)
-    screen.flip ()
-
-    okay = True
-    while okay:
-        for ev in event.get ():
-            if ev.type == sdlconst.QUIT:
-                okay = False
-            if ev.type == sdlconst.KEYDOWN and ev.key == sdlconst.K_ESCAPE:
-                okay = False
-            if ev.type == sdlconst.MOUSEBUTTONDOWN:
-                curtype += 1
-                if curtype >= len (drawtypes):
-                    curtype = 0
-                screen.fill (white)
-                drawtypes[curtype] (screen)
-                screen.flip ()
-    video.quit ()
-
-if __name__ == "__main__":
-    run ()

examples/sdl/pixelarray.py

-import sys, os
-import pygame2
-try:
-    import pygame2.sdl.constants as sdlconst
-    import pygame2.sdl.event as event
-    import pygame2.sdl.video as video
-    import pygame2.sdl.wm as wm
-    import pygame2.sdl.image as image
-    from pygame2.sdlext import PixelArray
-except ImportError:
-    print ("No pygame2.sdl support")
-    sys.exit ()
-
-white = pygame2.Color (255, 255, 255)
-black = pygame2.Color (0, 0, 0)
-red = pygame2.Color (255, 0, 0)
-green = pygame2.Color (0, 255, 0)
-blue = pygame2.Color (0, 0, 255)
-
-redt = pygame2.Color (255, 0, 0, 75)
-greent = pygame2.Color (0, 255, 0, 75)
-bluet = pygame2.Color (0, 0, 255, 75)
-
-def draw_checked (screen):
-    wm.set_caption ("Manipulating every second pixel in every second row")
-    pxarray = PixelArray (screen)
-    pxarray[::2,::2] = white
-    del pxarray
-
-def draw_striped (screen):
-    wm.set_caption ("Manipulating every third column")
-    pxarray = PixelArray (screen)
-    pxarray[::3] = white
-    del pxarray
-
-def draw_flipped (screen):
-    wm.set_caption ("Flipping around x and y")
-    pxarray = PixelArray (screen)
-    pxarray[:] = pxarray[::-1, ::-1]
-    del pxarray
-
-def draw_mixed (screen):
-    wm.set_caption ("Manipulating parts")
-    pxarray = PixelArray (screen)
-    pxarray[::2, :120:2] = pxarray[-1, -1]
-    pxarray[::6, 120::] = red
-    del pxarray
-
-def draw_zoomed (screen):
-    wm.set_caption ("2x zoom")
-    pxarray = PixelArray (screen)
-    
-    # Temporary array.
-    sf = video.Surface (640, 480, 32)
-    tmparray = PixelArray (sf)
-    tmparray[::2, ::2] = pxarray[:]
-    tmparray[1::2, ::2] = pxarray[:-1]
-    tmparray[:, 1::2] = tmparray[:, :-1:2]
-    
-    pxarray[:] = tmparray[80:400, 80:320]
-    del tmparray
-    del sf
-    del pxarray
-
-def draw_replaced (screen):
-    wm.set_caption ("Replacing colors")
-    pxarray = PixelArray (screen)
-    pxarray.replace (black, white, 0.06)
-    pxarray.replace (red, green, 0)
-    del pxarray
-    
-def draw_extracted (screen):
-    wm.set_caption ("Extracting colors (black, exact match)")
-    pxarray = PixelArray (screen)
-    pxarray[:] = pxarray.extract (black, 0)
-    del pxarray
-
-def draw_extracted2 (screen):
-    wm.set_caption ("Extracting colors (black, 50% match)")
-    pxarray = PixelArray (screen)
-    pxarray[:] = pxarray.extract (black, 0.5)
-    del pxarray
-
-def run ():
-    methods = [ draw_checked, draw_striped, draw_flipped, draw_mixed,
-                draw_zoomed, draw_replaced, draw_extracted, draw_extracted2]
-    curmethod = -1
-    
-    video.init ()
-    screen = video.set_mode (320, 240, 32)
-    screen.fill (black)
-    
-    imgdir = os.path.dirname (os.path.abspath (__file__))
-    surface = image.load_bmp (os.path.join (imgdir, "array.bmp"))
-    surface = surface.convert (flags=sdlconst.SRCALPHA)
-    screen.blit (surface)
-    screen.flip ()
-
-    okay = True
-    while okay:
-        for ev in event.get ():
-            if ev.type == sdlconst.QUIT:
-                okay = False
-            if ev.type == sdlconst.KEYDOWN and ev.key == sdlconst.K_ESCAPE:
-                okay = False
-            if ev.type == sdlconst.MOUSEBUTTONDOWN:
-                curmethod += 1
-                if curmethod >= len (methods):
-                    curmethod = 0
-                screen.fill (black)
-                screen.blit (surface)
-                methods[curmethod](screen)
-                screen.flip ()
-    video.quit ()
-
-if __name__ == "__main__":
-    run ()

examples/sdlext/__init__.py

+"""Examples for pygame2.sdlext."""

examples/sdlext/array.bmp

Added
New image

examples/sdlext/draw.py

+import sys
+import pygame2
+try:
+    import pygame2.sdl.constants as sdlconst
+    import pygame2.sdl.event as event
+    import pygame2.sdl.video as video
+    import pygame2.sdlext.draw as draw
+except ImportError:
+    print ("No pygame2.sdl support")
+    sys.exit ()
+
+white = pygame2.Color (255, 255, 255)
+black = pygame2.Color (0, 0, 0)
+red = pygame2.Color (255, 0, 0)
+green = pygame2.Color (0, 255, 0)
+blue = pygame2.Color (0, 0, 255)
+
+def draw_rect (screen):
+    draw.rect (screen, black, pygame2.Rect (20, 20, 100, 100))
+    draw.rect (screen, red, pygame2.Rect (160, 100, 160, 60))
+    draw.rect (screen, green, pygame2.Rect (180, 190, 180, 200))
+    draw.rect (screen, blue, pygame2.Rect (390, 120, 200, 140))
+
+def draw_circle (screen):
+    draw.circle (screen, black, (100, 100), 50)
+    draw.circle (screen, red, (200, 160), 80, 4)
+    draw.circle (screen, green, (370, 210), 100, 12)
+    draw.circle (screen, blue, (400, 400), 45, 40)
+
+def draw_arc (screen):
+    draw.arc (screen, black, pygame2.Rect (80, 100, 100, 100), 0, 30)
+
+def run ():
+    drawtypes = [ draw_rect, draw_circle, draw_arc ]
+    curtype = 0
+    video.init ()
+
+    screen = video.set_mode (640, 480)
+    screen.fill (white)
+    draw_rect (screen)
+    screen.flip ()
+
+    okay = True
+    while okay:
+        for ev in event.get ():
+            if ev.type == sdlconst.QUIT:
+                okay = False
+            if ev.type == sdlconst.KEYDOWN and ev.key == sdlconst.K_ESCAPE:
+                okay = False
+            if ev.type == sdlconst.MOUSEBUTTONDOWN:
+                curtype += 1
+                if curtype >= len (drawtypes):
+                    curtype = 0
+                screen.fill (white)
+                drawtypes[curtype] (screen)
+                screen.flip ()
+    video.quit ()
+
+if __name__ == "__main__":
+    run ()

examples/sdlext/pixelarray.py

+import sys, os
+import pygame2
+try:
+    import pygame2.sdl.constants as sdlconst
+    import pygame2.sdl.event as event
+    import pygame2.sdl.video as video
+    import pygame2.sdl.wm as wm
+    import pygame2.sdl.image as image
+    from pygame2.sdlext import PixelArray
+except ImportError:
+    print ("No pygame2.sdl support")
+    sys.exit ()
+
+white = pygame2.Color (255, 255, 255)
+black = pygame2.Color (0, 0, 0)
+red = pygame2.Color (255, 0, 0)
+green = pygame2.Color (0, 255, 0)
+blue = pygame2.Color (0, 0, 255)
+
+redt = pygame2.Color (255, 0, 0, 75)
+greent = pygame2.Color (0, 255, 0, 75)
+bluet = pygame2.Color (0, 0, 255, 75)
+
+def draw_checked (screen):
+    wm.set_caption ("Manipulating every second pixel in every second row")
+    pxarray = PixelArray (screen)
+    pxarray[::2,::2] = white
+    del pxarray
+
+def draw_striped (screen):
+    wm.set_caption ("Manipulating every third column")
+    pxarray = PixelArray (screen)
+    pxarray[::3] = white
+    del pxarray
+
+def draw_flipped (screen):
+    wm.set_caption ("Flipping around x and y")
+    pxarray = PixelArray (screen)
+    pxarray[:] = pxarray[::-1, ::-1]
+    del pxarray
+
+def draw_mixed (screen):
+    wm.set_caption ("Manipulating parts")
+    pxarray = PixelArray (screen)
+    pxarray[::2, :120:2] = pxarray[-1, -1]
+    pxarray[::6, 120::] = red
+    del pxarray
+
+def draw_zoomed (screen):
+    wm.set_caption ("2x zoom")
+    pxarray = PixelArray (screen)
+    
+    # Temporary array.
+    sf = video.Surface (640, 480, 32)
+    tmparray = PixelArray (sf)
+    tmparray[::2, ::2] = pxarray[:]
+    tmparray[1::2, ::2] = pxarray[:-1]
+    tmparray[:, 1::2] = tmparray[:, :-1:2]
+    
+    pxarray[:] = tmparray[80:400, 80:320]
+    del tmparray
+    del sf
+    del pxarray
+
+def draw_replaced (screen):
+    wm.set_caption ("Replacing colors")
+    pxarray = PixelArray (screen)
+    pxarray.replace (black, white, 0.06)
+    pxarray.replace (red, green, 0)
+    del pxarray
+    
+def draw_extracted (screen):
+    wm.set_caption ("Extracting colors (black, exact match)")
+    pxarray = PixelArray (screen)
+    pxarray[:] = pxarray.extract (black, 0)
+    del pxarray
+
+def draw_extracted2 (screen):
+    wm.set_caption ("Extracting colors (black, 50% match)")
+    pxarray = PixelArray (screen)
+    pxarray[:] = pxarray.extract (black, 0.5)
+    del pxarray
+
+def run ():
+    methods = [ draw_checked, draw_striped, draw_flipped, draw_mixed,
+                draw_zoomed, draw_replaced, draw_extracted, draw_extracted2]
+    curmethod = -1
+    
+    video.init ()
+    screen = video.set_mode (320, 240, 32)
+    screen.fill (black)
+    
+    imgdir = os.path.dirname (os.path.abspath (__file__))
+    surface = image.load_bmp (os.path.join (imgdir, "array.bmp"))
+    surface = surface.convert (flags=sdlconst.SRCALPHA)
+    screen.blit (surface)
+    screen.flip ()
+
+    okay = True
+    while okay:
+        for ev in event.get ():
+            if ev.type == sdlconst.QUIT:
+                okay = False
+            if ev.type == sdlconst.KEYDOWN and ev.key == sdlconst.K_ESCAPE:
+                okay = False
+            if ev.type == sdlconst.MOUSEBUTTONDOWN:
+                curmethod += 1
+                if curmethod >= len (methods):
+                    curmethod = 0
+                screen.fill (black)
+                screen.blit (surface)
+                methods[curmethod](screen)
+                screen.flip ()
+    video.quit ()
+
+if __name__ == "__main__":
+    run ()
         files[:] = [f for f in files if nofilesrev.match(f[-1::-1]) is None \
                     and f not in excludefiles]
         subd = subd.replace (directory, "", 1)
-        subd.lstrip (os.path.sep)
+        subd = subd.lstrip (os.path.sep)
         for f in files:
             pkgdata.append (os.path.join (subd, f))
     return pkgdata
                  "pygame2.examples",
                  "pygame2.examples.physics",
                  "pygame2.examples.sdl",
+                 "pygame2.examples.sdlext",
                  "pygame2.sprite",
                  "pygame2.threads",
                  "pygame2.test",