Last set of CW Pro 5 projects (probably)
[python/dscho.git] / Mac / Modules / evt / Evtmodule.c
blobc161c75e52011c9ad1866e11b2b595bf0800a0ad
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 static PyObject *Evt_WaitNextEvent(_self, _args)
320 PyObject *_self;
321 PyObject *_args;
323 PyObject *_res = NULL;
325 Boolean _rv;
326 EventMask eventMask;
327 EventRecord theEvent;
328 UInt32 sleep;
329 Handle mouseregion = (Handle)0;
331 if (!PyArg_ParseTuple(_args, "Hl|O&",
332 &eventMask,
333 &sleep,
334 OptResObj_Convert, &mouseregion))
335 return NULL;
336 _rv = WaitNextEvent(eventMask,
337 &theEvent,
338 sleep,
339 (RgnHandle)mouseregion);
340 _res = Py_BuildValue("bO&",
341 _rv,
342 PyMac_BuildEventRecord, &theEvent);
343 return _res;
347 static PyMethodDef Evt_methods[] = {
348 {"GetMouse", (PyCFunction)Evt_GetMouse, 1,
349 "() -> (Point mouseLoc)"},
350 {"Button", (PyCFunction)Evt_Button, 1,
351 "() -> (Boolean _rv)"},
352 {"StillDown", (PyCFunction)Evt_StillDown, 1,
353 "() -> (Boolean _rv)"},
354 {"WaitMouseUp", (PyCFunction)Evt_WaitMouseUp, 1,
355 "() -> (Boolean _rv)"},
356 {"TickCount", (PyCFunction)Evt_TickCount, 1,
357 "() -> (UInt32 _rv)"},
358 {"GetCaretTime", (PyCFunction)Evt_GetCaretTime, 1,
359 "() -> (UInt32 _rv)"},
360 {"GetKeys", (PyCFunction)Evt_GetKeys, 1,
361 "() -> (KeyMap theKeys)"},
362 {"GetDblTime", (PyCFunction)Evt_GetDblTime, 1,
363 "() -> (UInt32 _rv)"},
364 {"SetEventMask", (PyCFunction)Evt_SetEventMask, 1,
365 "(EventMask value) -> None"},
366 {"GetNextEvent", (PyCFunction)Evt_GetNextEvent, 1,
367 "(EventMask eventMask) -> (Boolean _rv, EventRecord theEvent)"},
368 {"EventAvail", (PyCFunction)Evt_EventAvail, 1,
369 "(EventMask eventMask) -> (Boolean _rv, EventRecord theEvent)"},
370 {"PostEvent", (PyCFunction)Evt_PostEvent, 1,
371 "(EventKind eventNum, UInt32 eventMsg) -> None"},
373 #if !TARGET_API_MAC_CARBON
374 {"OSEventAvail", (PyCFunction)Evt_OSEventAvail, 1,
375 "(EventMask mask) -> (Boolean _rv, EventRecord theEvent)"},
376 #endif
378 #if !TARGET_API_MAC_CARBON
379 {"GetOSEvent", (PyCFunction)Evt_GetOSEvent, 1,
380 "(EventMask mask) -> (Boolean _rv, EventRecord theEvent)"},
381 #endif
382 {"FlushEvents", (PyCFunction)Evt_FlushEvents, 1,
383 "(EventMask whichMask, EventMask stopMask) -> None"},
385 #if !TARGET_API_MAC_CARBON
386 {"SystemClick", (PyCFunction)Evt_SystemClick, 1,
387 "(EventRecord theEvent, WindowPtr theWindow) -> None"},
388 #endif
390 #if !TARGET_API_MAC_CARBON
391 {"SystemTask", (PyCFunction)Evt_SystemTask, 1,
392 "() -> None"},
393 #endif
395 #if !TARGET_API_MAC_CARBON
396 {"SystemEvent", (PyCFunction)Evt_SystemEvent, 1,
397 "(EventRecord theEvent) -> (Boolean _rv)"},
398 #endif
399 {"WaitNextEvent", (PyCFunction)Evt_WaitNextEvent, 1,
400 "(EventMask eventMask, UInt32 sleep [,RegionHandle]) -> (Boolean _rv, EventRecord theEvent)"},
401 {NULL, NULL, 0}
407 void initEvt()
409 PyObject *m;
410 PyObject *d;
415 m = Py_InitModule("Evt", Evt_methods);
416 d = PyModule_GetDict(m);
417 Evt_Error = PyMac_GetOSErrException();
418 if (Evt_Error == NULL ||
419 PyDict_SetItemString(d, "Error", Evt_Error) != 0)
420 Py_FatalError("can't initialize Evt.Error");
423 /* ========================= End module Evt ========================= */