Fix three PyChecker-detected gotchas.
[python/dscho.git] / Mac / Modules / evt / Evtmodule.c
blobed18f9c89419265a9b371780ef01c5ad40e7ac4f
2 /* =========================== Module Evt =========================== */
4 #include "Python.h"
8 #include "macglue.h"
9 #include "pymactoolbox.h"
11 #include <Events.h>
13 static PyObject *Evt_Error;
15 static PyObject *Evt_GetMouse(_self, _args)
16 PyObject *_self;
17 PyObject *_args;
19 PyObject *_res = NULL;
20 Point mouseLoc;
21 if (!PyArg_ParseTuple(_args, ""))
22 return NULL;
23 GetMouse(&mouseLoc);
24 _res = Py_BuildValue("O&",
25 PyMac_BuildPoint, mouseLoc);
26 return _res;
29 static PyObject *Evt_Button(_self, _args)
30 PyObject *_self;
31 PyObject *_args;
33 PyObject *_res = NULL;
34 Boolean _rv;
35 if (!PyArg_ParseTuple(_args, ""))
36 return NULL;
37 _rv = Button();
38 _res = Py_BuildValue("b",
39 _rv);
40 return _res;
43 static PyObject *Evt_StillDown(_self, _args)
44 PyObject *_self;
45 PyObject *_args;
47 PyObject *_res = NULL;
48 Boolean _rv;
49 if (!PyArg_ParseTuple(_args, ""))
50 return NULL;
51 _rv = StillDown();
52 _res = Py_BuildValue("b",
53 _rv);
54 return _res;
57 static PyObject *Evt_WaitMouseUp(_self, _args)
58 PyObject *_self;
59 PyObject *_args;
61 PyObject *_res = NULL;
62 Boolean _rv;
63 if (!PyArg_ParseTuple(_args, ""))
64 return NULL;
65 _rv = WaitMouseUp();
66 _res = Py_BuildValue("b",
67 _rv);
68 return _res;
71 static PyObject *Evt_TickCount(_self, _args)
72 PyObject *_self;
73 PyObject *_args;
75 PyObject *_res = NULL;
76 UInt32 _rv;
77 if (!PyArg_ParseTuple(_args, ""))
78 return NULL;
79 _rv = TickCount();
80 _res = Py_BuildValue("l",
81 _rv);
82 return _res;
85 static PyObject *Evt_GetCaretTime(_self, _args)
86 PyObject *_self;
87 PyObject *_args;
89 PyObject *_res = NULL;
90 UInt32 _rv;
91 if (!PyArg_ParseTuple(_args, ""))
92 return NULL;
93 _rv = GetCaretTime();
94 _res = Py_BuildValue("l",
95 _rv);
96 return _res;
99 static PyObject *Evt_GetKeys(_self, _args)
100 PyObject *_self;
101 PyObject *_args;
103 PyObject *_res = NULL;
104 KeyMap theKeys__out__;
105 if (!PyArg_ParseTuple(_args, ""))
106 return NULL;
107 GetKeys(theKeys__out__);
108 _res = Py_BuildValue("s#",
109 (char *)&theKeys__out__, (int)sizeof(KeyMap));
110 theKeys__error__: ;
111 return _res;
114 static PyObject *Evt_GetDblTime(_self, _args)
115 PyObject *_self;
116 PyObject *_args;
118 PyObject *_res = NULL;
119 UInt32 _rv;
120 if (!PyArg_ParseTuple(_args, ""))
121 return NULL;
122 _rv = GetDblTime();
123 _res = Py_BuildValue("l",
124 _rv);
125 return _res;
128 static PyObject *Evt_SetEventMask(_self, _args)
129 PyObject *_self;
130 PyObject *_args;
132 PyObject *_res = NULL;
133 EventMask value;
134 if (!PyArg_ParseTuple(_args, "H",
135 &value))
136 return NULL;
137 SetEventMask(value);
138 Py_INCREF(Py_None);
139 _res = Py_None;
140 return _res;
143 static PyObject *Evt_GetNextEvent(_self, _args)
144 PyObject *_self;
145 PyObject *_args;
147 PyObject *_res = NULL;
148 Boolean _rv;
149 EventMask eventMask;
150 EventRecord theEvent;
151 if (!PyArg_ParseTuple(_args, "H",
152 &eventMask))
153 return NULL;
154 _rv = GetNextEvent(eventMask,
155 &theEvent);
156 _res = Py_BuildValue("bO&",
157 _rv,
158 PyMac_BuildEventRecord, &theEvent);
159 return _res;
162 static PyObject *Evt_EventAvail(_self, _args)
163 PyObject *_self;
164 PyObject *_args;
166 PyObject *_res = NULL;
167 Boolean _rv;
168 EventMask eventMask;
169 EventRecord theEvent;
170 if (!PyArg_ParseTuple(_args, "H",
171 &eventMask))
172 return NULL;
173 _rv = EventAvail(eventMask,
174 &theEvent);
175 _res = Py_BuildValue("bO&",
176 _rv,
177 PyMac_BuildEventRecord, &theEvent);
178 return _res;
181 static PyObject *Evt_PostEvent(_self, _args)
182 PyObject *_self;
183 PyObject *_args;
185 PyObject *_res = NULL;
186 OSErr _err;
187 EventKind eventNum;
188 UInt32 eventMsg;
189 if (!PyArg_ParseTuple(_args, "Hl",
190 &eventNum,
191 &eventMsg))
192 return NULL;
193 _err = PostEvent(eventNum,
194 eventMsg);
195 if (_err != noErr) return PyMac_Error(_err);
196 Py_INCREF(Py_None);
197 _res = Py_None;
198 return _res;
201 #if !TARGET_API_MAC_CARBON
203 static PyObject *Evt_OSEventAvail(_self, _args)
204 PyObject *_self;
205 PyObject *_args;
207 PyObject *_res = NULL;
208 Boolean _rv;
209 EventMask mask;
210 EventRecord theEvent;
211 if (!PyArg_ParseTuple(_args, "H",
212 &mask))
213 return NULL;
214 _rv = OSEventAvail(mask,
215 &theEvent);
216 _res = Py_BuildValue("bO&",
217 _rv,
218 PyMac_BuildEventRecord, &theEvent);
219 return _res;
221 #endif
223 #if !TARGET_API_MAC_CARBON
225 static PyObject *Evt_GetOSEvent(_self, _args)
226 PyObject *_self;
227 PyObject *_args;
229 PyObject *_res = NULL;
230 Boolean _rv;
231 EventMask mask;
232 EventRecord theEvent;
233 if (!PyArg_ParseTuple(_args, "H",
234 &mask))
235 return NULL;
236 _rv = GetOSEvent(mask,
237 &theEvent);
238 _res = Py_BuildValue("bO&",
239 _rv,
240 PyMac_BuildEventRecord, &theEvent);
241 return _res;
243 #endif
245 static PyObject *Evt_FlushEvents(_self, _args)
246 PyObject *_self;
247 PyObject *_args;
249 PyObject *_res = NULL;
250 EventMask whichMask;
251 EventMask stopMask;
252 if (!PyArg_ParseTuple(_args, "HH",
253 &whichMask,
254 &stopMask))
255 return NULL;
256 FlushEvents(whichMask,
257 stopMask);
258 Py_INCREF(Py_None);
259 _res = Py_None;
260 return _res;
263 #if !TARGET_API_MAC_CARBON
265 static PyObject *Evt_SystemClick(_self, _args)
266 PyObject *_self;
267 PyObject *_args;
269 PyObject *_res = NULL;
270 EventRecord theEvent;
271 WindowPtr theWindow;
272 if (!PyArg_ParseTuple(_args, "O&O&",
273 PyMac_GetEventRecord, &theEvent,
274 WinObj_Convert, &theWindow))
275 return NULL;
276 SystemClick(&theEvent,
277 theWindow);
278 Py_INCREF(Py_None);
279 _res = Py_None;
280 return _res;
282 #endif
284 #if !TARGET_API_MAC_CARBON
286 static PyObject *Evt_SystemTask(_self, _args)
287 PyObject *_self;
288 PyObject *_args;
290 PyObject *_res = NULL;
291 if (!PyArg_ParseTuple(_args, ""))
292 return NULL;
293 SystemTask();
294 Py_INCREF(Py_None);
295 _res = Py_None;
296 return _res;
298 #endif
300 #if !TARGET_API_MAC_CARBON
302 static PyObject *Evt_SystemEvent(_self, _args)
303 PyObject *_self;
304 PyObject *_args;
306 PyObject *_res = NULL;
307 Boolean _rv;
308 EventRecord theEvent;
309 if (!PyArg_ParseTuple(_args, "O&",
310 PyMac_GetEventRecord, &theEvent))
311 return NULL;
312 _rv = SystemEvent(&theEvent);
313 _res = Py_BuildValue("b",
314 _rv);
315 return _res;
317 #endif
319 #if TARGET_API_MAC_CARBON
321 static PyObject *Evt_GetGlobalMouse(_self, _args)
322 PyObject *_self;
323 PyObject *_args;
325 PyObject *_res = NULL;
326 Point globalMouse;
327 if (!PyArg_ParseTuple(_args, ""))
328 return NULL;
329 GetGlobalMouse(&globalMouse);
330 _res = Py_BuildValue("O&",
331 PyMac_BuildPoint, globalMouse);
332 return _res;
334 #endif
336 #if TARGET_API_MAC_CARBON
338 static PyObject *Evt_GetCurrentKeyModifiers(_self, _args)
339 PyObject *_self;
340 PyObject *_args;
342 PyObject *_res = NULL;
343 UInt32 _rv;
344 if (!PyArg_ParseTuple(_args, ""))
345 return NULL;
346 _rv = GetCurrentKeyModifiers();
347 _res = Py_BuildValue("l",
348 _rv);
349 return _res;
351 #endif
353 #if TARGET_API_MAC_CARBON
355 static PyObject *Evt_CheckEventQueueForUserCancel(_self, _args)
356 PyObject *_self;
357 PyObject *_args;
359 PyObject *_res = NULL;
360 Boolean _rv;
361 if (!PyArg_ParseTuple(_args, ""))
362 return NULL;
363 _rv = CheckEventQueueForUserCancel();
364 _res = Py_BuildValue("b",
365 _rv);
366 return _res;
368 #endif
370 static PyObject *Evt_WaitNextEvent(_self, _args)
371 PyObject *_self;
372 PyObject *_args;
374 PyObject *_res = NULL;
376 Boolean _rv;
377 EventMask eventMask;
378 EventRecord theEvent;
379 UInt32 sleep;
380 Handle mouseregion = (Handle)0;
382 if (!PyArg_ParseTuple(_args, "Hl|O&",
383 &eventMask,
384 &sleep,
385 OptResObj_Convert, &mouseregion))
386 return NULL;
387 _rv = WaitNextEvent(eventMask,
388 &theEvent,
389 sleep,
390 (RgnHandle)mouseregion);
391 _res = Py_BuildValue("bO&",
392 _rv,
393 PyMac_BuildEventRecord, &theEvent);
394 return _res;
398 static PyMethodDef Evt_methods[] = {
399 {"GetMouse", (PyCFunction)Evt_GetMouse, 1,
400 "() -> (Point mouseLoc)"},
401 {"Button", (PyCFunction)Evt_Button, 1,
402 "() -> (Boolean _rv)"},
403 {"StillDown", (PyCFunction)Evt_StillDown, 1,
404 "() -> (Boolean _rv)"},
405 {"WaitMouseUp", (PyCFunction)Evt_WaitMouseUp, 1,
406 "() -> (Boolean _rv)"},
407 {"TickCount", (PyCFunction)Evt_TickCount, 1,
408 "() -> (UInt32 _rv)"},
409 {"GetCaretTime", (PyCFunction)Evt_GetCaretTime, 1,
410 "() -> (UInt32 _rv)"},
411 {"GetKeys", (PyCFunction)Evt_GetKeys, 1,
412 "() -> (KeyMap theKeys)"},
413 {"GetDblTime", (PyCFunction)Evt_GetDblTime, 1,
414 "() -> (UInt32 _rv)"},
415 {"SetEventMask", (PyCFunction)Evt_SetEventMask, 1,
416 "(EventMask value) -> None"},
417 {"GetNextEvent", (PyCFunction)Evt_GetNextEvent, 1,
418 "(EventMask eventMask) -> (Boolean _rv, EventRecord theEvent)"},
419 {"EventAvail", (PyCFunction)Evt_EventAvail, 1,
420 "(EventMask eventMask) -> (Boolean _rv, EventRecord theEvent)"},
421 {"PostEvent", (PyCFunction)Evt_PostEvent, 1,
422 "(EventKind eventNum, UInt32 eventMsg) -> None"},
424 #if !TARGET_API_MAC_CARBON
425 {"OSEventAvail", (PyCFunction)Evt_OSEventAvail, 1,
426 "(EventMask mask) -> (Boolean _rv, EventRecord theEvent)"},
427 #endif
429 #if !TARGET_API_MAC_CARBON
430 {"GetOSEvent", (PyCFunction)Evt_GetOSEvent, 1,
431 "(EventMask mask) -> (Boolean _rv, EventRecord theEvent)"},
432 #endif
433 {"FlushEvents", (PyCFunction)Evt_FlushEvents, 1,
434 "(EventMask whichMask, EventMask stopMask) -> None"},
436 #if !TARGET_API_MAC_CARBON
437 {"SystemClick", (PyCFunction)Evt_SystemClick, 1,
438 "(EventRecord theEvent, WindowPtr theWindow) -> None"},
439 #endif
441 #if !TARGET_API_MAC_CARBON
442 {"SystemTask", (PyCFunction)Evt_SystemTask, 1,
443 "() -> None"},
444 #endif
446 #if !TARGET_API_MAC_CARBON
447 {"SystemEvent", (PyCFunction)Evt_SystemEvent, 1,
448 "(EventRecord theEvent) -> (Boolean _rv)"},
449 #endif
451 #if TARGET_API_MAC_CARBON
452 {"GetGlobalMouse", (PyCFunction)Evt_GetGlobalMouse, 1,
453 "() -> (Point globalMouse)"},
454 #endif
456 #if TARGET_API_MAC_CARBON
457 {"GetCurrentKeyModifiers", (PyCFunction)Evt_GetCurrentKeyModifiers, 1,
458 "() -> (UInt32 _rv)"},
459 #endif
461 #if TARGET_API_MAC_CARBON
462 {"CheckEventQueueForUserCancel", (PyCFunction)Evt_CheckEventQueueForUserCancel, 1,
463 "() -> (Boolean _rv)"},
464 #endif
465 {"WaitNextEvent", (PyCFunction)Evt_WaitNextEvent, 1,
466 "(EventMask eventMask, UInt32 sleep [,RegionHandle]) -> (Boolean _rv, EventRecord theEvent)"},
467 {NULL, NULL, 0}
473 void initEvt()
475 PyObject *m;
476 PyObject *d;
481 m = Py_InitModule("Evt", Evt_methods);
482 d = PyModule_GetDict(m);
483 Evt_Error = PyMac_GetOSErrException();
484 if (Evt_Error == NULL ||
485 PyDict_SetItemString(d, "Error", Evt_Error) != 0)
486 return;
489 /* ========================= End module Evt ========================= */