This commit was manufactured by cvs2svn to create tag 'r212c1'.
[python/dscho.git] / Mac / Modules / evt / Evtmodule.c
blobbff6e1e56c7dcabfc6eac53730f7249b032fceb6
2 /* =========================== Module Evt =========================== */
4 #include "Python.h"
8 #include "macglue.h"
9 #include "pymactoolbox.h"
11 #ifdef WITHOUT_FRAMEWORKS
12 #include <Events.h>
13 #else
14 #include <Carbon/Carbon.h>
15 #endif
18 static PyObject *Evt_Error;
20 static PyObject *Evt_GetMouse(PyObject *_self, PyObject *_args)
22 PyObject *_res = NULL;
23 Point mouseLoc;
24 if (!PyArg_ParseTuple(_args, ""))
25 return NULL;
26 GetMouse(&mouseLoc);
27 _res = Py_BuildValue("O&",
28 PyMac_BuildPoint, mouseLoc);
29 return _res;
32 static PyObject *Evt_Button(PyObject *_self, PyObject *_args)
34 PyObject *_res = NULL;
35 Boolean _rv;
36 if (!PyArg_ParseTuple(_args, ""))
37 return NULL;
38 _rv = Button();
39 _res = Py_BuildValue("b",
40 _rv);
41 return _res;
44 static PyObject *Evt_StillDown(PyObject *_self, PyObject *_args)
46 PyObject *_res = NULL;
47 Boolean _rv;
48 if (!PyArg_ParseTuple(_args, ""))
49 return NULL;
50 _rv = StillDown();
51 _res = Py_BuildValue("b",
52 _rv);
53 return _res;
56 static PyObject *Evt_WaitMouseUp(PyObject *_self, PyObject *_args)
58 PyObject *_res = NULL;
59 Boolean _rv;
60 if (!PyArg_ParseTuple(_args, ""))
61 return NULL;
62 _rv = WaitMouseUp();
63 _res = Py_BuildValue("b",
64 _rv);
65 return _res;
68 static PyObject *Evt_TickCount(PyObject *_self, PyObject *_args)
70 PyObject *_res = NULL;
71 UInt32 _rv;
72 if (!PyArg_ParseTuple(_args, ""))
73 return NULL;
74 _rv = TickCount();
75 _res = Py_BuildValue("l",
76 _rv);
77 return _res;
80 static PyObject *Evt_GetCaretTime(PyObject *_self, PyObject *_args)
82 PyObject *_res = NULL;
83 UInt32 _rv;
84 if (!PyArg_ParseTuple(_args, ""))
85 return NULL;
86 _rv = GetCaretTime();
87 _res = Py_BuildValue("l",
88 _rv);
89 return _res;
92 static PyObject *Evt_GetKeys(PyObject *_self, PyObject *_args)
94 PyObject *_res = NULL;
95 KeyMap theKeys__out__;
96 if (!PyArg_ParseTuple(_args, ""))
97 return NULL;
98 GetKeys(theKeys__out__);
99 _res = Py_BuildValue("s#",
100 (char *)&theKeys__out__, (int)sizeof(KeyMap));
101 theKeys__error__: ;
102 return _res;
105 static PyObject *Evt_GetDblTime(PyObject *_self, PyObject *_args)
107 PyObject *_res = NULL;
108 UInt32 _rv;
109 if (!PyArg_ParseTuple(_args, ""))
110 return NULL;
111 _rv = GetDblTime();
112 _res = Py_BuildValue("l",
113 _rv);
114 return _res;
117 static PyObject *Evt_SetEventMask(PyObject *_self, PyObject *_args)
119 PyObject *_res = NULL;
120 EventMask value;
121 if (!PyArg_ParseTuple(_args, "H",
122 &value))
123 return NULL;
124 SetEventMask(value);
125 Py_INCREF(Py_None);
126 _res = Py_None;
127 return _res;
130 static PyObject *Evt_GetNextEvent(PyObject *_self, PyObject *_args)
132 PyObject *_res = NULL;
133 Boolean _rv;
134 EventMask eventMask;
135 EventRecord theEvent;
136 if (!PyArg_ParseTuple(_args, "H",
137 &eventMask))
138 return NULL;
139 _rv = GetNextEvent(eventMask,
140 &theEvent);
141 _res = Py_BuildValue("bO&",
142 _rv,
143 PyMac_BuildEventRecord, &theEvent);
144 return _res;
147 static PyObject *Evt_EventAvail(PyObject *_self, PyObject *_args)
149 PyObject *_res = NULL;
150 Boolean _rv;
151 EventMask eventMask;
152 EventRecord theEvent;
153 if (!PyArg_ParseTuple(_args, "H",
154 &eventMask))
155 return NULL;
156 _rv = EventAvail(eventMask,
157 &theEvent);
158 _res = Py_BuildValue("bO&",
159 _rv,
160 PyMac_BuildEventRecord, &theEvent);
161 return _res;
164 static PyObject *Evt_PostEvent(PyObject *_self, PyObject *_args)
166 PyObject *_res = NULL;
167 OSErr _err;
168 EventKind eventNum;
169 UInt32 eventMsg;
170 if (!PyArg_ParseTuple(_args, "Hl",
171 &eventNum,
172 &eventMsg))
173 return NULL;
174 _err = PostEvent(eventNum,
175 eventMsg);
176 if (_err != noErr) return PyMac_Error(_err);
177 Py_INCREF(Py_None);
178 _res = Py_None;
179 return _res;
182 #if !TARGET_API_MAC_CARBON
184 static PyObject *Evt_OSEventAvail(PyObject *_self, PyObject *_args)
186 PyObject *_res = NULL;
187 Boolean _rv;
188 EventMask mask;
189 EventRecord theEvent;
190 if (!PyArg_ParseTuple(_args, "H",
191 &mask))
192 return NULL;
193 _rv = OSEventAvail(mask,
194 &theEvent);
195 _res = Py_BuildValue("bO&",
196 _rv,
197 PyMac_BuildEventRecord, &theEvent);
198 return _res;
200 #endif
202 #if !TARGET_API_MAC_CARBON
204 static PyObject *Evt_GetOSEvent(PyObject *_self, PyObject *_args)
206 PyObject *_res = NULL;
207 Boolean _rv;
208 EventMask mask;
209 EventRecord theEvent;
210 if (!PyArg_ParseTuple(_args, "H",
211 &mask))
212 return NULL;
213 _rv = GetOSEvent(mask,
214 &theEvent);
215 _res = Py_BuildValue("bO&",
216 _rv,
217 PyMac_BuildEventRecord, &theEvent);
218 return _res;
220 #endif
222 static PyObject *Evt_FlushEvents(PyObject *_self, PyObject *_args)
224 PyObject *_res = NULL;
225 EventMask whichMask;
226 EventMask stopMask;
227 if (!PyArg_ParseTuple(_args, "HH",
228 &whichMask,
229 &stopMask))
230 return NULL;
231 FlushEvents(whichMask,
232 stopMask);
233 Py_INCREF(Py_None);
234 _res = Py_None;
235 return _res;
238 #if !TARGET_API_MAC_CARBON
240 static PyObject *Evt_SystemClick(PyObject *_self, PyObject *_args)
242 PyObject *_res = NULL;
243 EventRecord theEvent;
244 WindowPtr theWindow;
245 if (!PyArg_ParseTuple(_args, "O&O&",
246 PyMac_GetEventRecord, &theEvent,
247 WinObj_Convert, &theWindow))
248 return NULL;
249 SystemClick(&theEvent,
250 theWindow);
251 Py_INCREF(Py_None);
252 _res = Py_None;
253 return _res;
255 #endif
257 #if !TARGET_API_MAC_CARBON
259 static PyObject *Evt_SystemTask(PyObject *_self, PyObject *_args)
261 PyObject *_res = NULL;
262 if (!PyArg_ParseTuple(_args, ""))
263 return NULL;
264 SystemTask();
265 Py_INCREF(Py_None);
266 _res = Py_None;
267 return _res;
269 #endif
271 #if !TARGET_API_MAC_CARBON
273 static PyObject *Evt_SystemEvent(PyObject *_self, PyObject *_args)
275 PyObject *_res = NULL;
276 Boolean _rv;
277 EventRecord theEvent;
278 if (!PyArg_ParseTuple(_args, "O&",
279 PyMac_GetEventRecord, &theEvent))
280 return NULL;
281 _rv = SystemEvent(&theEvent);
282 _res = Py_BuildValue("b",
283 _rv);
284 return _res;
286 #endif
288 #if TARGET_API_MAC_CARBON
290 static PyObject *Evt_GetGlobalMouse(PyObject *_self, PyObject *_args)
292 PyObject *_res = NULL;
293 Point globalMouse;
294 if (!PyArg_ParseTuple(_args, ""))
295 return NULL;
296 GetGlobalMouse(&globalMouse);
297 _res = Py_BuildValue("O&",
298 PyMac_BuildPoint, globalMouse);
299 return _res;
301 #endif
303 #if TARGET_API_MAC_CARBON
305 static PyObject *Evt_GetCurrentKeyModifiers(PyObject *_self, PyObject *_args)
307 PyObject *_res = NULL;
308 UInt32 _rv;
309 if (!PyArg_ParseTuple(_args, ""))
310 return NULL;
311 _rv = GetCurrentKeyModifiers();
312 _res = Py_BuildValue("l",
313 _rv);
314 return _res;
316 #endif
318 #if TARGET_API_MAC_CARBON
320 static PyObject *Evt_CheckEventQueueForUserCancel(PyObject *_self, PyObject *_args)
322 PyObject *_res = NULL;
323 Boolean _rv;
324 if (!PyArg_ParseTuple(_args, ""))
325 return NULL;
326 _rv = CheckEventQueueForUserCancel();
327 _res = Py_BuildValue("b",
328 _rv);
329 return _res;
331 #endif
333 static PyObject *Evt_WaitNextEvent(PyObject *_self, PyObject *_args)
335 PyObject *_res = NULL;
337 Boolean _rv;
338 EventMask eventMask;
339 EventRecord theEvent;
340 UInt32 sleep;
341 Handle mouseregion = (Handle)0;
343 if (!PyArg_ParseTuple(_args, "Hl|O&",
344 &eventMask,
345 &sleep,
346 OptResObj_Convert, &mouseregion))
347 return NULL;
348 _rv = WaitNextEvent(eventMask,
349 &theEvent,
350 sleep,
351 (RgnHandle)mouseregion);
352 _res = Py_BuildValue("bO&",
353 _rv,
354 PyMac_BuildEventRecord, &theEvent);
355 return _res;
359 static PyMethodDef Evt_methods[] = {
360 {"GetMouse", (PyCFunction)Evt_GetMouse, 1,
361 "() -> (Point mouseLoc)"},
362 {"Button", (PyCFunction)Evt_Button, 1,
363 "() -> (Boolean _rv)"},
364 {"StillDown", (PyCFunction)Evt_StillDown, 1,
365 "() -> (Boolean _rv)"},
366 {"WaitMouseUp", (PyCFunction)Evt_WaitMouseUp, 1,
367 "() -> (Boolean _rv)"},
368 {"TickCount", (PyCFunction)Evt_TickCount, 1,
369 "() -> (UInt32 _rv)"},
370 {"GetCaretTime", (PyCFunction)Evt_GetCaretTime, 1,
371 "() -> (UInt32 _rv)"},
372 {"GetKeys", (PyCFunction)Evt_GetKeys, 1,
373 "() -> (KeyMap theKeys)"},
374 {"GetDblTime", (PyCFunction)Evt_GetDblTime, 1,
375 "() -> (UInt32 _rv)"},
376 {"SetEventMask", (PyCFunction)Evt_SetEventMask, 1,
377 "(EventMask value) -> None"},
378 {"GetNextEvent", (PyCFunction)Evt_GetNextEvent, 1,
379 "(EventMask eventMask) -> (Boolean _rv, EventRecord theEvent)"},
380 {"EventAvail", (PyCFunction)Evt_EventAvail, 1,
381 "(EventMask eventMask) -> (Boolean _rv, EventRecord theEvent)"},
382 {"PostEvent", (PyCFunction)Evt_PostEvent, 1,
383 "(EventKind eventNum, UInt32 eventMsg) -> None"},
385 #if !TARGET_API_MAC_CARBON
386 {"OSEventAvail", (PyCFunction)Evt_OSEventAvail, 1,
387 "(EventMask mask) -> (Boolean _rv, EventRecord theEvent)"},
388 #endif
390 #if !TARGET_API_MAC_CARBON
391 {"GetOSEvent", (PyCFunction)Evt_GetOSEvent, 1,
392 "(EventMask mask) -> (Boolean _rv, EventRecord theEvent)"},
393 #endif
394 {"FlushEvents", (PyCFunction)Evt_FlushEvents, 1,
395 "(EventMask whichMask, EventMask stopMask) -> None"},
397 #if !TARGET_API_MAC_CARBON
398 {"SystemClick", (PyCFunction)Evt_SystemClick, 1,
399 "(EventRecord theEvent, WindowPtr theWindow) -> None"},
400 #endif
402 #if !TARGET_API_MAC_CARBON
403 {"SystemTask", (PyCFunction)Evt_SystemTask, 1,
404 "() -> None"},
405 #endif
407 #if !TARGET_API_MAC_CARBON
408 {"SystemEvent", (PyCFunction)Evt_SystemEvent, 1,
409 "(EventRecord theEvent) -> (Boolean _rv)"},
410 #endif
412 #if TARGET_API_MAC_CARBON
413 {"GetGlobalMouse", (PyCFunction)Evt_GetGlobalMouse, 1,
414 "() -> (Point globalMouse)"},
415 #endif
417 #if TARGET_API_MAC_CARBON
418 {"GetCurrentKeyModifiers", (PyCFunction)Evt_GetCurrentKeyModifiers, 1,
419 "() -> (UInt32 _rv)"},
420 #endif
422 #if TARGET_API_MAC_CARBON
423 {"CheckEventQueueForUserCancel", (PyCFunction)Evt_CheckEventQueueForUserCancel, 1,
424 "() -> (Boolean _rv)"},
425 #endif
426 {"WaitNextEvent", (PyCFunction)Evt_WaitNextEvent, 1,
427 "(EventMask eventMask, UInt32 sleep [,RegionHandle]) -> (Boolean _rv, EventRecord theEvent)"},
428 {NULL, NULL, 0}
434 void initEvt(void)
436 PyObject *m;
437 PyObject *d;
442 m = Py_InitModule("Evt", Evt_methods);
443 d = PyModule_GetDict(m);
444 Evt_Error = PyMac_GetOSErrException();
445 if (Evt_Error == NULL ||
446 PyDict_SetItemString(d, "Error", Evt_Error) != 0)
447 return;
450 /* ========================= End module Evt ========================= */