Commits

Anonymous committed c69f501

Started to document sdl.constants. Fixed minor issues with tests.

  • Participants
  • Parent commits 1025c04
  • Branches pgreloaded

Comments (0)

Files changed (6)

    ref/pygame2_physics.rst
    ref/pygame2_sdl.rst
    ref/pygame2_sdl_audio.rst
+   ref/pygame2_sdl_cdrom.rst
+   ref/sdlconstants.rst
    ref/pygame2_sdl_cursors.rst
-   ref/pygame2_sdl_cdrom.rst
    ref/pygame2_sdl_event.rst
    ref/pygame2_sdl_gl.rst
    ref/pygame2_sdl_image.rst

doc/ref/sdlconstants.rst

+:mod:`pygame2.sdl.constants` -- Constants for SDL
+=================================================
+
+This module contains the constants used throughout the :mod:`pygame2.sdl`
+modules.
+
+.. module:: pygame2.sdl.constants
+   :synopsis: Constants used throughout the :mod:`pygame2.sdl` modules.
+
+Blending Constants
+------------------
+
+Those constants are used by the :meth:`pygame2.sdl.video.Surface.blit`
+and :meth:`pygame2.sdl.video.Surface.fill` methods.
+
+.. data:: BLEND_RGB_ADD
+
+   Used for an additive blend, ignoring the per-pixel alpha value.
+
+.. data:: BLEND_RGB_SUB
+
+   Used for an subtractive blend, ignoring the per-pixel alpha value.
+
+.. data:: BLEND_RGB_MULT
+
+   Used for an multiply blend, ignoring the per-pixel alpha value.
+
+.. data:: BLEND_RGB_AND
+
+   Used for a binary AND'd blend, ignoring the per-pixel alpha value.
+
+.. data:: BLEND_RGB_OR
+
+   Used for a binary OR'd  blend, ignoring the per-pixel alpha value.
+
+.. data:: BLEND_RGB_XOR
+
+   Used for a binary XOR'd blend, ignoring the per-pixel alpha value.
+
+.. data:: BLEND_RGB_MIN
+
+   Used for a minimum blend, ignoring the per-pixel alpha value.
+
+.. data:: BLEND_RGB_MAX
+
+   Used for a maximum blend, ignoring the per-pixel alpha value.
+
+.. data:: BLEND_RGB_AVG
+
+   Used for an average blend, ignoring the per-pixel alpha value.
+
+.. data:: BLEND_RGB_DIFF
+
+   Used for a difference blend, ignoring the per-pixel alpha value.
+
+.. data:: BLEND_RGB_SCREEN
+
+   Used for a screen blend, ignoring the per-pixel alpha value.
+
+.. data:: BLEND_RGBA_ADD
+
+   Used for an additive blend, with the per-pixel alpha value.
+
+.. data:: BLEND_RGBA_SUB
+
+   Used for an subtractive blend, with the per-pixel alpha value.
+
+.. data:: BLEND_RGBA_MULT
+
+   Used for an multiply blend, with the per-pixel alpha value.
+
+.. data:: BLEND_RGBA_MIN
+
+   Used for a minimum blend, with the per-pixel alpha value.
+
+.. data:: BLEND_RGBA_MAX
+
+   Used for a maximum blend, with the per-pixel alpha value.
+
+Event Constants
+---------------
+
+Those constants are used by the :mod:`pygame2.sdl.event` module
+functions.
+
+.. data:: ACTIVEEVENT
+   
+   Raised, when the SDL application state changes.
+
+.. data:: KEYDOWN
+
+   Raised, when a key is pressed down.
+
+.. data:: KEYUP
+
+   Raised, when a key is released.
+
+.. data:: MOUSEMOTION
+
+   Raised, when the mouse moves.
+
+.. data:: MOUSEBUTTONDOWN
+
+   Raised, when a mouse button is pressed down.
+
+.. data:: MOUSEBUTTONUP
+   
+   Raised, when a mouse button is released.
+
+.. data:: JOYAXISMOTION
+
+   Raised, when a joystick axis moves.
+
+.. data:: JOYBALLMOTION
+
+   Raised, when a trackball on a joystick moves.
+
+.. data:: JOYHATMOTION
+
+   Raised, when a hat on a joystick moves.
+
+.. data:: JOYBUTTONDOWN
+
+   Raised, when a joystick button is pressed down.
+
+.. data:: JOYBUTTONUP
+
+   Raised, when a joystick button is released.
+
+.. data:: QUIT
+
+   Raised, when the SDL application window shall be closed.
+
+.. data:: SYSWMEVENT
+
+   Raised, when an unknown, window manager specific event occurs.
+
+.. data:: VIDEORESIZE
+
+   Raised, when the SDL application window shall be resized.
+
+.. data:: VIDEOEXPOSE
+
+   Raised, when the screen has been modified outside of the SDL
+   application and the SDL application window needs to be redrawn.
+
+.. data:: USEREVENT
+
+   Raised, when a user-specific event occurs.
+
+
+Application Constants
+---------------------
+
+Those constants are used by the :data:`ACTIVEEVENT` event and the
+:func:`pygame2.sdl.event.get_app_state` method.
+
+.. data:: APPACTIVE
+
+   Indicates that that the SDL application is currently active.
+
+.. data:: APPINPUTFOCUS
+
+   Indicates that the SDL application has the keyboard input focus.
+
+.. data:: APPMOUSEFOCUS
+
+   Indicates that the SDL application has the mouse input focus.

test/sdl_base_test.py

         self.assertEquals (base.init (constants.INIT_CDROM), True)
         self.assertEquals (base.init
                            (constants.INIT_CDROM | constants.INIT_AUDIO), True)
+        base.quit ()
 
     def test_pygame2_sdl_base_init_subsystem(self):
 
         self.assertEquals (base.init_subsystem (constants.INIT_CDROM), True)
         self.assertEquals (base.init_subsystem
                            (constants.INIT_CDROM | constants.INIT_TIMER), True)
+        base.quit ()
 
     def test_pygame2_sdl_base_quit(self):
 
         base.init (constants.INIT_JOYSTICK)
         v = base.was_init (constants.INIT_JOYSTICK) & constants.INIT_JOYSTICK
         self.assert_ (v == constants.INIT_JOYSTICK)
+        base.quit ()
 
 if __name__ == "__main__":
     unittest.main ()

test/sdl_image_test.py

         # creates a pygame2.sdl.video.Surface from it.  Loads a BMP file and
         # creates a pygame2.sdl.video.Surface from it. The file argument can
         # be either a file object or the filename.
+        video.init ()
         imgdir = os.path.dirname (os.path.abspath (__file__))
         sf = image.load_bmp (os.path.join (imgdir, "test.bmp"))
         self.assert_ (sf.size == (16, 16))
+        video.quit ()
 
     def test_pygame2_sdl_image_save_bmp(self):
 
         # save_bmp (surface, file) -> None  Saves a surface to a bitmap file.
         # Saves a pygame2.sdl.video.Surface to the specified file, where file
         # can be a filename or file object.
+        video.init ()
         imgdir = os.path.dirname (os.path.abspath (__file__))
         sf = image.load_bmp (os.path.join (imgdir, "test.bmp"))
         buf = None
         self.assert_ (image.save_bmp (sf, buf) == None)
         self.assertEquals (os.stat (os.path.join (imgdir, "test.bmp")).st_size,
                            len (buf.getvalue ()))
+        video.quit ()
 
 if __name__ == "__main__":
     unittest.main ()

test/sdl_video_surface_test.py

         # Gets or sets the current clipping rectangle for
         # operations on the Surface.
         video.init ()
+        video.quit ()
         self.fail() 
 
     def todo_test_pygame2_sdl_video_Surface_convert(self):
         # 
         # This creates a new, converted surface and leaves the original one
         # untouched.
-        
+        video.init ()
+        video.quit ()
         self.fail() 
 
     def test_pygame2_sdl_video_Surface_copy(self):
         # Gets the (read-only) pygame2.sdl.video.PixelFormat for this
         # Surface.
         video.init ()
+        video.quit ()
         self.fail() 
 
     def todo_test_pygame2_sdl_video_Surface_get_alpha(self):
         # surface does not support alpha transparency (SRCALPHA flag not set),
         # None will be returned.
         video.init ()
+        video.quit ()
         self.fail() 
 
-    def todo_test_pygame2_sdl_video_Surface_get_at(self):
+    def test_pygame2_sdl_video_Surface_get_at(self):
 
         # __doc__ (as of 2009-05-15) for pygame2.sdl.video.Surface.get_at:
 
         # 
         # Gets the Surface pixel value at the specified point.
         video.init ()
-        self.fail() 
+        sf = video.Surface (10, 10)
+
+        color = pygame2.Color (100, 50, 20)
+        sf.fill (color)
+        color = sf.format.get_rgba (color)
+        rect = pygame2.Rect (0, 0, 3, 7)
+        for x in range (10):
+            for y in range (10):
+                rect.topleft = x, y
+                self.assert_ (sf.get_at (x, y) == color)
+                self.assert_ (sf.get_at ((x, y)) == color)
+                self.assert_ (sf.get_at (rect) == color)
+        video.quit ()
 
     def todo_test_pygame2_sdl_video_Surface_get_colorkey(self):
 
         # Gets the colorkey for the Surface or None in case it has no colorkey
         # (SRCCOLORKEY flag not set).
         video.init ()
+        video.quit ()
         self.fail() 
 
     def todo_test_pygame2_sdl_video_Surface_get_palette(self):
 
         # get_palette () -> (Color, Color, ...)
         video.init ()
+        video.quit ()
         self.fail() 
 
     def test_pygame2_sdl_video_Surface_h(self):
 
         # Get the length of a surface scanline in bytes.
         video.init ()
+        video.quit ()
         self.fail() 
 
     def todo_test_pygame2_sdl_video_Surface_pixels(self):
 
         # Gets the pixel buffer of the Surface.
         video.init ()
+        video.quit ()
         self.fail() 
 
     def test_pygame2_sdl_video_Surface_save(self):
         # 
         # TODO
         video.init ()
+        video.quit ()
         self.fail() 
 
     def todo_test_pygame2_sdl_video_Surface_set_at(self):
         # 
         # Sets the Surface pixel value at the specified point.
         video.init ()
+        video.quit ()
         self.fail() 
 
     def todo_test_pygame2_sdl_video_Surface_set_colorkey(self):
         # Adjusts the colorkey of the Surface.
         # 
         # TODO
+        video.quit ()
         video.init ()
         self.fail() 
 
         # If any other error occurs, False will be returned and the
         # Surface palette should be inspected for any changes.
         video.init ()
+        video.quit ()
         self.fail() 
 
     def todo_test_pygame2_sdl_video_Surface_set_palette(self):
         # If any other error occurs, False will be returned and the
         # Surface palette should be inspected for any changes.
         video.init ()
+        video.quit ()
         self.fail() 
 
     def test_pygame2_sdl_video_Surface_size(self):
         self.assert_ (sf.unlock () == None)
         video.quit ()
 
-
     def todo_test_pygame2_sdl_video_Surface_update(self):
 
         # __doc__ (as of 2009-05-15) for pygame2.sdl.video.Surface.update:
         # Upates the given area (or areas, if a list of rects is passed)
         # on the Surface.
         video.init ()
+        video.quit ()
         self.fail() 
 
     def test_pygame2_sdl_video_Surface_w(self):

test/sdl_video_test.py

         video.quit ()
         self.assert_ (video.get_drivername () == None)
 
-    def todo_test_pygame2_sdl_video_get_gammaramp(self):
+    def test_pygame2_sdl_video_get_gammaramp(self):
 
         # __doc__ (as of 2009-05-31) for pygame2.sdl.video.get_gammaramp:
 
         # Gets the color gamma lookup table for the display. This will
         # return three tuples for the red, green and blue gamma values. Each
         # tuple contains 256 values.
-
-        self.fail() 
+        video.init ()
+        r, g, b = video.get_gammaramp ()
+        self.assert_ (len (r) == 256)
+        self.assert_ (len (g) == 256)
+        self.assert_ (len (b) == 256)
+        for v in r:
+            self.assert_ (type (v) == int)
+        for v in g:
+            self.assert_ (type (v) == int)
+        for v in b:
+            self.assert_ (type (v) == int)
+        video.quit ()
 
     def test_pygame2_sdl_video_get_info(self):