Mercurial > pygame
annotate src/key.c @ 3172:d1b367fc08bc tests-returncode
Use a return code of 1 when the tests fail.
| author | Thomas Kluyver <takowl@gmail.com> |
|---|---|
| date | Wed, 09 Jan 2013 10:13:57 +0000 |
| parents | 0d661c00c1aa |
| children |
| rev | line source |
|---|---|
| 7 | 1 /* |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
2 pygame - Python Game Library |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
3 Copyright (C) 2000-2001 Pete Shinners |
| 7 | 4 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
5 This library is free software; you can redistribute it and/or |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
6 modify it under the terms of the GNU Library General Public |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
7 License as published by the Free Software Foundation; either |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
8 version 2 of the License, or (at your option) any later version. |
| 7 | 9 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
10 This library is distributed in the hope that it will be useful, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
13 Library General Public License for more details. |
| 7 | 14 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
15 You should have received a copy of the GNU Library General Public |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
16 License along with this library; if not, write to the Free |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 7 | 18 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
19 Pete Shinners |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
20 pete@shinners.org |
| 7 | 21 */ |
| 22 | |
| 23 /* | |
| 29 | 24 * pygame keyboard module |
| 7 | 25 */ |
| 26 #include "pygame.h" | |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
27 #include "pgcompat.h" |
| 1937 | 28 #include "doc/key_doc.h" |
| 7 | 29 |
| 30 /* keyboard module functions */ | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
31 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
32 key_set_repeat (PyObject* self, PyObject* args) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
33 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
34 int delay = 0, interval = 0; |
| 7 | 35 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
36 if (!PyArg_ParseTuple (args, "|ii", &delay, &interval)) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
37 return NULL; |
| 7 | 38 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
39 VIDEO_INIT_CHECK (); |
| 7 | 40 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
41 if (delay && !interval) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
42 interval = delay; |
| 7 | 43 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
44 if (SDL_EnableKeyRepeat (delay, interval) == -1) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
45 return RAISE (PyExc_SDLError, SDL_GetError ()); |
| 255 | 46 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
47 Py_RETURN_NONE; |
| 7 | 48 } |
| 49 | |
|
920
c65a322ea131
Updated constants GL_SWAP_CONTROL,GL_ACCELERATED_VISUAL,BUTTON_X1,BUTTON_X2
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
50 |
|
c65a322ea131
Updated constants GL_SWAP_CONTROL,GL_ACCELERATED_VISUAL,BUTTON_X1,BUTTON_X2
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
51 |
|
c65a322ea131
Updated constants GL_SWAP_CONTROL,GL_ACCELERATED_VISUAL,BUTTON_X1,BUTTON_X2
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
52 static PyObject* |
|
c65a322ea131
Updated constants GL_SWAP_CONTROL,GL_ACCELERATED_VISUAL,BUTTON_X1,BUTTON_X2
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
53 key_get_repeat (PyObject* self, PyObject* args) |
|
c65a322ea131
Updated constants GL_SWAP_CONTROL,GL_ACCELERATED_VISUAL,BUTTON_X1,BUTTON_X2
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
54 { |
|
c65a322ea131
Updated constants GL_SWAP_CONTROL,GL_ACCELERATED_VISUAL,BUTTON_X1,BUTTON_X2
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
55 int delay = 0, interval = 0; |
|
c65a322ea131
Updated constants GL_SWAP_CONTROL,GL_ACCELERATED_VISUAL,BUTTON_X1,BUTTON_X2
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
56 |
|
c65a322ea131
Updated constants GL_SWAP_CONTROL,GL_ACCELERATED_VISUAL,BUTTON_X1,BUTTON_X2
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
57 VIDEO_INIT_CHECK (); |
|
c65a322ea131
Updated constants GL_SWAP_CONTROL,GL_ACCELERATED_VISUAL,BUTTON_X1,BUTTON_X2
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
58 #if SDL_VERSION_ATLEAST(1, 2, 10) |
|
c65a322ea131
Updated constants GL_SWAP_CONTROL,GL_ACCELERATED_VISUAL,BUTTON_X1,BUTTON_X2
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
59 SDL_GetKeyRepeat (&delay, &interval); |
|
c65a322ea131
Updated constants GL_SWAP_CONTROL,GL_ACCELERATED_VISUAL,BUTTON_X1,BUTTON_X2
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
60 return Py_BuildValue ("(ii)", delay, interval); |
|
c65a322ea131
Updated constants GL_SWAP_CONTROL,GL_ACCELERATED_VISUAL,BUTTON_X1,BUTTON_X2
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
61 #else |
|
c65a322ea131
Updated constants GL_SWAP_CONTROL,GL_ACCELERATED_VISUAL,BUTTON_X1,BUTTON_X2
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
62 Py_RETURN_NONE; |
|
c65a322ea131
Updated constants GL_SWAP_CONTROL,GL_ACCELERATED_VISUAL,BUTTON_X1,BUTTON_X2
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
63 #endif |
|
c65a322ea131
Updated constants GL_SWAP_CONTROL,GL_ACCELERATED_VISUAL,BUTTON_X1,BUTTON_X2
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
64 } |
|
c65a322ea131
Updated constants GL_SWAP_CONTROL,GL_ACCELERATED_VISUAL,BUTTON_X1,BUTTON_X2
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
65 |
|
c65a322ea131
Updated constants GL_SWAP_CONTROL,GL_ACCELERATED_VISUAL,BUTTON_X1,BUTTON_X2
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
66 |
|
c65a322ea131
Updated constants GL_SWAP_CONTROL,GL_ACCELERATED_VISUAL,BUTTON_X1,BUTTON_X2
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
67 |
|
c65a322ea131
Updated constants GL_SWAP_CONTROL,GL_ACCELERATED_VISUAL,BUTTON_X1,BUTTON_X2
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
68 |
|
c65a322ea131
Updated constants GL_SWAP_CONTROL,GL_ACCELERATED_VISUAL,BUTTON_X1,BUTTON_X2
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
69 |
|
c65a322ea131
Updated constants GL_SWAP_CONTROL,GL_ACCELERATED_VISUAL,BUTTON_X1,BUTTON_X2
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
70 |
|
c65a322ea131
Updated constants GL_SWAP_CONTROL,GL_ACCELERATED_VISUAL,BUTTON_X1,BUTTON_X2
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
71 |
|
c65a322ea131
Updated constants GL_SWAP_CONTROL,GL_ACCELERATED_VISUAL,BUTTON_X1,BUTTON_X2
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
72 |
|
c65a322ea131
Updated constants GL_SWAP_CONTROL,GL_ACCELERATED_VISUAL,BUTTON_X1,BUTTON_X2
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
73 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
74 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
75 key_get_pressed (PyObject* self) |
| 7 | 76 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
77 int num_keys; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
78 Uint8* key_state; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
79 PyObject* key_tuple; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
80 int i; |
| 7 | 81 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
82 VIDEO_INIT_CHECK (); |
| 7 | 83 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
84 key_state = SDL_GetKeyState (&num_keys); |
| 7 | 85 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
86 if (!key_state || !num_keys) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
87 Py_RETURN_NONE; |
| 7 | 88 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
89 if (!(key_tuple = PyTuple_New (num_keys))) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
90 return NULL; |
| 7 | 91 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
92 for (i = 0;i < num_keys;i++) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
93 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
94 PyObject* key_elem; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
95 key_elem = PyInt_FromLong (key_state[i]); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
96 if (!key_elem) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
97 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
98 Py_DECREF (key_tuple); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
99 return NULL; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
100 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
101 PyTuple_SET_ITEM (key_tuple, i, key_elem); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
102 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
103 return key_tuple; |
| 7 | 104 } |
| 105 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
106 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
107 key_name (PyObject* self, PyObject* args) |
| 7 | 108 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
109 int key; |
| 7 | 110 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
111 if (!PyArg_ParseTuple (args, "i", &key)) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
112 return NULL; |
| 7 | 113 |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
114 return Text_FromUTF8 (SDL_GetKeyName (key)); |
| 7 | 115 } |
| 116 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
117 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
118 key_get_mods (PyObject* self) |
| 7 | 119 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
120 VIDEO_INIT_CHECK (); |
| 7 | 121 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
122 return PyInt_FromLong (SDL_GetModState ()); |
| 7 | 123 } |
| 124 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
125 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
126 key_set_mods (PyObject* self, PyObject* args) |
| 7 | 127 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
128 int mods; |
| 126 | 129 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
130 if (!PyArg_ParseTuple (args, "i", &mods)) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
131 return NULL; |
| 7 | 132 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
133 VIDEO_INIT_CHECK (); |
| 7 | 134 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
135 SDL_SetModState (mods); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
136 Py_RETURN_NONE; |
| 7 | 137 } |
| 138 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
139 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
140 key_get_focused (PyObject* self) |
| 7 | 141 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
142 VIDEO_INIT_CHECK (); |
| 7 | 143 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
144 return PyInt_FromLong ((SDL_GetAppState () & SDL_APPINPUTFOCUS) != 0); |
| 7 | 145 } |
| 146 | |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
147 static PyMethodDef _key_methods[] = |
| 7 | 148 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
149 { "set_repeat", key_set_repeat, METH_VARARGS, DOC_PYGAMEKEYSETREPEAT }, |
|
920
c65a322ea131
Updated constants GL_SWAP_CONTROL,GL_ACCELERATED_VISUAL,BUTTON_X1,BUTTON_X2
Rene Dudfield <renesd@gmail.com>
parents:
831
diff
changeset
|
150 { "get_repeat", key_get_repeat, METH_NOARGS, DOC_PYGAMEKEYGETREPEAT }, |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
151 { "get_pressed", (PyCFunction) key_get_pressed, METH_NOARGS, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
152 DOC_PYGAMEKEYGETPRESSED }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
153 { "name", key_name, METH_VARARGS, DOC_PYGAMEKEYNAME }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
154 { "get_mods", (PyCFunction) key_get_mods, METH_NOARGS, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
155 DOC_PYGAMEKEYGETMODS }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
156 { "set_mods", key_set_mods, METH_VARARGS, DOC_PYGAMEKEYSETMODS }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
157 { "get_focused", (PyCFunction) key_get_focused, METH_NOARGS, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
158 DOC_PYGAMEKEYGETFOCUSED }, |
| 7 | 159 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
798
diff
changeset
|
160 { NULL, NULL, 0, NULL } |
| 7 | 161 }; |
| 162 | |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
163 MODINIT_DEFINE (key) |
| 7 | 164 { |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
165 PyObject *module; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
166 |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
167 #if PY3 |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
168 static struct PyModuleDef _module = { |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
169 PyModuleDef_HEAD_INIT, |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
170 "key", |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
171 DOC_PYGAMEKEY, |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
172 -1, |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
173 _key_methods, |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
174 NULL, NULL, NULL, NULL |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
175 }; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
176 #endif |
| 7 | 177 |
|
1499
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
920
diff
changeset
|
178 /* imported needed apis; Do this first so if there is an error |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
920
diff
changeset
|
179 the module is not loaded. |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
920
diff
changeset
|
180 */ |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
920
diff
changeset
|
181 import_pygame_base (); |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
920
diff
changeset
|
182 if (PyErr_Occurred ()) { |
|
1804
7444350a233c
in init functions: fix minor Python 3.x related memory leaks and clean up indentation
Lenard Lindstrom <len-l@telus.net>
parents:
1592
diff
changeset
|
183 MODINIT_ERROR; |
|
1499
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
920
diff
changeset
|
184 } |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
920
diff
changeset
|
185 |
| 7 | 186 /* create the module */ |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
187 #if PY3 |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
188 module = PyModule_Create (&_module); |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
189 #else |
| 1592 | 190 module = Py_InitModule3 (MODPREFIX "key", |
| 191 _key_methods, | |
| 192 DOC_PYGAMEKEY); | |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
193 #endif |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
194 if (module == NULL) { |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
195 MODINIT_ERROR; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
196 } |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
197 MODINIT_RETURN (module); |
| 7 | 198 } |
