Mercurial > pygame
annotate src/event.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 | f8bb07a1bccd |
| children |
| rev | line source |
|---|---|
| 7 | 1 /* |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
2 pygame - Python Game Library |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
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:
813
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:
813
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:
813
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:
813
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:
813
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:
813
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:
813
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:
813
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:
813
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:
813
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:
813
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:
813
diff
changeset
|
19 Pete Shinners |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
20 pete@shinners.org |
| 7 | 21 */ |
| 22 | |
| 23 /* | |
| 29 | 24 * pygame event module |
| 7 | 25 */ |
| 26 #define PYGAMEAPI_EVENT_INTERNAL | |
| 27 #include "pygame.h" | |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
28 #include "pgcompat.h" |
| 1937 | 29 #include "doc/event_doc.h" |
| 7 | 30 |
|
2164
4ab5917b771e
Implements Motherhamster Bugzilla feature request 62: Allow attribute assignment to event type
Lenard Lindstrom <len-l@telus.net>
parents:
2163
diff
changeset
|
31 #include "structmember.h" |
|
4ab5917b771e
Implements Motherhamster Bugzilla feature request 62: Allow attribute assignment to event type
Lenard Lindstrom <len-l@telus.net>
parents:
2163
diff
changeset
|
32 |
|
617
69cd7b44cac0
Some code from Matthias Baas. It adds some attributes to the
Rene Dudfield <renesd@gmail.com>
parents:
587
diff
changeset
|
33 // FIXME: The system message code is only tested on windows, so only |
|
69cd7b44cac0
Some code from Matthias Baas. It adds some attributes to the
Rene Dudfield <renesd@gmail.com>
parents:
587
diff
changeset
|
34 // include it there for now. |
|
69cd7b44cac0
Some code from Matthias Baas. It adds some attributes to the
Rene Dudfield <renesd@gmail.com>
parents:
587
diff
changeset
|
35 #include <SDL_syswm.h> |
| 7 | 36 |
| 172 | 37 /*this user event object is for safely passing |
| 38 *objects through the event queue. | |
| 39 */ | |
| 40 | |
| 41 #define USEROBJECT_CHECK1 0xDEADBEEF | |
| 42 #define USEROBJECT_CHECK2 0xFEEDF00D | |
| 43 | |
| 44 typedef struct UserEventObject | |
| 45 { | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
46 struct UserEventObject* next; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
47 PyObject* object; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
48 } UserEventObject; |
| 172 | 49 |
| 50 static UserEventObject* user_event_objects = NULL; | |
| 51 | |
| 52 /*must pass dictionary as this object*/ | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
53 static UserEventObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
54 user_event_addobject (PyObject* obj) |
| 172 | 55 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
56 UserEventObject* userobj = PyMem_New (UserEventObject, 1); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
57 if (!userobj) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
58 return NULL; |
| 172 | 59 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
60 Py_INCREF (obj); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
61 userobj->next = user_event_objects; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
62 userobj->object = obj; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
63 user_event_objects = userobj; |
| 231 | 64 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
65 return userobj; |
| 172 | 66 } |
| 67 | |
| 68 /*note, we doublecheck to make sure the pointer is in our list, | |
| 288 | 69 *not just some random pointer. this will keep us safe(r). |
| 172 | 70 */ |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
71 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
72 user_event_getobject (UserEventObject* userobj) |
| 172 | 73 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
74 PyObject* obj = NULL; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
75 if (!user_event_objects) /*fail in most common case*/ |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
76 return NULL; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
77 if (user_event_objects == userobj) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
78 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
79 obj = userobj->object; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
80 user_event_objects = userobj->next; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
81 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
82 else |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
83 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
84 UserEventObject* hunt = user_event_objects; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
85 while (hunt && hunt->next != userobj) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
86 hunt = hunt->next; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
87 if (hunt) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
88 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
89 hunt->next = userobj->next; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
90 obj = userobj->object; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
91 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
92 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
93 if (obj) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
94 PyMem_Del (userobj); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
95 return obj; |
| 172 | 96 } |
| 97 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
98 static void |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
99 user_event_cleanup (void) |
| 172 | 100 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
101 if (user_event_objects) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
102 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
103 UserEventObject *hunt, *kill; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
104 hunt = user_event_objects; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
105 while (hunt) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
106 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
107 kill = hunt; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
108 hunt = hunt->next; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
109 Py_DECREF (kill->object); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
110 PyMem_Del (kill); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
111 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
112 user_event_objects = NULL; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
113 } |
| 172 | 114 } |
| 7 | 115 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
116 static int PyEvent_FillUserEvent (PyEventObject *e, SDL_Event *event) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
117 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
118 UserEventObject *userobj = user_event_addobject (e->dict); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
119 if (!userobj) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
120 return -1; |
| 7 | 121 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
122 event->type = e->type; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
123 event->user.code = USEROBJECT_CHECK1; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
124 event->user.data1 = (void*)USEROBJECT_CHECK2; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
125 event->user.data2 = userobj; |
| 587 | 126 return 0; |
| 127 } | |
| 7 | 128 |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
129 static PyTypeObject PyEvent_Type; |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
130 static PyObject* PyEvent_New (SDL_Event*); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
131 static PyObject* PyEvent_New2 (int, PyObject*); |
| 7 | 132 #define PyEvent_Check(x) ((x)->ob_type == &PyEvent_Type) |
| 133 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
134 static char* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
135 name_from_eventtype (int type) |
| 7 | 136 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
137 switch (type) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
138 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
139 case SDL_ACTIVEEVENT: |
|
2162
9e86b65470f9
Tidy up white space in event.c in preparation to update attribute handling
Lenard Lindstrom <len-l@telus.net>
parents:
2146
diff
changeset
|
140 return "ActiveEvent"; |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
141 case SDL_KEYDOWN: |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
142 return "KeyDown"; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
143 case SDL_KEYUP: |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
144 return "KeyUp"; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
145 case SDL_MOUSEMOTION: |
|
2162
9e86b65470f9
Tidy up white space in event.c in preparation to update attribute handling
Lenard Lindstrom <len-l@telus.net>
parents:
2146
diff
changeset
|
146 return "MouseMotion"; |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
147 case SDL_MOUSEBUTTONDOWN: |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
148 return "MouseButtonDown"; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
149 case SDL_MOUSEBUTTONUP: |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
150 return "MouseButtonUp"; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
151 case SDL_JOYAXISMOTION: |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
152 return "JoyAxisMotion"; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
153 case SDL_JOYBALLMOTION: |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
154 return "JoyBallMotion"; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
155 case SDL_JOYHATMOTION: |
|
2162
9e86b65470f9
Tidy up white space in event.c in preparation to update attribute handling
Lenard Lindstrom <len-l@telus.net>
parents:
2146
diff
changeset
|
156 return "JoyHatMotion"; |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
157 case SDL_JOYBUTTONUP: |
|
2162
9e86b65470f9
Tidy up white space in event.c in preparation to update attribute handling
Lenard Lindstrom <len-l@telus.net>
parents:
2146
diff
changeset
|
158 return "JoyButtonUp"; |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
159 case SDL_JOYBUTTONDOWN: |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
160 return "JoyButtonDown"; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
161 case SDL_QUIT: |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
162 return "Quit"; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
163 case SDL_SYSWMEVENT: |
|
2162
9e86b65470f9
Tidy up white space in event.c in preparation to update attribute handling
Lenard Lindstrom <len-l@telus.net>
parents:
2146
diff
changeset
|
164 return "SysWMEvent"; |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
165 case SDL_VIDEORESIZE: |
|
2162
9e86b65470f9
Tidy up white space in event.c in preparation to update attribute handling
Lenard Lindstrom <len-l@telus.net>
parents:
2146
diff
changeset
|
166 return "VideoResize"; |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
167 case SDL_VIDEOEXPOSE: |
|
2162
9e86b65470f9
Tidy up white space in event.c in preparation to update attribute handling
Lenard Lindstrom <len-l@telus.net>
parents:
2146
diff
changeset
|
168 return "VideoExpose"; |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
169 case SDL_NOEVENT: |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
170 return "NoEvent"; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
171 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
172 if (type >= SDL_USEREVENT && type < SDL_NUMEVENTS) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
173 return "UserEvent"; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
174 return "Unknown"; |
| 7 | 175 } |
| 176 | |
| 163 | 177 /* Helper for adding objects to dictionaries. Check for errors with |
| 178 PyErr_Occurred() */ | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
179 static void |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
180 insobj (PyObject *dict, char *name, PyObject *v) |
| 163 | 181 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
182 if(v) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
183 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
184 PyDict_SetItemString (dict, name, v); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
185 Py_DECREF (v); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
186 } |
| 163 | 187 } |
| 188 | |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
189 #if defined(Py_USING_UNICODE) |
| 401 | 190 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
191 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
192 our_unichr (long uni) |
| 401 | 193 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
194 static PyObject* bltin_unichr = NULL; |
| 481 | 195 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
196 if (bltin_unichr == NULL) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
197 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
198 PyObject* bltins; |
| 401 | 199 |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
200 bltins = PyImport_ImportModule (BUILTINS_MODULE); |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
201 bltin_unichr = PyObject_GetAttrString (bltins, BUILTINS_UNICHR); |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
202 Py_DECREF (bltins); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
203 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
204 return PyEval_CallFunction (bltin_unichr, "(l)", uni); |
| 401 | 205 } |
| 206 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
207 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
208 our_empty_ustr (void) |
| 401 | 209 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
210 static PyObject* empty_ustr = NULL; |
| 401 | 211 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
212 if (empty_ustr == NULL) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
213 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
214 PyObject* bltins; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
215 PyObject* bltin_unicode; |
| 481 | 216 |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
217 bltins = PyImport_ImportModule (BUILTINS_MODULE); |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
218 bltin_unicode = PyObject_GetAttrString (bltins, BUILTINS_UNICODE); |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
219 empty_ustr = PyEval_CallFunction (bltin_unicode, "(s)", ""); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
220 Py_DECREF (bltin_unicode); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
221 Py_DECREF (bltins); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
222 } |
| 401 | 223 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
224 Py_INCREF (empty_ustr); |
| 401 | 225 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
226 return empty_ustr; |
| 401 | 227 } |
| 228 | |
| 229 #else | |
| 230 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
231 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
232 our_unichr (long uni) |
| 401 | 233 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
234 return PyInt_FromLong (uni); |
| 401 | 235 } |
| 236 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
237 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
238 our_empty_ustr (void) |
| 401 | 239 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
240 return PyInt_FromLong (0); |
| 401 | 241 } |
| 242 | |
| 243 #endif /* Py_USING_UNICODE */ | |
| 163 | 244 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
245 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
246 dict_from_event (SDL_Event* event) |
| 7 | 247 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
248 PyObject *dict=NULL, *tuple, *obj; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
249 int hx, hy; |
| 7 | 250 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
251 /*check if it is an event the user posted*/ |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
252 if (event->user.code == USEROBJECT_CHECK1 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
253 && event->user.data1 == (void*)USEROBJECT_CHECK2) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
254 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
255 dict = user_event_getobject ((UserEventObject*)event->user.data2); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
256 if (dict) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
257 return dict; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
258 } |
| 231 | 259 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
260 if (!(dict = PyDict_New ())) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
261 return NULL; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
262 switch (event->type) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
263 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
264 case SDL_ACTIVEEVENT: |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
265 insobj (dict, "gain", PyInt_FromLong (event->active.gain)); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
266 insobj (dict, "state", PyInt_FromLong (event->active.state)); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
267 break; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
268 case SDL_KEYDOWN: |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
269 if (event->key.keysym.unicode) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
270 insobj (dict, "unicode", our_unichr (event->key.keysym.unicode)); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
271 else |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
272 insobj (dict, "unicode", our_empty_ustr ()); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
273 case SDL_KEYUP: |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
274 insobj (dict, "key", PyInt_FromLong (event->key.keysym.sym)); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
275 insobj (dict, "mod", PyInt_FromLong (event->key.keysym.mod)); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
276 insobj (dict, "scancode", PyInt_FromLong (event->key.keysym.scancode)); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
277 break; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
278 case SDL_MOUSEMOTION: |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
279 obj = Py_BuildValue ("(ii)", event->motion.x, event->motion.y); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
280 insobj (dict, "pos", obj); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
281 obj = Py_BuildValue ("(ii)", event->motion.xrel, event->motion.yrel); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
282 insobj (dict, "rel", obj); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
283 if ((tuple = PyTuple_New (3))) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
284 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
285 PyTuple_SET_ITEM |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
286 (tuple, 0, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
287 PyInt_FromLong ((event->motion.state&SDL_BUTTON(1)) != 0)); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
288 PyTuple_SET_ITEM |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
289 (tuple, 1, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
290 PyInt_FromLong ((event->motion.state&SDL_BUTTON(2)) != 0)); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
291 PyTuple_SET_ITEM |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
292 (tuple, 2, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
293 PyInt_FromLong ((event->motion.state&SDL_BUTTON(3)) != 0)); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
294 insobj (dict, "buttons", tuple); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
295 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
296 break; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
297 case SDL_MOUSEBUTTONDOWN: |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
298 case SDL_MOUSEBUTTONUP: |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
299 obj = Py_BuildValue ("(ii)", event->button.x, event->button.y); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
300 insobj (dict, "pos", obj); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
301 insobj (dict, "button", PyInt_FromLong (event->button.button)); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
302 break; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
303 case SDL_JOYAXISMOTION: |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
304 insobj (dict, "joy", PyInt_FromLong (event->jaxis.which)); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
305 insobj (dict, "axis", PyInt_FromLong (event->jaxis.axis)); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
306 insobj (dict, "value", PyFloat_FromDouble (event->jaxis.value/32767.0)); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
307 break; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
308 case SDL_JOYBALLMOTION: |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
309 insobj (dict, "joy", PyInt_FromLong (event->jball.which)); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
310 insobj (dict, "ball", PyInt_FromLong (event->jball.ball)); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
311 obj = Py_BuildValue ("(ii)", event->jball.xrel, event->jball.yrel); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
312 insobj (dict, "rel", obj); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
313 break; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
314 case SDL_JOYHATMOTION: |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
315 insobj (dict, "joy", PyInt_FromLong (event->jhat.which)); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
316 insobj (dict, "hat", PyInt_FromLong (event->jhat.hat)); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
317 hx = hy = 0; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
318 if (event->jhat.value&SDL_HAT_UP) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
319 hy = 1; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
320 else if (event->jhat.value&SDL_HAT_DOWN) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
321 hy = -1; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
322 if (event->jhat.value&SDL_HAT_RIGHT) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
323 hx = 1; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
324 else if (event->jhat.value&SDL_HAT_LEFT) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
325 hx = -1; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
326 insobj (dict, "value", Py_BuildValue ("(ii)", hx, hy)); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
327 break; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
328 case SDL_JOYBUTTONUP: |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
329 case SDL_JOYBUTTONDOWN: |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
330 insobj (dict, "joy", PyInt_FromLong (event->jbutton.which)); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
331 insobj (dict, "button", PyInt_FromLong (event->jbutton.button)); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
332 break; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
333 case SDL_VIDEORESIZE: |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
334 obj = Py_BuildValue ("(ii)", event->resize.w, event->resize.h); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
335 insobj (dict, "size", obj); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
336 insobj (dict, "w", PyInt_FromLong (event->resize.w)); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
337 insobj (dict, "h", PyInt_FromLong (event->resize.h)); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
338 break; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
339 case SDL_SYSWMEVENT: |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
340 #ifdef WIN32 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
341 insobj (dict, "hwnd", PyInt_FromLong ((long)(event-> syswm.msg->hwnd))); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
342 insobj (dict, "msg", PyInt_FromLong (event-> syswm.msg->msg)); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
343 insobj (dict, "wparam", PyInt_FromLong (event-> syswm.msg->wParam)); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
344 insobj (dict, "lparam", PyInt_FromLong (event-> syswm.msg->lParam)); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
345 #endif |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
346 /* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
347 * Make the event |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
348 */ |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
349 #if (defined(unix) || defined(__unix__) || defined(_AIX) \ |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
350 || defined(__OpenBSD__)) && \ |
|
1912
35e02db899ff
bugzilla 29, patch to use SDL_VIDEO_DRIVER_X11 instead of DISABLE_X11. Thanks Robert A. Lerche.
Rene Dudfield <renesd@gmail.com>
parents:
1581
diff
changeset
|
351 (defined(SDL_VIDEO_DRIVER_X11) && !defined(__CYGWIN32__) && \ |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
352 !defined(ENABLE_NANOX) && !defined(__QNXNTO__)) |
|
675
7cf576f4d731
Added an event member for SDL_SYSWMEVENT on X11. So you can get
Rene Dudfield <renesd@gmail.com>
parents:
627
diff
changeset
|
353 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
354 //printf("asdf :%d:", event->syswm.msg->event.xevent.type); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
355 insobj (dict, "event", |
|
2146
43f03efa305e
fix bug involving Python 3.x and X11 PropertyNotify event: raw binary data was returned as a unicode objects instead of bytes.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
356 Bytes_FromStringAndSize |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
357 ((char*) & (event->syswm.msg->event.xevent), sizeof (XEvent))); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
358 #endif |
|
675
7cf576f4d731
Added an event member for SDL_SYSWMEVENT on X11. So you can get
Rene Dudfield <renesd@gmail.com>
parents:
627
diff
changeset
|
359 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
360 break; |
| 248 | 361 /* SDL_VIDEOEXPOSE and SDL_QUIT have no attributes */ |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
362 } |
|
3079
05eb8d574096
Add support for MacOSX OpenFile. This was done in SDL, but not in the pygame implementation. Use a similar approach that SDL 1.3 does, using SDL_USEREVENT + 0x1000 usercode + data1 for filename.
Mathieu Virbel <mat@kivy.org>
parents:
3012
diff
changeset
|
363 if (event->type == SDL_USEREVENT && event->user.code == 0x1000) { |
|
3086
f8bb07a1bccd
Fix 3.2 breakage introduced with commit 05eb8d574096
Lenard Lindstrom <len-l@telus.net>
parents:
3082
diff
changeset
|
364 insobj (dict, "filename", Text_FromUTF8 (event->user.data1)); |
| 3082 | 365 free(event->user.data1); |
| 366 event->user.data1 = NULL; | |
| 367 } | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
368 if (event->type >= SDL_USEREVENT && event->type < SDL_NUMEVENTS) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
369 insobj (dict, "code", PyInt_FromLong (event->user.code)); |
| 7 | 370 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
371 return dict; |
| 7 | 372 } |
| 373 | |
| 374 /* event object internals */ | |
| 375 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
376 static void |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
377 event_dealloc (PyObject* self) |
| 7 | 378 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
379 PyEventObject* e = (PyEventObject*)self; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
380 Py_XDECREF (e->dict); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
381 PyObject_DEL (self); |
| 7 | 382 } |
| 383 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
384 PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
385 event_str (PyObject* self) |
| 7 | 386 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
387 PyEventObject* e = (PyEventObject*)self; |
|
3012
51ea31f4da7b
Buffer overflow in event_str. Fixes #67
Rene Dudfield <renesd@gmail.com>
parents:
2286
diff
changeset
|
388 char *str; |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
389 PyObject *strobj; |
|
3012
51ea31f4da7b
Buffer overflow in event_str. Fixes #67
Rene Dudfield <renesd@gmail.com>
parents:
2286
diff
changeset
|
390 PyObject * pyobj; |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
391 char *s; |
|
3012
51ea31f4da7b
Buffer overflow in event_str. Fixes #67
Rene Dudfield <renesd@gmail.com>
parents:
2286
diff
changeset
|
392 int size; |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
393 #if PY3 |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
394 PyObject *encodedobj; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
395 #endif |
| 7 | 396 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
397 strobj = PyObject_Str (e->dict); |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
398 if (strobj == NULL) { |
|
2162
9e86b65470f9
Tidy up white space in event.c in preparation to update attribute handling
Lenard Lindstrom <len-l@telus.net>
parents:
2146
diff
changeset
|
399 return NULL; |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
400 } |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
401 #if PY3 |
|
2286
0e6b42275ddb
BUG: fix problem with Event.__repr__ reported on Pygame mailing list on July 24, 2011; thanks Dávid Gábor
Lenard Lindstrom <len-l@telus.net>
parents:
2164
diff
changeset
|
402 encodedobj = PyUnicode_AsUTF8String (strobj); |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
403 Py_DECREF (strobj); |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
404 strobj = encodedobj; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
405 encodedobj = NULL; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
406 if (strobj == NULL) { |
|
2162
9e86b65470f9
Tidy up white space in event.c in preparation to update attribute handling
Lenard Lindstrom <len-l@telus.net>
parents:
2146
diff
changeset
|
407 return NULL; |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
408 } |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
409 s = PyBytes_AsString (strobj); |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
410 #else |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
411 s = PyString_AsString (strobj); |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
412 #endif |
|
3012
51ea31f4da7b
Buffer overflow in event_str. Fixes #67
Rene Dudfield <renesd@gmail.com>
parents:
2286
diff
changeset
|
413 size = (11 + strlen(name_from_eventtype (e->type)) + strlen(s) + sizeof(e->type) * 3 + 1); |
|
51ea31f4da7b
Buffer overflow in event_str. Fixes #67
Rene Dudfield <renesd@gmail.com>
parents:
2286
diff
changeset
|
414 str = (char *) PyMem_Malloc(size); |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
415 sprintf (str, "<Event(%d-%s %s)>", e->type, name_from_eventtype (e->type), |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
416 s); |
| 7 | 417 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
418 Py_DECREF (strobj); |
|
3012
51ea31f4da7b
Buffer overflow in event_str. Fixes #67
Rene Dudfield <renesd@gmail.com>
parents:
2286
diff
changeset
|
419 |
|
51ea31f4da7b
Buffer overflow in event_str. Fixes #67
Rene Dudfield <renesd@gmail.com>
parents:
2286
diff
changeset
|
420 pyobj = Text_FromUTF8 (str); |
|
51ea31f4da7b
Buffer overflow in event_str. Fixes #67
Rene Dudfield <renesd@gmail.com>
parents:
2286
diff
changeset
|
421 PyMem_Free(str); |
|
51ea31f4da7b
Buffer overflow in event_str. Fixes #67
Rene Dudfield <renesd@gmail.com>
parents:
2286
diff
changeset
|
422 |
|
51ea31f4da7b
Buffer overflow in event_str. Fixes #67
Rene Dudfield <renesd@gmail.com>
parents:
2286
diff
changeset
|
423 return (pyobj); |
| 7 | 424 } |
| 425 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
426 static int |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
427 event_nonzero (PyEventObject *self) |
| 352 | 428 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
429 return self->type != SDL_NOEVENT; |
| 352 | 430 } |
| 15 | 431 |
| 352 | 432 static PyNumberMethods event_as_number = { |
|
2163
a7c8f262d2e6
Include edits missed in previous commit.
Lenard Lindstrom <len-l@telus.net>
parents:
2162
diff
changeset
|
433 (binaryfunc)NULL, /*Add*/ |
|
2162
9e86b65470f9
Tidy up white space in event.c in preparation to update attribute handling
Lenard Lindstrom <len-l@telus.net>
parents:
2146
diff
changeset
|
434 (binaryfunc)NULL, /*subtract*/ |
|
9e86b65470f9
Tidy up white space in event.c in preparation to update attribute handling
Lenard Lindstrom <len-l@telus.net>
parents:
2146
diff
changeset
|
435 (binaryfunc)NULL, /*multiply*/ |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
436 #if !PY3 |
|
2162
9e86b65470f9
Tidy up white space in event.c in preparation to update attribute handling
Lenard Lindstrom <len-l@telus.net>
parents:
2146
diff
changeset
|
437 (binaryfunc)NULL, /*divide*/ |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
438 #endif |
|
2162
9e86b65470f9
Tidy up white space in event.c in preparation to update attribute handling
Lenard Lindstrom <len-l@telus.net>
parents:
2146
diff
changeset
|
439 (binaryfunc)NULL, /*remainder*/ |
|
9e86b65470f9
Tidy up white space in event.c in preparation to update attribute handling
Lenard Lindstrom <len-l@telus.net>
parents:
2146
diff
changeset
|
440 (binaryfunc)NULL, /*divmod*/ |
|
2163
a7c8f262d2e6
Include edits missed in previous commit.
Lenard Lindstrom <len-l@telus.net>
parents:
2162
diff
changeset
|
441 (ternaryfunc)NULL, /*power*/ |
|
a7c8f262d2e6
Include edits missed in previous commit.
Lenard Lindstrom <len-l@telus.net>
parents:
2162
diff
changeset
|
442 (unaryfunc)NULL, /*negative*/ |
|
a7c8f262d2e6
Include edits missed in previous commit.
Lenard Lindstrom <len-l@telus.net>
parents:
2162
diff
changeset
|
443 (unaryfunc)NULL, /*pos*/ |
|
a7c8f262d2e6
Include edits missed in previous commit.
Lenard Lindstrom <len-l@telus.net>
parents:
2162
diff
changeset
|
444 (unaryfunc)NULL, /*abs*/ |
|
a7c8f262d2e6
Include edits missed in previous commit.
Lenard Lindstrom <len-l@telus.net>
parents:
2162
diff
changeset
|
445 (inquiry)event_nonzero, /*nonzero*/ |
|
a7c8f262d2e6
Include edits missed in previous commit.
Lenard Lindstrom <len-l@telus.net>
parents:
2162
diff
changeset
|
446 (unaryfunc)NULL, /*invert*/ |
|
2162
9e86b65470f9
Tidy up white space in event.c in preparation to update attribute handling
Lenard Lindstrom <len-l@telus.net>
parents:
2146
diff
changeset
|
447 (binaryfunc)NULL, /*lshift*/ |
|
9e86b65470f9
Tidy up white space in event.c in preparation to update attribute handling
Lenard Lindstrom <len-l@telus.net>
parents:
2146
diff
changeset
|
448 (binaryfunc)NULL, /*rshift*/ |
|
9e86b65470f9
Tidy up white space in event.c in preparation to update attribute handling
Lenard Lindstrom <len-l@telus.net>
parents:
2146
diff
changeset
|
449 (binaryfunc)NULL, /*and*/ |
|
9e86b65470f9
Tidy up white space in event.c in preparation to update attribute handling
Lenard Lindstrom <len-l@telus.net>
parents:
2146
diff
changeset
|
450 (binaryfunc)NULL, /*xor*/ |
|
9e86b65470f9
Tidy up white space in event.c in preparation to update attribute handling
Lenard Lindstrom <len-l@telus.net>
parents:
2146
diff
changeset
|
451 (binaryfunc)NULL, /*or*/ |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
452 #if !PY3 |
|
2163
a7c8f262d2e6
Include edits missed in previous commit.
Lenard Lindstrom <len-l@telus.net>
parents:
2162
diff
changeset
|
453 (coercion)NULL, /*coerce*/ |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
454 #endif |
|
2163
a7c8f262d2e6
Include edits missed in previous commit.
Lenard Lindstrom <len-l@telus.net>
parents:
2162
diff
changeset
|
455 (unaryfunc)NULL, /*int*/ |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
456 #if !PY3 |
|
2163
a7c8f262d2e6
Include edits missed in previous commit.
Lenard Lindstrom <len-l@telus.net>
parents:
2162
diff
changeset
|
457 (unaryfunc)NULL, /*long*/ |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
458 #endif |
|
2163
a7c8f262d2e6
Include edits missed in previous commit.
Lenard Lindstrom <len-l@telus.net>
parents:
2162
diff
changeset
|
459 (unaryfunc)NULL, /*float*/ |
| 352 | 460 }; |
| 151 | 461 |
|
2164
4ab5917b771e
Implements Motherhamster Bugzilla feature request 62: Allow attribute assignment to event type
Lenard Lindstrom <len-l@telus.net>
parents:
2163
diff
changeset
|
462 #define OFF(x) offsetof(PyEventObject, x) |
|
4ab5917b771e
Implements Motherhamster Bugzilla feature request 62: Allow attribute assignment to event type
Lenard Lindstrom <len-l@telus.net>
parents:
2163
diff
changeset
|
463 |
|
4ab5917b771e
Implements Motherhamster Bugzilla feature request 62: Allow attribute assignment to event type
Lenard Lindstrom <len-l@telus.net>
parents:
2163
diff
changeset
|
464 static PyMemberDef event_members[] = { |
|
4ab5917b771e
Implements Motherhamster Bugzilla feature request 62: Allow attribute assignment to event type
Lenard Lindstrom <len-l@telus.net>
parents:
2163
diff
changeset
|
465 {"__dict__", T_OBJECT, OFF(dict), READONLY}, |
|
4ab5917b771e
Implements Motherhamster Bugzilla feature request 62: Allow attribute assignment to event type
Lenard Lindstrom <len-l@telus.net>
parents:
2163
diff
changeset
|
466 {"type", T_INT, OFF(type), READONLY}, |
|
4ab5917b771e
Implements Motherhamster Bugzilla feature request 62: Allow attribute assignment to event type
Lenard Lindstrom <len-l@telus.net>
parents:
2163
diff
changeset
|
467 {"dict", T_OBJECT, OFF(dict), READONLY}, |
|
4ab5917b771e
Implements Motherhamster Bugzilla feature request 62: Allow attribute assignment to event type
Lenard Lindstrom <len-l@telus.net>
parents:
2163
diff
changeset
|
468 {NULL} /* Sentinel */ |
|
4ab5917b771e
Implements Motherhamster Bugzilla feature request 62: Allow attribute assignment to event type
Lenard Lindstrom <len-l@telus.net>
parents:
2163
diff
changeset
|
469 }; |
|
4ab5917b771e
Implements Motherhamster Bugzilla feature request 62: Allow attribute assignment to event type
Lenard Lindstrom <len-l@telus.net>
parents:
2163
diff
changeset
|
470 |
|
1548
9379bdac652e
add event object comparison as per mailing list request
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
471 /* |
|
9379bdac652e
add event object comparison as per mailing list request
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
472 * eventA == eventB |
|
9379bdac652e
add event object comparison as per mailing list request
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
473 * eventA != eventB |
|
9379bdac652e
add event object comparison as per mailing list request
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
474 */ |
|
9379bdac652e
add event object comparison as per mailing list request
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
475 static PyObject* |
|
9379bdac652e
add event object comparison as per mailing list request
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
476 event_richcompare(PyObject *o1, PyObject *o2, int opid) |
|
9379bdac652e
add event object comparison as per mailing list request
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
477 { |
|
9379bdac652e
add event object comparison as per mailing list request
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
478 PyEventObject *e1, *e2; |
|
9379bdac652e
add event object comparison as per mailing list request
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
479 |
|
9379bdac652e
add event object comparison as per mailing list request
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
480 if (!PyEvent_Check(o1) || !PyEvent_Check(o2)) |
|
9379bdac652e
add event object comparison as per mailing list request
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
481 { |
|
2162
9e86b65470f9
Tidy up white space in event.c in preparation to update attribute handling
Lenard Lindstrom <len-l@telus.net>
parents:
2146
diff
changeset
|
482 goto Unimplemented; |
|
1548
9379bdac652e
add event object comparison as per mailing list request
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
483 } |
|
9379bdac652e
add event object comparison as per mailing list request
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
484 |
|
9379bdac652e
add event object comparison as per mailing list request
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
485 e1 = (PyEventObject *) o1; |
|
9379bdac652e
add event object comparison as per mailing list request
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
486 e2 = (PyEventObject *) o2; |
|
9379bdac652e
add event object comparison as per mailing list request
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
487 switch (opid) |
|
9379bdac652e
add event object comparison as per mailing list request
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
488 { |
|
9379bdac652e
add event object comparison as per mailing list request
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
489 case Py_EQ: |
|
9379bdac652e
add event object comparison as per mailing list request
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
490 return PyBool_FromLong (e1->type == e2->type && |
|
2162
9e86b65470f9
Tidy up white space in event.c in preparation to update attribute handling
Lenard Lindstrom <len-l@telus.net>
parents:
2146
diff
changeset
|
491 PyObject_RichCompareBool (e1->dict, |
|
9e86b65470f9
Tidy up white space in event.c in preparation to update attribute handling
Lenard Lindstrom <len-l@telus.net>
parents:
2146
diff
changeset
|
492 e2->dict, |
|
9e86b65470f9
Tidy up white space in event.c in preparation to update attribute handling
Lenard Lindstrom <len-l@telus.net>
parents:
2146
diff
changeset
|
493 Py_EQ) == 1); |
|
1548
9379bdac652e
add event object comparison as per mailing list request
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
494 case Py_NE: |
|
9379bdac652e
add event object comparison as per mailing list request
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
495 return PyBool_FromLong (e1->type != e2->type || |
|
2162
9e86b65470f9
Tidy up white space in event.c in preparation to update attribute handling
Lenard Lindstrom <len-l@telus.net>
parents:
2146
diff
changeset
|
496 PyObject_RichCompareBool (e1->dict, |
|
9e86b65470f9
Tidy up white space in event.c in preparation to update attribute handling
Lenard Lindstrom <len-l@telus.net>
parents:
2146
diff
changeset
|
497 e2->dict, |
|
9e86b65470f9
Tidy up white space in event.c in preparation to update attribute handling
Lenard Lindstrom <len-l@telus.net>
parents:
2146
diff
changeset
|
498 Py_NE) == 1); |
|
1548
9379bdac652e
add event object comparison as per mailing list request
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
499 default: |
|
9379bdac652e
add event object comparison as per mailing list request
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
500 break; |
|
9379bdac652e
add event object comparison as per mailing list request
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
501 } |
|
9379bdac652e
add event object comparison as per mailing list request
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
502 |
|
9379bdac652e
add event object comparison as per mailing list request
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
503 Unimplemented: |
|
9379bdac652e
add event object comparison as per mailing list request
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
504 Py_INCREF (Py_NotImplemented); |
|
9379bdac652e
add event object comparison as per mailing list request
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
505 return Py_NotImplemented; |
|
9379bdac652e
add event object comparison as per mailing list request
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
506 } |
|
9379bdac652e
add event object comparison as per mailing list request
Lenard Lindstrom <len-l@telus.net>
parents:
1499
diff
changeset
|
507 |
| 151 | 508 |
| 7 | 509 static PyTypeObject PyEvent_Type = |
| 510 { | |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
511 TYPE_HEAD (NULL, 0) |
|
2163
a7c8f262d2e6
Include edits missed in previous commit.
Lenard Lindstrom <len-l@telus.net>
parents:
2162
diff
changeset
|
512 "Event", /*name*/ |
|
a7c8f262d2e6
Include edits missed in previous commit.
Lenard Lindstrom <len-l@telus.net>
parents:
2162
diff
changeset
|
513 sizeof(PyEventObject), /*basic size*/ |
|
a7c8f262d2e6
Include edits missed in previous commit.
Lenard Lindstrom <len-l@telus.net>
parents:
2162
diff
changeset
|
514 0, /*itemsize*/ |
|
a7c8f262d2e6
Include edits missed in previous commit.
Lenard Lindstrom <len-l@telus.net>
parents:
2162
diff
changeset
|
515 event_dealloc, /*dealloc*/ |
|
a7c8f262d2e6
Include edits missed in previous commit.
Lenard Lindstrom <len-l@telus.net>
parents:
2162
diff
changeset
|
516 0, /*print*/ |
|
2164
4ab5917b771e
Implements Motherhamster Bugzilla feature request 62: Allow attribute assignment to event type
Lenard Lindstrom <len-l@telus.net>
parents:
2163
diff
changeset
|
517 0, /*getattr*/ |
|
4ab5917b771e
Implements Motherhamster Bugzilla feature request 62: Allow attribute assignment to event type
Lenard Lindstrom <len-l@telus.net>
parents:
2163
diff
changeset
|
518 0, /*setattr*/ |
|
4ab5917b771e
Implements Motherhamster Bugzilla feature request 62: Allow attribute assignment to event type
Lenard Lindstrom <len-l@telus.net>
parents:
2163
diff
changeset
|
519 0, /*compare*/ |
|
2163
a7c8f262d2e6
Include edits missed in previous commit.
Lenard Lindstrom <len-l@telus.net>
parents:
2162
diff
changeset
|
520 event_str, /*repr*/ |
|
2162
9e86b65470f9
Tidy up white space in event.c in preparation to update attribute handling
Lenard Lindstrom <len-l@telus.net>
parents:
2146
diff
changeset
|
521 &event_as_number, /*as_number*/ |
|
2164
4ab5917b771e
Implements Motherhamster Bugzilla feature request 62: Allow attribute assignment to event type
Lenard Lindstrom <len-l@telus.net>
parents:
2163
diff
changeset
|
522 0, /*as_sequence*/ |
|
4ab5917b771e
Implements Motherhamster Bugzilla feature request 62: Allow attribute assignment to event type
Lenard Lindstrom <len-l@telus.net>
parents:
2163
diff
changeset
|
523 0, /*as_mapping*/ |
|
2163
a7c8f262d2e6
Include edits missed in previous commit.
Lenard Lindstrom <len-l@telus.net>
parents:
2162
diff
changeset
|
524 (hashfunc)NULL, /*hash*/ |
|
a7c8f262d2e6
Include edits missed in previous commit.
Lenard Lindstrom <len-l@telus.net>
parents:
2162
diff
changeset
|
525 (ternaryfunc)NULL, /*call*/ |
|
a7c8f262d2e6
Include edits missed in previous commit.
Lenard Lindstrom <len-l@telus.net>
parents:
2162
diff
changeset
|
526 (reprfunc)NULL, /*str*/ |
|
2164
4ab5917b771e
Implements Motherhamster Bugzilla feature request 62: Allow attribute assignment to event type
Lenard Lindstrom <len-l@telus.net>
parents:
2163
diff
changeset
|
527 PyObject_GenericGetAttr, /* tp_getattro */ |
|
4ab5917b771e
Implements Motherhamster Bugzilla feature request 62: Allow attribute assignment to event type
Lenard Lindstrom <len-l@telus.net>
parents:
2163
diff
changeset
|
528 PyObject_GenericSetAttr, /* tp_setattro */ |
|
2163
a7c8f262d2e6
Include edits missed in previous commit.
Lenard Lindstrom <len-l@telus.net>
parents:
2162
diff
changeset
|
529 0, /* tp_as_buffer */ |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
530 #if PY3 |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
531 0, |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
532 #else |
|
2164
4ab5917b771e
Implements Motherhamster Bugzilla feature request 62: Allow attribute assignment to event type
Lenard Lindstrom <len-l@telus.net>
parents:
2163
diff
changeset
|
533 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_RICHCOMPARE, |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
534 #endif |
|
2163
a7c8f262d2e6
Include edits missed in previous commit.
Lenard Lindstrom <len-l@telus.net>
parents:
2162
diff
changeset
|
535 DOC_PYGAMEEVENTEVENT, /* Documentation string */ |
|
a7c8f262d2e6
Include edits missed in previous commit.
Lenard Lindstrom <len-l@telus.net>
parents:
2162
diff
changeset
|
536 0, /* tp_traverse */ |
|
a7c8f262d2e6
Include edits missed in previous commit.
Lenard Lindstrom <len-l@telus.net>
parents:
2162
diff
changeset
|
537 0, /* tp_clear */ |
|
a7c8f262d2e6
Include edits missed in previous commit.
Lenard Lindstrom <len-l@telus.net>
parents:
2162
diff
changeset
|
538 event_richcompare, /* tp_richcompare */ |
|
2164
4ab5917b771e
Implements Motherhamster Bugzilla feature request 62: Allow attribute assignment to event type
Lenard Lindstrom <len-l@telus.net>
parents:
2163
diff
changeset
|
539 0, /* tp_weaklistoffset */ |
|
4ab5917b771e
Implements Motherhamster Bugzilla feature request 62: Allow attribute assignment to event type
Lenard Lindstrom <len-l@telus.net>
parents:
2163
diff
changeset
|
540 0, /* tp_iter */ |
|
4ab5917b771e
Implements Motherhamster Bugzilla feature request 62: Allow attribute assignment to event type
Lenard Lindstrom <len-l@telus.net>
parents:
2163
diff
changeset
|
541 0, /* tp_iternext */ |
|
4ab5917b771e
Implements Motherhamster Bugzilla feature request 62: Allow attribute assignment to event type
Lenard Lindstrom <len-l@telus.net>
parents:
2163
diff
changeset
|
542 0, /* tp_methods */ |
|
4ab5917b771e
Implements Motherhamster Bugzilla feature request 62: Allow attribute assignment to event type
Lenard Lindstrom <len-l@telus.net>
parents:
2163
diff
changeset
|
543 event_members, /* tp_members */ |
|
4ab5917b771e
Implements Motherhamster Bugzilla feature request 62: Allow attribute assignment to event type
Lenard Lindstrom <len-l@telus.net>
parents:
2163
diff
changeset
|
544 0, /* tp_getset */ |
|
4ab5917b771e
Implements Motherhamster Bugzilla feature request 62: Allow attribute assignment to event type
Lenard Lindstrom <len-l@telus.net>
parents:
2163
diff
changeset
|
545 0, /* tp_base */ |
|
4ab5917b771e
Implements Motherhamster Bugzilla feature request 62: Allow attribute assignment to event type
Lenard Lindstrom <len-l@telus.net>
parents:
2163
diff
changeset
|
546 0, /* tp_dict */ |
|
4ab5917b771e
Implements Motherhamster Bugzilla feature request 62: Allow attribute assignment to event type
Lenard Lindstrom <len-l@telus.net>
parents:
2163
diff
changeset
|
547 0, /* tp_descr_get */ |
|
4ab5917b771e
Implements Motherhamster Bugzilla feature request 62: Allow attribute assignment to event type
Lenard Lindstrom <len-l@telus.net>
parents:
2163
diff
changeset
|
548 0, /* tp_descr_set */ |
|
4ab5917b771e
Implements Motherhamster Bugzilla feature request 62: Allow attribute assignment to event type
Lenard Lindstrom <len-l@telus.net>
parents:
2163
diff
changeset
|
549 offsetof(PyEventObject, dict), /* tp_dictoffset */ |
|
4ab5917b771e
Implements Motherhamster Bugzilla feature request 62: Allow attribute assignment to event type
Lenard Lindstrom <len-l@telus.net>
parents:
2163
diff
changeset
|
550 0, /* tp_init */ |
|
4ab5917b771e
Implements Motherhamster Bugzilla feature request 62: Allow attribute assignment to event type
Lenard Lindstrom <len-l@telus.net>
parents:
2163
diff
changeset
|
551 0, /* tp_alloc */ |
|
4ab5917b771e
Implements Motherhamster Bugzilla feature request 62: Allow attribute assignment to event type
Lenard Lindstrom <len-l@telus.net>
parents:
2163
diff
changeset
|
552 0, /* tp_new */ |
| 7 | 553 }; |
| 554 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
555 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
556 PyEvent_New (SDL_Event* event) |
| 7 | 557 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
558 PyEventObject* e; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
559 e = PyObject_NEW (PyEventObject, &PyEvent_Type); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
560 if(!e) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
561 return NULL; |
| 7 | 562 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
563 if (event) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
564 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
565 e->type = event->type; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
566 e->dict = dict_from_event (event); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
567 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
568 else |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
569 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
570 e->type = SDL_NOEVENT; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
571 e->dict = PyDict_New (); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
572 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
573 return (PyObject*)e; |
| 7 | 574 } |
| 575 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
576 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
577 PyEvent_New2 (int type, PyObject* dict) |
| 7 | 578 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
579 PyEventObject* e; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
580 e = PyObject_NEW (PyEventObject, &PyEvent_Type); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
581 if (e) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
582 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
583 e->type = type; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
584 if (!dict) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
585 dict = PyDict_New (); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
586 else |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
587 Py_INCREF (dict); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
588 e->dict = dict; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
589 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
590 return (PyObject*)e; |
| 7 | 591 } |
| 592 | |
| 593 /* event module functions */ | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
594 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
595 Event (PyObject* self, PyObject* arg, PyObject* keywords) |
| 7 | 596 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
597 PyObject* dict = NULL; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
598 PyObject* event; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
599 int type; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
600 if (!PyArg_ParseTuple (arg, "i|O!", &type, &PyDict_Type, &dict)) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
601 return NULL; |
| 172 | 602 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
603 if (!dict) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
604 dict = PyDict_New (); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
605 else |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
606 Py_INCREF (dict); |
| 172 | 607 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
608 if (keywords) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
609 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
610 PyObject *key, *value; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
611 Py_ssize_t pos = 0; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
612 while (PyDict_Next (keywords, &pos, &key, &value)) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
613 PyDict_SetItem (dict, key, value); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
614 } |
| 172 | 615 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
616 event = PyEvent_New2 (type, dict); |
| 172 | 617 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
618 Py_DECREF (dict); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
619 return event; |
| 7 | 620 } |
| 621 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
622 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
623 event_name (PyObject* self, PyObject* arg) |
| 7 | 624 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
625 int type; |
| 7 | 626 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
627 if (!PyArg_ParseTuple (arg, "i", &type)) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
628 return NULL; |
| 7 | 629 |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
630 return Text_FromUTF8 (name_from_eventtype (type)); |
| 7 | 631 } |
| 632 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
633 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
634 set_grab (PyObject* self, PyObject* arg) |
| 7 | 635 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
636 int doit; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
637 if (!PyArg_ParseTuple (arg, "i", &doit)) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
638 return NULL; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
639 VIDEO_INIT_CHECK (); |
| 7 | 640 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
641 if (doit) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
642 SDL_WM_GrabInput (SDL_GRAB_ON); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
643 else |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
644 SDL_WM_GrabInput (SDL_GRAB_OFF); |
| 7 | 645 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
646 Py_RETURN_NONE; |
| 7 | 647 } |
| 648 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
649 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
650 get_grab (PyObject* self, PyObject* arg) |
| 7 | 651 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
652 int mode; |
| 7 | 653 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
654 VIDEO_INIT_CHECK (); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
655 mode = SDL_WM_GrabInput (SDL_GRAB_QUERY); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
656 return PyInt_FromLong (mode == SDL_GRAB_ON); |
| 7 | 657 } |
| 658 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
659 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
660 pygame_pump (PyObject* self, PyObject* args) |
| 7 | 661 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
662 VIDEO_INIT_CHECK (); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
663 SDL_PumpEvents (); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
664 Py_RETURN_NONE; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
665 } |
| 7 | 666 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
667 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
668 pygame_wait (PyObject* self, PyObject* args) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
669 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
670 SDL_Event event; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
671 int status; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
672 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
673 VIDEO_INIT_CHECK (); |
| 7 | 674 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
675 Py_BEGIN_ALLOW_THREADS; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
676 status = SDL_WaitEvent (&event); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
677 Py_END_ALLOW_THREADS; |
| 7 | 678 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
679 if (!status) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
680 return RAISE (PyExc_SDLError, SDL_GetError ()); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
681 |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
682 return PyEvent_New (&event); |
| 7 | 683 } |
| 684 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
685 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
686 pygame_poll (PyObject* self, PyObject* args) |
| 7 | 687 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
688 SDL_Event event; |
| 15 | 689 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
690 VIDEO_INIT_CHECK (); |
| 7 | 691 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
692 if (SDL_PollEvent (&event)) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
693 return PyEvent_New (&event); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
694 return PyEvent_New (NULL); |
| 7 | 695 } |
| 696 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
697 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
698 event_clear (PyObject* self, PyObject* args) |
| 424 | 699 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
700 SDL_Event event; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
701 int mask = 0; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
702 int loop, num; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
703 PyObject* type; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
704 int val; |
| 424 | 705 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
706 if (PyTuple_Size (args) != 0 && PyTuple_Size (args) != 1) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
707 return RAISE (PyExc_ValueError, "get requires 0 or 1 argument"); |
| 424 | 708 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
709 VIDEO_INIT_CHECK (); |
| 424 | 710 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
711 if (PyTuple_Size (args) == 0) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
712 mask = SDL_ALLEVENTS; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
713 else |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
714 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
715 type = PyTuple_GET_ITEM (args, 0); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
716 if(PySequence_Check (type)) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
717 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
718 num = PySequence_Size (type); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
719 for(loop = 0; loop < num; ++loop) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
720 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
721 if (!IntFromObjIndex (type, loop, &val)) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
722 return RAISE |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
723 (PyExc_TypeError, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
724 "type sequence must contain valid event types"); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
725 mask |= SDL_EVENTMASK (val); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
726 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
727 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
728 else if (IntFromObj (type, &val)) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
729 mask = SDL_EVENTMASK (val); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
730 else |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
731 return RAISE (PyExc_TypeError, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
732 "get type must be numeric or a sequence"); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
733 } |
| 424 | 734 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
735 SDL_PumpEvents (); |
| 424 | 736 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
737 while (SDL_PeepEvents (&event, 1, SDL_GETEVENT, mask) == 1) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
738 {} |
| 424 | 739 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
740 Py_RETURN_NONE; |
| 424 | 741 } |
| 742 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
743 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
744 event_get (PyObject* self, PyObject* args) |
| 7 | 745 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
746 SDL_Event event; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
747 int mask = 0; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
748 int loop, num; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
749 PyObject* type, *list, *e; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
750 int val; |
| 7 | 751 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
752 if (PyTuple_Size (args) != 0 && PyTuple_Size (args) != 1) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
753 return RAISE (PyExc_ValueError, "get requires 0 or 1 argument"); |
| 7 | 754 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
755 VIDEO_INIT_CHECK (); |
| 7 | 756 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
757 if (PyTuple_Size (args) == 0) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
758 mask = SDL_ALLEVENTS; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
759 else |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
760 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
761 type = PyTuple_GET_ITEM (args, 0); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
762 if (PySequence_Check (type)) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
763 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
764 num = PySequence_Size (type); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
765 for(loop = 0; loop < num; ++loop) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
766 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
767 if (!IntFromObjIndex (type, loop, &val)) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
768 return RAISE |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
769 (PyExc_TypeError, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
770 "type sequence must contain valid event types"); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
771 mask |= SDL_EVENTMASK (val); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
772 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
773 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
774 else if (IntFromObj (type, &val)) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
775 mask = SDL_EVENTMASK (val); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
776 else |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
777 return RAISE (PyExc_TypeError, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
778 "get type must be numeric or a sequence"); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
779 } |
| 481 | 780 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
781 list = PyList_New (0); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
782 if (!list) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
783 return NULL; |
| 7 | 784 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
785 SDL_PumpEvents (); |
| 7 | 786 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
787 while (SDL_PeepEvents (&event, 1, SDL_GETEVENT, mask) == 1) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
788 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
789 e = PyEvent_New (&event); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
790 if (!e) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
791 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
792 Py_DECREF (list); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
793 return NULL; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
794 } |
| 7 | 795 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
796 PyList_Append (list, e); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
797 Py_DECREF (e); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
798 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
799 return list; |
| 7 | 800 } |
| 801 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
802 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
803 event_peek (PyObject* self, PyObject* args) |
| 7 | 804 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
805 SDL_Event event; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
806 int result; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
807 int mask = 0; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
808 int loop, num, noargs=0; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
809 PyObject* type; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
810 int val; |
| 7 | 811 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
812 if (PyTuple_Size (args) != 0 && PyTuple_Size (args) != 1) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
813 return RAISE (PyExc_ValueError, "peek requires 0 or 1 argument"); |
| 7 | 814 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
815 VIDEO_INIT_CHECK (); |
| 7 | 816 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
817 if (PyTuple_Size (args) == 0) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
818 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
819 mask = SDL_ALLEVENTS; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
820 noargs=1; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
821 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
822 else |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
823 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
824 type = PyTuple_GET_ITEM (args, 0); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
825 if(PySequence_Check (type)) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
826 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
827 num = PySequence_Size (type); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
828 for(loop = 0; loop < num; ++loop) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
829 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
830 if (!IntFromObjIndex (type, loop, &val)) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
831 return RAISE |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
832 (PyExc_TypeError, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
833 "type sequence must contain valid event types"); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
834 mask |= SDL_EVENTMASK (val); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
835 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
836 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
837 else if (IntFromObj (type, &val)) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
838 mask = SDL_EVENTMASK (val); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
839 else |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
840 return RAISE (PyExc_TypeError, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
841 "peek type must be numeric or a sequence"); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
842 } |
| 481 | 843 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
844 SDL_PumpEvents (); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
845 result = SDL_PeepEvents (&event, 1, SDL_PEEKEVENT, mask); |
| 352 | 846 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
847 if (noargs) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
848 return PyEvent_New (&event); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
849 return PyInt_FromLong (result == 1); |
| 7 | 850 } |
| 851 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
852 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
853 event_post (PyObject* self, PyObject* args) |
| 7 | 854 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
855 PyEventObject* e; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
856 SDL_Event event; |
|
1272
c94848696dde
Added fix for event.set_blocked not working for posted events.
Rene Dudfield <renesd@gmail.com>
parents:
863
diff
changeset
|
857 int isblocked = 0; |
| 7 | 858 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
859 if (!PyArg_ParseTuple (args, "O!", &PyEvent_Type, &e)) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
860 return NULL; |
| 7 | 861 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
862 VIDEO_INIT_CHECK (); |
| 7 | 863 |
|
1272
c94848696dde
Added fix for event.set_blocked not working for posted events.
Rene Dudfield <renesd@gmail.com>
parents:
863
diff
changeset
|
864 |
|
c94848696dde
Added fix for event.set_blocked not working for posted events.
Rene Dudfield <renesd@gmail.com>
parents:
863
diff
changeset
|
865 /* see if the event is blocked before posting it. */ |
|
2162
9e86b65470f9
Tidy up white space in event.c in preparation to update attribute handling
Lenard Lindstrom <len-l@telus.net>
parents:
2146
diff
changeset
|
866 isblocked = SDL_EventState (e->type, SDL_QUERY) == SDL_IGNORE; |
|
1272
c94848696dde
Added fix for event.set_blocked not working for posted events.
Rene Dudfield <renesd@gmail.com>
parents:
863
diff
changeset
|
867 |
|
2164
4ab5917b771e
Implements Motherhamster Bugzilla feature request 62: Allow attribute assignment to event type
Lenard Lindstrom <len-l@telus.net>
parents:
2163
diff
changeset
|
868 if (isblocked) { |
|
4ab5917b771e
Implements Motherhamster Bugzilla feature request 62: Allow attribute assignment to event type
Lenard Lindstrom <len-l@telus.net>
parents:
2163
diff
changeset
|
869 /* event is blocked, so we do not post it. */ |
|
1272
c94848696dde
Added fix for event.set_blocked not working for posted events.
Rene Dudfield <renesd@gmail.com>
parents:
863
diff
changeset
|
870 Py_RETURN_NONE; |
|
c94848696dde
Added fix for event.set_blocked not working for posted events.
Rene Dudfield <renesd@gmail.com>
parents:
863
diff
changeset
|
871 } |
|
c94848696dde
Added fix for event.set_blocked not working for posted events.
Rene Dudfield <renesd@gmail.com>
parents:
863
diff
changeset
|
872 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
873 if (PyEvent_FillUserEvent (e, &event)) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
874 return NULL; |
| 231 | 875 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
876 if (SDL_PushEvent (&event) == -1) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
877 return RAISE (PyExc_SDLError, "Event queue full"); |
| 7 | 878 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
879 Py_RETURN_NONE; |
| 7 | 880 } |
| 881 | |
|
863
6cf1fbb0772c
fixes to compile on windows (toolkit compiler) and some bounds checking on event calls to prevent buffer over-runs (thanks to John Popplewell)
brian
parents:
831
diff
changeset
|
882 static int |
|
6cf1fbb0772c
fixes to compile on windows (toolkit compiler) and some bounds checking on event calls to prevent buffer over-runs (thanks to John Popplewell)
brian
parents:
831
diff
changeset
|
883 CheckEventInRange(int evt) |
|
6cf1fbb0772c
fixes to compile on windows (toolkit compiler) and some bounds checking on event calls to prevent buffer over-runs (thanks to John Popplewell)
brian
parents:
831
diff
changeset
|
884 { |
|
6cf1fbb0772c
fixes to compile on windows (toolkit compiler) and some bounds checking on event calls to prevent buffer over-runs (thanks to John Popplewell)
brian
parents:
831
diff
changeset
|
885 return evt >= 0 && evt < SDL_NUMEVENTS; |
|
6cf1fbb0772c
fixes to compile on windows (toolkit compiler) and some bounds checking on event calls to prevent buffer over-runs (thanks to John Popplewell)
brian
parents:
831
diff
changeset
|
886 } |
|
6cf1fbb0772c
fixes to compile on windows (toolkit compiler) and some bounds checking on event calls to prevent buffer over-runs (thanks to John Popplewell)
brian
parents:
831
diff
changeset
|
887 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
888 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
889 set_allowed (PyObject* self, PyObject* args) |
| 7 | 890 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
891 int loop, num; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
892 PyObject* type; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
893 int val; |
| 7 | 894 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
895 if (PyTuple_Size (args) != 1) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
896 return RAISE (PyExc_ValueError, "set_allowed requires 1 argument"); |
| 7 | 897 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
898 VIDEO_INIT_CHECK (); |
| 7 | 899 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
900 type = PyTuple_GET_ITEM (args, 0); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
901 if (PySequence_Check (type)) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
902 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
903 num = PySequence_Length (type); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
904 for(loop = 0; loop < num; ++loop) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
905 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
906 if (!IntFromObjIndex (type, loop, &val)) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
907 return RAISE (PyExc_TypeError, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
908 "type sequence must contain valid event types"); |
|
863
6cf1fbb0772c
fixes to compile on windows (toolkit compiler) and some bounds checking on event calls to prevent buffer over-runs (thanks to John Popplewell)
brian
parents:
831
diff
changeset
|
909 if(!CheckEventInRange(val)) |
|
6cf1fbb0772c
fixes to compile on windows (toolkit compiler) and some bounds checking on event calls to prevent buffer over-runs (thanks to John Popplewell)
brian
parents:
831
diff
changeset
|
910 return RAISE (PyExc_ValueError, "Invalid event in sequence"); |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
911 SDL_EventState ((Uint8)val, SDL_ENABLE); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
912 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
913 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
914 else if (type == Py_None) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
915 SDL_EventState ((Uint8)0xFF, SDL_IGNORE); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
916 else if (IntFromObj (type, &val)) |
|
863
6cf1fbb0772c
fixes to compile on windows (toolkit compiler) and some bounds checking on event calls to prevent buffer over-runs (thanks to John Popplewell)
brian
parents:
831
diff
changeset
|
917 { |
|
6cf1fbb0772c
fixes to compile on windows (toolkit compiler) and some bounds checking on event calls to prevent buffer over-runs (thanks to John Popplewell)
brian
parents:
831
diff
changeset
|
918 if(!CheckEventInRange (val)) |
|
6cf1fbb0772c
fixes to compile on windows (toolkit compiler) and some bounds checking on event calls to prevent buffer over-runs (thanks to John Popplewell)
brian
parents:
831
diff
changeset
|
919 return RAISE (PyExc_ValueError, "Invalid event"); |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
920 SDL_EventState ((Uint8)val, SDL_ENABLE); |
|
863
6cf1fbb0772c
fixes to compile on windows (toolkit compiler) and some bounds checking on event calls to prevent buffer over-runs (thanks to John Popplewell)
brian
parents:
831
diff
changeset
|
921 } |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
922 else |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
923 return RAISE (PyExc_TypeError, "type must be numeric or a sequence"); |
| 7 | 924 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
925 Py_RETURN_NONE; |
| 7 | 926 } |
| 927 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
928 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
929 set_blocked (PyObject* self, PyObject* args) |
| 7 | 930 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
931 int loop, num; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
932 PyObject* type; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
933 int val; |
| 7 | 934 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
935 if (PyTuple_Size (args) != 1) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
936 return RAISE (PyExc_ValueError, "set_blocked requires 1 argument"); |
| 7 | 937 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
938 VIDEO_INIT_CHECK (); |
| 7 | 939 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
940 type = PyTuple_GET_ITEM (args, 0); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
941 if (PySequence_Check (type)) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
942 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
943 num = PySequence_Length (type); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
944 for(loop = 0; loop < num; ++loop) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
945 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
946 if (!IntFromObjIndex (type, loop, &val)) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
947 return RAISE (PyExc_TypeError, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
948 "type sequence must contain valid event types"); |
|
863
6cf1fbb0772c
fixes to compile on windows (toolkit compiler) and some bounds checking on event calls to prevent buffer over-runs (thanks to John Popplewell)
brian
parents:
831
diff
changeset
|
949 if(!CheckEventInRange(val)) |
|
6cf1fbb0772c
fixes to compile on windows (toolkit compiler) and some bounds checking on event calls to prevent buffer over-runs (thanks to John Popplewell)
brian
parents:
831
diff
changeset
|
950 return RAISE (PyExc_ValueError, "Invalid event in sequence"); |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
951 SDL_EventState ((Uint8)val, SDL_IGNORE); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
952 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
953 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
954 else if (type == Py_None) |
|
863
6cf1fbb0772c
fixes to compile on windows (toolkit compiler) and some bounds checking on event calls to prevent buffer over-runs (thanks to John Popplewell)
brian
parents:
831
diff
changeset
|
955 SDL_EventState ((Uint8)0xFF, SDL_IGNORE); |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
956 else if (IntFromObj (type, &val)) |
|
863
6cf1fbb0772c
fixes to compile on windows (toolkit compiler) and some bounds checking on event calls to prevent buffer over-runs (thanks to John Popplewell)
brian
parents:
831
diff
changeset
|
957 { |
|
6cf1fbb0772c
fixes to compile on windows (toolkit compiler) and some bounds checking on event calls to prevent buffer over-runs (thanks to John Popplewell)
brian
parents:
831
diff
changeset
|
958 if(!CheckEventInRange (val)) |
|
6cf1fbb0772c
fixes to compile on windows (toolkit compiler) and some bounds checking on event calls to prevent buffer over-runs (thanks to John Popplewell)
brian
parents:
831
diff
changeset
|
959 return RAISE (PyExc_ValueError, "Invalid event"); |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
960 SDL_EventState ((Uint8)val, SDL_IGNORE); |
|
863
6cf1fbb0772c
fixes to compile on windows (toolkit compiler) and some bounds checking on event calls to prevent buffer over-runs (thanks to John Popplewell)
brian
parents:
831
diff
changeset
|
961 } |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
962 else |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
963 return RAISE (PyExc_TypeError, "type must be numeric or a sequence"); |
| 7 | 964 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
965 Py_RETURN_NONE; |
| 7 | 966 } |
| 967 | |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
968 static PyObject* |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
969 get_blocked (PyObject* self, PyObject* args) |
| 233 | 970 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
971 int loop, num; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
972 PyObject* type; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
973 int val; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
974 int isblocked = 0; |
| 233 | 975 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
976 if (PyTuple_Size (args) != 1) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
977 return RAISE (PyExc_ValueError, "get_blocked requires 1 argument"); |
| 233 | 978 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
979 VIDEO_INIT_CHECK (); |
| 233 | 980 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
981 type = PyTuple_GET_ITEM (args, 0); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
982 if (PySequence_Check (type)) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
983 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
984 num = PySequence_Length (type); |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
985 for (loop = 0; loop < num; ++loop) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
986 { |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
987 if (!IntFromObjIndex (type, loop, &val)) |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
988 return RAISE (PyExc_TypeError, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
989 "type sequence must contain valid event types"); |
|
863
6cf1fbb0772c
fixes to compile on windows (toolkit compiler) and some bounds checking on event calls to prevent buffer over-runs (thanks to John Popplewell)
brian
parents:
831
diff
changeset
|
990 if(!CheckEventInRange(val)) |
|
6cf1fbb0772c
fixes to compile on windows (toolkit compiler) and some bounds checking on event calls to prevent buffer over-runs (thanks to John Popplewell)
brian
parents:
831
diff
changeset
|
991 return RAISE (PyExc_ValueError, "Invalid event in sequence"); |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
992 isblocked |= SDL_EventState ((Uint8)val, SDL_QUERY) == SDL_IGNORE; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
993 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
994 } |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
995 else if (IntFromObj (type, &val)) |
|
863
6cf1fbb0772c
fixes to compile on windows (toolkit compiler) and some bounds checking on event calls to prevent buffer over-runs (thanks to John Popplewell)
brian
parents:
831
diff
changeset
|
996 { |
|
6cf1fbb0772c
fixes to compile on windows (toolkit compiler) and some bounds checking on event calls to prevent buffer over-runs (thanks to John Popplewell)
brian
parents:
831
diff
changeset
|
997 if(!CheckEventInRange (val)) |
|
6cf1fbb0772c
fixes to compile on windows (toolkit compiler) and some bounds checking on event calls to prevent buffer over-runs (thanks to John Popplewell)
brian
parents:
831
diff
changeset
|
998 return RAISE (PyExc_ValueError, "Invalid event"); |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
999 isblocked = SDL_EventState ((Uint8)val, SDL_QUERY) == SDL_IGNORE; |
|
863
6cf1fbb0772c
fixes to compile on windows (toolkit compiler) and some bounds checking on event calls to prevent buffer over-runs (thanks to John Popplewell)
brian
parents:
831
diff
changeset
|
1000 } |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1001 else |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1002 return RAISE (PyExc_TypeError, "type must be numeric or a sequence"); |
| 233 | 1003 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1004 return PyInt_FromLong (isblocked); |
| 233 | 1005 } |
| 1006 | |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
1007 static PyMethodDef _event_methods[] = |
| 7 | 1008 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1009 { "Event", (PyCFunction)Event, 3, DOC_PYGAMEEVENTEVENT }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1010 { "event_name", event_name, METH_VARARGS, DOC_PYGAMEEVENTEVENTNAME }, |
| 7 | 1011 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1012 { "set_grab", set_grab, METH_VARARGS, DOC_PYGAMEEVENTSETGRAB }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1013 { "get_grab", (PyCFunction) get_grab, METH_NOARGS, DOC_PYGAMEEVENTGETGRAB }, |
| 7 | 1014 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1015 { "pump", (PyCFunction) pygame_pump, METH_NOARGS, DOC_PYGAMEEVENTPUMP }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1016 { "wait", (PyCFunction) pygame_wait, METH_NOARGS, DOC_PYGAMEEVENTWAIT }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1017 { "poll", (PyCFunction) pygame_poll, METH_NOARGS, DOC_PYGAMEEVENTPOLL }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1018 { "clear", event_clear, METH_VARARGS, DOC_PYGAMEEVENTCLEAR }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1019 { "get", event_get, METH_VARARGS, DOC_PYGAMEEVENTGET }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1020 { "peek", event_peek, METH_VARARGS, DOC_PYGAMEEVENTPEEK }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1021 { "post", event_post, METH_VARARGS, DOC_PYGAMEEVENTPOST }, |
| 7 | 1022 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1023 { "set_allowed", set_allowed, METH_VARARGS, DOC_PYGAMEEVENTSETALLOWED }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1024 { "set_blocked", set_blocked, METH_VARARGS, DOC_PYGAMEEVENTSETBLOCKED }, |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1025 { "get_blocked", get_blocked, METH_VARARGS, DOC_PYGAMEEVENTGETBLOCKED }, |
| 7 | 1026 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1027 { NULL, NULL, 0, NULL } |
| 7 | 1028 }; |
| 1029 | |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
1030 MODINIT_DEFINE (event) |
| 7 | 1031 { |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1032 PyObject *module, *dict, *apiobj; |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
1033 int ecode; |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1034 static void* c_api[PYGAMEAPI_EVENT_NUMSLOTS]; |
| 7 | 1035 |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
1036 #if PY3 |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
1037 static struct PyModuleDef _module = { |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
1038 PyModuleDef_HEAD_INIT, |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
1039 "event", |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
1040 DOC_PYGAMEEVENT, |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
1041 -1, |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
1042 _event_methods, |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
1043 NULL, NULL, NULL, NULL |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
1044 }; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
1045 #endif |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
1046 |
|
1499
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1272
diff
changeset
|
1047 /* 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:
1272
diff
changeset
|
1048 the module is not loaded. |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1272
diff
changeset
|
1049 */ |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1272
diff
changeset
|
1050 import_pygame_base (); |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1272
diff
changeset
|
1051 if (PyErr_Occurred ()) { |
|
2162
9e86b65470f9
Tidy up white space in event.c in preparation to update attribute handling
Lenard Lindstrom <len-l@telus.net>
parents:
2146
diff
changeset
|
1052 MODINIT_ERROR; |
|
1499
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1272
diff
changeset
|
1053 } |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1272
diff
changeset
|
1054 |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1272
diff
changeset
|
1055 /* type preparation */ |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
1056 if (PyType_Ready (&PyEvent_Type) < 0) { |
|
2162
9e86b65470f9
Tidy up white space in event.c in preparation to update attribute handling
Lenard Lindstrom <len-l@telus.net>
parents:
2146
diff
changeset
|
1057 MODINIT_ERROR; |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
1058 } |
| 7 | 1059 |
| 1060 /* create the module */ | |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
1061 #if PY3 |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
1062 module = PyModule_Create (&_module); |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
1063 #else |
|
1581
9f910eda60c5
Starting to merge in sybian_s60 branch... still going... you like break? Well then try and build this!
Rene Dudfield <renesd@gmail.com>
parents:
1553
diff
changeset
|
1064 module = Py_InitModule3 (MODPREFIX "event", _event_methods, DOC_PYGAMEEVENT); |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
1065 #endif |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1066 dict = PyModule_GetDict (module); |
| 7 | 1067 |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
1068 if (PyDict_SetItemString (dict, "EventType", |
|
2162
9e86b65470f9
Tidy up white space in event.c in preparation to update attribute handling
Lenard Lindstrom <len-l@telus.net>
parents:
2146
diff
changeset
|
1069 (PyObject *)&PyEvent_Type) == -1) { |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
1070 DECREF_MOD (module); |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
1071 MODINIT_ERROR; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
1072 } |
| 37 | 1073 |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1074 /* export the c api */ |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1075 c_api[0] = &PyEvent_Type; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1076 c_api[1] = PyEvent_New; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1077 c_api[2] = PyEvent_New2; |
|
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1078 c_api[3] = PyEvent_FillUserEvent; |
|
2120
42e2bde1a12c
Use capsule objects in preference to cobject objects. This allows Pygame to build an run from Python 3.2, which has to cobjects.
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
1079 apiobj = encapsulate_api (c_api, "event"); |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
1080 if (apiobj == NULL) { |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
1081 DECREF_MOD (module); |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
1082 MODINIT_ERROR; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
1083 } |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
1084 ecode = PyDict_SetItemString (dict, PYGAMEAPI_LOCAL_ENTRY, apiobj); |
|
831
8749d7c235f8
Changes from Marcus for ref counting bug fixes and
Rene Dudfield <renesd@gmail.com>
parents:
813
diff
changeset
|
1085 Py_DECREF (apiobj); |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
1086 if (ecode) { |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
1087 DECREF_MOD (module); |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
1088 MODINIT_ERROR; |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
1089 } |
| 7 | 1090 |
|
1553
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
1091 /* Assume if there are events in the user events list |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
1092 * there is also a registered cleanup callback for them. |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
1093 */ |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
1094 if (user_event_objects == NULL) { |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
1095 PyGame_RegisterQuit (user_event_cleanup); |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
1096 } |
|
ebd545641c8b
merging with python3 branch r 2048
Lenard Lindstrom <len-l@telus.net>
parents:
1548
diff
changeset
|
1097 MODINIT_RETURN (module); |
| 7 | 1098 } |
