1. pygame
  2. Untitled project
  3. pygame

Commits

marcus  committed 15121dd

SDL video initialisation is required for keyboard functionanlity.

  • Participants
  • Parent commits 5f98111
  • Branches pgreloaded

Comments (0)

Files changed (2)

File src/sdl/keyboardmod.c

View file
     int count, i;
     PyObject *dict, *key, *val;
     
-    /*ASSERT_VIDEO_INIT (NULL);*/
+    ASSERT_VIDEO_INIT (NULL);
     
     dict = PyDict_New ();
     if (!dict)
 static PyObject*
 _sdl_keygetmodstate (PyObject *self)
 {
-    /*ASSERT_VIDEO_INIT (NULL);*/
+    ASSERT_VIDEO_INIT (NULL);
     return PyLong_FromUnsignedLong (SDL_GetModState ());
 }
 
 _sdl_keysetmodstate (PyObject *self, PyObject *args)
 {
     SDLMod mod;
-    /*ASSERT_VIDEO_INIT (NULL);*/
+    ASSERT_VIDEO_INIT (NULL);
     
     if (!PyArg_ParseTuple (args, "i:set_mod_state", &mod))
         return NULL;
 {
     int key;
     
-    /*ASSERT_VIDEO_INIT (NULL);*/
+    ASSERT_VIDEO_INIT (NULL);
     
     if (!PyArg_ParseTuple (args, "i:get_key_name", &key))
         return NULL;
 {
     int delay, interval;
     
+    ASSERT_VIDEO_INIT (NULL);
+
     if (!PyArg_ParseTuple (args, "ii:enable_key_repeat", &delay, &interval))
         return NULL;
     if (delay < 0 || interval < 0)
 _sdl_keygetkeyrepeat (PyObject *self)
 {
     int delay, interval;
+    ASSERT_VIDEO_INIT (NULL);
     SDL_GetKeyRepeat (&delay, &interval);
     return Py_BuildValue ("(ii)", delay, interval);
 }
     PyObject *val = NULL;
     int enable;
 
+    ASSERT_VIDEO_INIT (NULL);
+
     if (!PyArg_ParseTuple (args, "|O:enable_unicode", &val))
         return NULL;
 

File test/sdl_keyboard_test.py

View file
 
 import pygame2
 import pygame2.sdl.keyboard as keyboard
+import pygame2.sdl.video as video
 import pygame2.sdl.constants as constants
 
 class SDLKeyboardTest (unittest.TestCase):
         # repeating completely.
         # 
         # Setting delay to 0 will disable repeating completely.
+        video.init ()
         self.assert_ (keyboard.enable_repeat (0, 0) == None)
         self.assert_ (keyboard.enable_repeat (1, 1) == None)
         self.assert_ (keyboard.enable_repeat (900, 1000) == None)
         self.assertRaises (ValueError, keyboard.enable_repeat, -1, -1)
         self.assertRaises (ValueError, keyboard.enable_repeat,  1, -1)
         self.assertRaises (ValueError, keyboard.enable_repeat, -1,  1)
+        video.quit ()
 
     def test_pygame2_sdl_keyboard_enable_unicode(self):
 
         # state.  By default unicode handling is enabled and for
         # keyboard events, the *unicode* member of the event will be
         # filled with the corresponding unicode character.
+        video.init ()
         self.assert_ (keyboard.enable_unicode () == True)
         self.assert_ (keyboard.enable_unicode (True) == True)
         self.assert_ (keyboard.enable_unicode (False) == True)
         self.assert_ (keyboard.enable_unicode (False) == True)
         self.assert_ (keyboard.enable_unicode (False) == False)
         self.assert_ (keyboard.enable_unicode () == False)
+        video.quit ()
         
     def test_pygame2_sdl_keyboard_get_key_name(self):
 
         # get_key_name (key) -> str
         # 
         # Get the descriptive name for a key constant.
+        video.init ()
         self.assert_ (keyboard.get_key_name (constants.K_a) == 'a')
         self.assert_ (keyboard.get_key_name (constants.K_b) == 'b')
         self.assert_ (keyboard.get_key_name (constants.K_q) == 'q')
         self.assert_ (keyboard.get_key_name (constants.K_PAGEUP) == 'page up')
         self.assert_ (keyboard.get_key_name (constants.K_KP4) == '[4]')
         self.assert_ (keyboard.get_key_name (constants.K_4) == '4')
+        video.quit ()
 
     def todo_test_pygame2_sdl_keyboard_get_mod_state(self):
 
         # get_repeat () -> delay, interval
         # 
         # Gets the currently set keyboard repeat delay and interval.
+        video.init ()
         keyboard.enable_repeat (0, 0)
         self.assert_ (keyboard.get_repeat () == (0, 0))
         keyboard.enable_repeat (10, 10)
         self.assert_ (keyboard.get_repeat () == (0, 5))
         keyboard.enable_repeat (7, 0)
         self.assert_ (keyboard.get_repeat () == (7, 0))
+        video.quit ()
 
     def test_pygame2_sdl_keyboard_get_state(self):
 
         # the dictionary are the key constants, the boolean values of
         # the dictionary indicate, whether a certain key is pressed or
         # not.
+        video.init ()
         self.assert_ (type (keyboard.get_state ()) == dict)
         self.assert_ (constants.K_a in keyboard.get_state ().keys ())
         self.assert_ (constants.K_b in keyboard.get_state ().keys ())
         self.assert_ (constants.K_q in keyboard.get_state ().keys ())
         self.assert_ (constants.K_KP4 in keyboard.get_state ().keys ())
+        video.quit ()
 
     def todo_test_pygame2_sdl_keyboard_set_mod_state(self):