blob: c161c75e52011c9ad1866e11b2b595bf0800a0ad [file] [log] [blame]
Guido van Rossum17448e21995-01-30 11:53:55 +00001
2/* =========================== Module Evt =========================== */
3
4#include "Python.h"
5
6
7
Guido van Rossum17448e21995-01-30 11:53:55 +00008#include "macglue.h"
Jack Jansen9d8b96c2000-07-14 22:16:45 +00009#include "pymactoolbox.h"
Guido van Rossume26c2631995-02-28 09:11:41 +000010
Guido van Rossum17448e21995-01-30 11:53:55 +000011#include <Events.h>
12
Guido van Rossum17448e21995-01-30 11:53:55 +000013static PyObject *Evt_Error;
14
Jack Jansen21f96871998-02-20 16:02:09 +000015static PyObject *Evt_GetMouse(_self, _args)
16 PyObject *_self;
17 PyObject *_args;
18{
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;
27}
28
29static PyObject *Evt_Button(_self, _args)
30 PyObject *_self;
31 PyObject *_args;
32{
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;
41}
42
43static PyObject *Evt_StillDown(_self, _args)
44 PyObject *_self;
45 PyObject *_args;
46{
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;
55}
56
57static PyObject *Evt_WaitMouseUp(_self, _args)
58 PyObject *_self;
59 PyObject *_args;
60{
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;
69}
70
71static PyObject *Evt_TickCount(_self, _args)
72 PyObject *_self;
73 PyObject *_args;
74{
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;
83}
84
Jack Jansenb81cf9d1995-06-06 13:08:40 +000085static PyObject *Evt_GetCaretTime(_self, _args)
86 PyObject *_self;
87 PyObject *_args;
88{
89 PyObject *_res = NULL;
Jack Jansen7d0bc831995-06-09 20:56:31 +000090 UInt32 _rv;
Jack Jansenb81cf9d1995-06-06 13:08:40 +000091 if (!PyArg_ParseTuple(_args, ""))
92 return NULL;
93 _rv = GetCaretTime();
94 _res = Py_BuildValue("l",
95 _rv);
96 return _res;
97}
98
Jack Jansen21f96871998-02-20 16:02:09 +000099static PyObject *Evt_GetKeys(_self, _args)
100 PyObject *_self;
101 PyObject *_args;
102{
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;
112}
113
114static PyObject *Evt_GetDblTime(_self, _args)
115 PyObject *_self;
116 PyObject *_args;
117{
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;
126}
127
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000128static PyObject *Evt_SetEventMask(_self, _args)
129 PyObject *_self;
130 PyObject *_args;
131{
132 PyObject *_res = NULL;
Jack Jansend40f3c61995-10-09 23:12:22 +0000133 EventMask value;
Jack Jansen0b13e7c2000-07-07 13:09:35 +0000134 if (!PyArg_ParseTuple(_args, "H",
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000135 &value))
136 return NULL;
137 SetEventMask(value);
138 Py_INCREF(Py_None);
139 _res = Py_None;
140 return _res;
141}
142
Guido van Rossum17448e21995-01-30 11:53:55 +0000143static PyObject *Evt_GetNextEvent(_self, _args)
144 PyObject *_self;
145 PyObject *_args;
146{
147 PyObject *_res = NULL;
148 Boolean _rv;
Jack Jansend40f3c61995-10-09 23:12:22 +0000149 EventMask eventMask;
Guido van Rossum17448e21995-01-30 11:53:55 +0000150 EventRecord theEvent;
Jack Jansen0b13e7c2000-07-07 13:09:35 +0000151 if (!PyArg_ParseTuple(_args, "H",
Guido van Rossum17448e21995-01-30 11:53:55 +0000152 &eventMask))
153 return NULL;
154 _rv = GetNextEvent(eventMask,
155 &theEvent);
156 _res = Py_BuildValue("bO&",
157 _rv,
158 PyMac_BuildEventRecord, &theEvent);
159 return _res;
160}
161
Guido van Rossum17448e21995-01-30 11:53:55 +0000162static PyObject *Evt_EventAvail(_self, _args)
163 PyObject *_self;
164 PyObject *_args;
165{
166 PyObject *_res = NULL;
167 Boolean _rv;
Jack Jansend40f3c61995-10-09 23:12:22 +0000168 EventMask eventMask;
Guido van Rossum17448e21995-01-30 11:53:55 +0000169 EventRecord theEvent;
Jack Jansen0b13e7c2000-07-07 13:09:35 +0000170 if (!PyArg_ParseTuple(_args, "H",
Guido van Rossum17448e21995-01-30 11:53:55 +0000171 &eventMask))
172 return NULL;
173 _rv = EventAvail(eventMask,
174 &theEvent);
175 _res = Py_BuildValue("bO&",
176 _rv,
177 PyMac_BuildEventRecord, &theEvent);
178 return _res;
179}
180
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000181static PyObject *Evt_PostEvent(_self, _args)
182 PyObject *_self;
183 PyObject *_args;
184{
185 PyObject *_res = NULL;
186 OSErr _err;
Jack Jansend40f3c61995-10-09 23:12:22 +0000187 EventKind eventNum;
Jack Jansen7d0bc831995-06-09 20:56:31 +0000188 UInt32 eventMsg;
Jack Jansen0b13e7c2000-07-07 13:09:35 +0000189 if (!PyArg_ParseTuple(_args, "Hl",
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000190 &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;
199}
200
Jack Jansen74a1e632000-07-14 22:37:27 +0000201#if !TARGET_API_MAC_CARBON
Jack Jansenabf17032000-06-20 07:42:23 +0000202
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000203static PyObject *Evt_OSEventAvail(_self, _args)
204 PyObject *_self;
205 PyObject *_args;
206{
207 PyObject *_res = NULL;
208 Boolean _rv;
Jack Jansend40f3c61995-10-09 23:12:22 +0000209 EventMask mask;
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000210 EventRecord theEvent;
Jack Jansen0b13e7c2000-07-07 13:09:35 +0000211 if (!PyArg_ParseTuple(_args, "H",
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000212 &mask))
213 return NULL;
214 _rv = OSEventAvail(mask,
215 &theEvent);
216 _res = Py_BuildValue("bO&",
217 _rv,
218 PyMac_BuildEventRecord, &theEvent);
219 return _res;
220}
Jack Jansenabf17032000-06-20 07:42:23 +0000221#endif
222
Jack Jansen74a1e632000-07-14 22:37:27 +0000223#if !TARGET_API_MAC_CARBON
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000224
225static PyObject *Evt_GetOSEvent(_self, _args)
226 PyObject *_self;
227 PyObject *_args;
228{
229 PyObject *_res = NULL;
230 Boolean _rv;
Jack Jansend40f3c61995-10-09 23:12:22 +0000231 EventMask mask;
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000232 EventRecord theEvent;
Jack Jansen0b13e7c2000-07-07 13:09:35 +0000233 if (!PyArg_ParseTuple(_args, "H",
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000234 &mask))
235 return NULL;
236 _rv = GetOSEvent(mask,
237 &theEvent);
238 _res = Py_BuildValue("bO&",
239 _rv,
240 PyMac_BuildEventRecord, &theEvent);
241 return _res;
242}
Jack Jansenabf17032000-06-20 07:42:23 +0000243#endif
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000244
245static PyObject *Evt_FlushEvents(_self, _args)
246 PyObject *_self;
247 PyObject *_args;
248{
249 PyObject *_res = NULL;
Jack Jansend40f3c61995-10-09 23:12:22 +0000250 EventMask whichMask;
251 EventMask stopMask;
Jack Jansen0b13e7c2000-07-07 13:09:35 +0000252 if (!PyArg_ParseTuple(_args, "HH",
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000253 &whichMask,
254 &stopMask))
255 return NULL;
256 FlushEvents(whichMask,
257 stopMask);
258 Py_INCREF(Py_None);
259 _res = Py_None;
260 return _res;
261}
262
Jack Jansen74a1e632000-07-14 22:37:27 +0000263#if !TARGET_API_MAC_CARBON
Jack Jansenabf17032000-06-20 07:42:23 +0000264
Guido van Rossume26c2631995-02-28 09:11:41 +0000265static PyObject *Evt_SystemClick(_self, _args)
Guido van Rossum17448e21995-01-30 11:53:55 +0000266 PyObject *_self;
267 PyObject *_args;
268{
269 PyObject *_res = NULL;
Guido van Rossume26c2631995-02-28 09:11:41 +0000270 EventRecord theEvent;
271 WindowPtr theWindow;
272 if (!PyArg_ParseTuple(_args, "O&O&",
273 PyMac_GetEventRecord, &theEvent,
274 WinObj_Convert, &theWindow))
Guido van Rossum17448e21995-01-30 11:53:55 +0000275 return NULL;
Guido van Rossume26c2631995-02-28 09:11:41 +0000276 SystemClick(&theEvent,
277 theWindow);
278 Py_INCREF(Py_None);
279 _res = Py_None;
Guido van Rossum17448e21995-01-30 11:53:55 +0000280 return _res;
281}
Jack Jansenabf17032000-06-20 07:42:23 +0000282#endif
283
Jack Jansen74a1e632000-07-14 22:37:27 +0000284#if !TARGET_API_MAC_CARBON
Guido van Rossum17448e21995-01-30 11:53:55 +0000285
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000286static PyObject *Evt_SystemTask(_self, _args)
287 PyObject *_self;
288 PyObject *_args;
289{
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;
297}
Jack Jansenabf17032000-06-20 07:42:23 +0000298#endif
299
Jack Jansen74a1e632000-07-14 22:37:27 +0000300#if !TARGET_API_MAC_CARBON
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000301
302static PyObject *Evt_SystemEvent(_self, _args)
303 PyObject *_self;
304 PyObject *_args;
305{
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;
316}
Jack Jansenabf17032000-06-20 07:42:23 +0000317#endif
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000318
Jack Jansen91b5bed1998-09-17 15:28:58 +0000319static PyObject *Evt_WaitNextEvent(_self, _args)
320 PyObject *_self;
321 PyObject *_args;
322{
323 PyObject *_res = NULL;
324
325 Boolean _rv;
326 EventMask eventMask;
327 EventRecord theEvent;
328 UInt32 sleep;
329 Handle mouseregion = (Handle)0;
330
Jack Jansen4fb67f42000-07-24 19:59:17 +0000331 if (!PyArg_ParseTuple(_args, "Hl|O&",
Jack Jansen91b5bed1998-09-17 15:28:58 +0000332 &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;
344
345}
346
Guido van Rossum17448e21995-01-30 11:53:55 +0000347static PyMethodDef Evt_methods[] = {
Guido van Rossum17448e21995-01-30 11:53:55 +0000348 {"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)"},
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000356 {"TickCount", (PyCFunction)Evt_TickCount, 1,
Jack Jansen7d0bc831995-06-09 20:56:31 +0000357 "() -> (UInt32 _rv)"},
Jack Jansen21f96871998-02-20 16:02:09 +0000358 {"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)"},
Jack Jansen21f96871998-02-20 16:02:09 +0000368 {"EventAvail", (PyCFunction)Evt_EventAvail, 1,
369 "(EventMask eventMask) -> (Boolean _rv, EventRecord theEvent)"},
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000370 {"PostEvent", (PyCFunction)Evt_PostEvent, 1,
Jack Jansend40f3c61995-10-09 23:12:22 +0000371 "(EventKind eventNum, UInt32 eventMsg) -> None"},
Jack Jansenabf17032000-06-20 07:42:23 +0000372
Jack Jansen74a1e632000-07-14 22:37:27 +0000373#if !TARGET_API_MAC_CARBON
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000374 {"OSEventAvail", (PyCFunction)Evt_OSEventAvail, 1,
Jack Jansend40f3c61995-10-09 23:12:22 +0000375 "(EventMask mask) -> (Boolean _rv, EventRecord theEvent)"},
Jack Jansenabf17032000-06-20 07:42:23 +0000376#endif
377
Jack Jansen74a1e632000-07-14 22:37:27 +0000378#if !TARGET_API_MAC_CARBON
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000379 {"GetOSEvent", (PyCFunction)Evt_GetOSEvent, 1,
Jack Jansend40f3c61995-10-09 23:12:22 +0000380 "(EventMask mask) -> (Boolean _rv, EventRecord theEvent)"},
Jack Jansenabf17032000-06-20 07:42:23 +0000381#endif
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000382 {"FlushEvents", (PyCFunction)Evt_FlushEvents, 1,
Jack Jansend40f3c61995-10-09 23:12:22 +0000383 "(EventMask whichMask, EventMask stopMask) -> None"},
Jack Jansenabf17032000-06-20 07:42:23 +0000384
Jack Jansen74a1e632000-07-14 22:37:27 +0000385#if !TARGET_API_MAC_CARBON
Guido van Rossume26c2631995-02-28 09:11:41 +0000386 {"SystemClick", (PyCFunction)Evt_SystemClick, 1,
387 "(EventRecord theEvent, WindowPtr theWindow) -> None"},
Jack Jansenabf17032000-06-20 07:42:23 +0000388#endif
389
Jack Jansen74a1e632000-07-14 22:37:27 +0000390#if !TARGET_API_MAC_CARBON
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000391 {"SystemTask", (PyCFunction)Evt_SystemTask, 1,
392 "() -> None"},
Jack Jansenabf17032000-06-20 07:42:23 +0000393#endif
394
Jack Jansen74a1e632000-07-14 22:37:27 +0000395#if !TARGET_API_MAC_CARBON
Jack Jansenb81cf9d1995-06-06 13:08:40 +0000396 {"SystemEvent", (PyCFunction)Evt_SystemEvent, 1,
397 "(EventRecord theEvent) -> (Boolean _rv)"},
Jack Jansenabf17032000-06-20 07:42:23 +0000398#endif
Jack Jansen91b5bed1998-09-17 15:28:58 +0000399 {"WaitNextEvent", (PyCFunction)Evt_WaitNextEvent, 1,
400 "(EventMask eventMask, UInt32 sleep [,RegionHandle]) -> (Boolean _rv, EventRecord theEvent)"},
Guido van Rossum17448e21995-01-30 11:53:55 +0000401 {NULL, NULL, 0}
402};
403
404
405
406
407void initEvt()
408{
409 PyObject *m;
410 PyObject *d;
411
412
413
414
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");
421}
422
423/* ========================= End module Evt ========================= */
424