2 /* =========================== Module Evt =========================== */
9 #include "pymactoolbox.h"
11 #ifdef WITHOUT_FRAMEWORKS
14 #include <Carbon/Carbon.h>
18 static PyObject
*Evt_Error
;
20 static PyObject
*Evt_GetMouse(PyObject
*_self
, PyObject
*_args
)
22 PyObject
*_res
= NULL
;
24 if (!PyArg_ParseTuple(_args
, ""))
27 _res
= Py_BuildValue("O&",
28 PyMac_BuildPoint
, mouseLoc
);
32 static PyObject
*Evt_Button(PyObject
*_self
, PyObject
*_args
)
34 PyObject
*_res
= NULL
;
36 if (!PyArg_ParseTuple(_args
, ""))
39 _res
= Py_BuildValue("b",
44 static PyObject
*Evt_StillDown(PyObject
*_self
, PyObject
*_args
)
46 PyObject
*_res
= NULL
;
48 if (!PyArg_ParseTuple(_args
, ""))
51 _res
= Py_BuildValue("b",
56 static PyObject
*Evt_WaitMouseUp(PyObject
*_self
, PyObject
*_args
)
58 PyObject
*_res
= NULL
;
60 if (!PyArg_ParseTuple(_args
, ""))
63 _res
= Py_BuildValue("b",
68 static PyObject
*Evt_TickCount(PyObject
*_self
, PyObject
*_args
)
70 PyObject
*_res
= NULL
;
72 if (!PyArg_ParseTuple(_args
, ""))
75 _res
= Py_BuildValue("l",
80 static PyObject
*Evt_GetCaretTime(PyObject
*_self
, PyObject
*_args
)
82 PyObject
*_res
= NULL
;
84 if (!PyArg_ParseTuple(_args
, ""))
87 _res
= Py_BuildValue("l",
92 static PyObject
*Evt_GetKeys(PyObject
*_self
, PyObject
*_args
)
94 PyObject
*_res
= NULL
;
95 KeyMap theKeys__out__
;
96 if (!PyArg_ParseTuple(_args
, ""))
98 GetKeys(theKeys__out__
);
99 _res
= Py_BuildValue("s#",
100 (char *)&theKeys__out__
, (int)sizeof(KeyMap
));
105 static PyObject
*Evt_GetDblTime(PyObject
*_self
, PyObject
*_args
)
107 PyObject
*_res
= NULL
;
109 if (!PyArg_ParseTuple(_args
, ""))
112 _res
= Py_BuildValue("l",
117 static PyObject
*Evt_SetEventMask(PyObject
*_self
, PyObject
*_args
)
119 PyObject
*_res
= NULL
;
121 if (!PyArg_ParseTuple(_args
, "H",
130 static PyObject
*Evt_GetNextEvent(PyObject
*_self
, PyObject
*_args
)
132 PyObject
*_res
= NULL
;
135 EventRecord theEvent
;
136 if (!PyArg_ParseTuple(_args
, "H",
139 _rv
= GetNextEvent(eventMask
,
141 _res
= Py_BuildValue("bO&",
143 PyMac_BuildEventRecord
, &theEvent
);
147 static PyObject
*Evt_EventAvail(PyObject
*_self
, PyObject
*_args
)
149 PyObject
*_res
= NULL
;
152 EventRecord theEvent
;
153 if (!PyArg_ParseTuple(_args
, "H",
156 _rv
= EventAvail(eventMask
,
158 _res
= Py_BuildValue("bO&",
160 PyMac_BuildEventRecord
, &theEvent
);
164 static PyObject
*Evt_PostEvent(PyObject
*_self
, PyObject
*_args
)
166 PyObject
*_res
= NULL
;
170 if (!PyArg_ParseTuple(_args
, "Hl",
174 _err
= PostEvent(eventNum
,
176 if (_err
!= noErr
) return PyMac_Error(_err
);
182 #if !TARGET_API_MAC_CARBON
184 static PyObject
*Evt_OSEventAvail(PyObject
*_self
, PyObject
*_args
)
186 PyObject
*_res
= NULL
;
189 EventRecord theEvent
;
190 if (!PyArg_ParseTuple(_args
, "H",
193 _rv
= OSEventAvail(mask
,
195 _res
= Py_BuildValue("bO&",
197 PyMac_BuildEventRecord
, &theEvent
);
202 #if !TARGET_API_MAC_CARBON
204 static PyObject
*Evt_GetOSEvent(PyObject
*_self
, PyObject
*_args
)
206 PyObject
*_res
= NULL
;
209 EventRecord theEvent
;
210 if (!PyArg_ParseTuple(_args
, "H",
213 _rv
= GetOSEvent(mask
,
215 _res
= Py_BuildValue("bO&",
217 PyMac_BuildEventRecord
, &theEvent
);
222 static PyObject
*Evt_FlushEvents(PyObject
*_self
, PyObject
*_args
)
224 PyObject
*_res
= NULL
;
227 if (!PyArg_ParseTuple(_args
, "HH",
231 FlushEvents(whichMask
,
238 #if !TARGET_API_MAC_CARBON
240 static PyObject
*Evt_SystemClick(PyObject
*_self
, PyObject
*_args
)
242 PyObject
*_res
= NULL
;
243 EventRecord theEvent
;
245 if (!PyArg_ParseTuple(_args
, "O&O&",
246 PyMac_GetEventRecord
, &theEvent
,
247 WinObj_Convert
, &theWindow
))
249 SystemClick(&theEvent
,
257 #if !TARGET_API_MAC_CARBON
259 static PyObject
*Evt_SystemTask(PyObject
*_self
, PyObject
*_args
)
261 PyObject
*_res
= NULL
;
262 if (!PyArg_ParseTuple(_args
, ""))
271 #if !TARGET_API_MAC_CARBON
273 static PyObject
*Evt_SystemEvent(PyObject
*_self
, PyObject
*_args
)
275 PyObject
*_res
= NULL
;
277 EventRecord theEvent
;
278 if (!PyArg_ParseTuple(_args
, "O&",
279 PyMac_GetEventRecord
, &theEvent
))
281 _rv
= SystemEvent(&theEvent
);
282 _res
= Py_BuildValue("b",
288 #if TARGET_API_MAC_CARBON
290 static PyObject
*Evt_GetGlobalMouse(PyObject
*_self
, PyObject
*_args
)
292 PyObject
*_res
= NULL
;
294 if (!PyArg_ParseTuple(_args
, ""))
296 GetGlobalMouse(&globalMouse
);
297 _res
= Py_BuildValue("O&",
298 PyMac_BuildPoint
, globalMouse
);
303 #if TARGET_API_MAC_CARBON
305 static PyObject
*Evt_GetCurrentKeyModifiers(PyObject
*_self
, PyObject
*_args
)
307 PyObject
*_res
= NULL
;
309 if (!PyArg_ParseTuple(_args
, ""))
311 _rv
= GetCurrentKeyModifiers();
312 _res
= Py_BuildValue("l",
318 #if TARGET_API_MAC_CARBON
320 static PyObject
*Evt_CheckEventQueueForUserCancel(PyObject
*_self
, PyObject
*_args
)
322 PyObject
*_res
= NULL
;
324 if (!PyArg_ParseTuple(_args
, ""))
326 _rv
= CheckEventQueueForUserCancel();
327 _res
= Py_BuildValue("b",
333 static PyObject
*Evt_WaitNextEvent(PyObject
*_self
, PyObject
*_args
)
335 PyObject
*_res
= NULL
;
339 EventRecord theEvent
;
341 Handle mouseregion
= (Handle
)0;
343 if (!PyArg_ParseTuple(_args
, "Hl|O&",
346 OptResObj_Convert
, &mouseregion
))
348 _rv
= WaitNextEvent(eventMask
,
351 (RgnHandle
)mouseregion
);
352 _res
= Py_BuildValue("bO&",
354 PyMac_BuildEventRecord
, &theEvent
);
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)"},
390 #if !TARGET_API_MAC_CARBON
391 {"GetOSEvent", (PyCFunction
)Evt_GetOSEvent
, 1,
392 "(EventMask mask) -> (Boolean _rv, EventRecord theEvent)"},
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"},
402 #if !TARGET_API_MAC_CARBON
403 {"SystemTask", (PyCFunction
)Evt_SystemTask
, 1,
407 #if !TARGET_API_MAC_CARBON
408 {"SystemEvent", (PyCFunction
)Evt_SystemEvent
, 1,
409 "(EventRecord theEvent) -> (Boolean _rv)"},
412 #if TARGET_API_MAC_CARBON
413 {"GetGlobalMouse", (PyCFunction
)Evt_GetGlobalMouse
, 1,
414 "() -> (Point globalMouse)"},
417 #if TARGET_API_MAC_CARBON
418 {"GetCurrentKeyModifiers", (PyCFunction
)Evt_GetCurrentKeyModifiers
, 1,
419 "() -> (UInt32 _rv)"},
422 #if TARGET_API_MAC_CARBON
423 {"CheckEventQueueForUserCancel", (PyCFunction
)Evt_CheckEventQueueForUserCancel
, 1,
424 "() -> (Boolean _rv)"},
426 {"WaitNextEvent", (PyCFunction
)Evt_WaitNextEvent
, 1,
427 "(EventMask eventMask, UInt32 sleep [,RegionHandle]) -> (Boolean _rv, EventRecord theEvent)"},
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)
450 /* ========================= End module Evt ========================= */