2 /* =========================== Module Evt =========================== */
9 #include "pymactoolbox.h"
13 static PyObject
*Evt_Error
;
15 static PyObject
*Evt_GetMouse(_self
, _args
)
19 PyObject
*_res
= NULL
;
21 if (!PyArg_ParseTuple(_args
, ""))
24 _res
= Py_BuildValue("O&",
25 PyMac_BuildPoint
, mouseLoc
);
29 static PyObject
*Evt_Button(_self
, _args
)
33 PyObject
*_res
= NULL
;
35 if (!PyArg_ParseTuple(_args
, ""))
38 _res
= Py_BuildValue("b",
43 static PyObject
*Evt_StillDown(_self
, _args
)
47 PyObject
*_res
= NULL
;
49 if (!PyArg_ParseTuple(_args
, ""))
52 _res
= Py_BuildValue("b",
57 static PyObject
*Evt_WaitMouseUp(_self
, _args
)
61 PyObject
*_res
= NULL
;
63 if (!PyArg_ParseTuple(_args
, ""))
66 _res
= Py_BuildValue("b",
71 static PyObject
*Evt_TickCount(_self
, _args
)
75 PyObject
*_res
= NULL
;
77 if (!PyArg_ParseTuple(_args
, ""))
80 _res
= Py_BuildValue("l",
85 static PyObject
*Evt_GetCaretTime(_self
, _args
)
89 PyObject
*_res
= NULL
;
91 if (!PyArg_ParseTuple(_args
, ""))
94 _res
= Py_BuildValue("l",
99 static PyObject
*Evt_GetKeys(_self
, _args
)
103 PyObject
*_res
= NULL
;
104 KeyMap theKeys__out__
;
105 if (!PyArg_ParseTuple(_args
, ""))
107 GetKeys(theKeys__out__
);
108 _res
= Py_BuildValue("s#",
109 (char *)&theKeys__out__
, (int)sizeof(KeyMap
));
114 static PyObject
*Evt_GetDblTime(_self
, _args
)
118 PyObject
*_res
= NULL
;
120 if (!PyArg_ParseTuple(_args
, ""))
123 _res
= Py_BuildValue("l",
128 static PyObject
*Evt_SetEventMask(_self
, _args
)
132 PyObject
*_res
= NULL
;
134 if (!PyArg_ParseTuple(_args
, "H",
143 static PyObject
*Evt_GetNextEvent(_self
, _args
)
147 PyObject
*_res
= NULL
;
150 EventRecord theEvent
;
151 if (!PyArg_ParseTuple(_args
, "H",
154 _rv
= GetNextEvent(eventMask
,
156 _res
= Py_BuildValue("bO&",
158 PyMac_BuildEventRecord
, &theEvent
);
162 static PyObject
*Evt_EventAvail(_self
, _args
)
166 PyObject
*_res
= NULL
;
169 EventRecord theEvent
;
170 if (!PyArg_ParseTuple(_args
, "H",
173 _rv
= EventAvail(eventMask
,
175 _res
= Py_BuildValue("bO&",
177 PyMac_BuildEventRecord
, &theEvent
);
181 static PyObject
*Evt_PostEvent(_self
, _args
)
185 PyObject
*_res
= NULL
;
189 if (!PyArg_ParseTuple(_args
, "Hl",
193 _err
= PostEvent(eventNum
,
195 if (_err
!= noErr
) return PyMac_Error(_err
);
201 #if !TARGET_API_MAC_CARBON
203 static PyObject
*Evt_OSEventAvail(_self
, _args
)
207 PyObject
*_res
= NULL
;
210 EventRecord theEvent
;
211 if (!PyArg_ParseTuple(_args
, "H",
214 _rv
= OSEventAvail(mask
,
216 _res
= Py_BuildValue("bO&",
218 PyMac_BuildEventRecord
, &theEvent
);
223 #if !TARGET_API_MAC_CARBON
225 static PyObject
*Evt_GetOSEvent(_self
, _args
)
229 PyObject
*_res
= NULL
;
232 EventRecord theEvent
;
233 if (!PyArg_ParseTuple(_args
, "H",
236 _rv
= GetOSEvent(mask
,
238 _res
= Py_BuildValue("bO&",
240 PyMac_BuildEventRecord
, &theEvent
);
245 static PyObject
*Evt_FlushEvents(_self
, _args
)
249 PyObject
*_res
= NULL
;
252 if (!PyArg_ParseTuple(_args
, "HH",
256 FlushEvents(whichMask
,
263 #if !TARGET_API_MAC_CARBON
265 static PyObject
*Evt_SystemClick(_self
, _args
)
269 PyObject
*_res
= NULL
;
270 EventRecord theEvent
;
272 if (!PyArg_ParseTuple(_args
, "O&O&",
273 PyMac_GetEventRecord
, &theEvent
,
274 WinObj_Convert
, &theWindow
))
276 SystemClick(&theEvent
,
284 #if !TARGET_API_MAC_CARBON
286 static PyObject
*Evt_SystemTask(_self
, _args
)
290 PyObject
*_res
= NULL
;
291 if (!PyArg_ParseTuple(_args
, ""))
300 #if !TARGET_API_MAC_CARBON
302 static PyObject
*Evt_SystemEvent(_self
, _args
)
306 PyObject
*_res
= NULL
;
308 EventRecord theEvent
;
309 if (!PyArg_ParseTuple(_args
, "O&",
310 PyMac_GetEventRecord
, &theEvent
))
312 _rv
= SystemEvent(&theEvent
);
313 _res
= Py_BuildValue("b",
319 #if TARGET_API_MAC_CARBON
321 static PyObject
*Evt_GetGlobalMouse(_self
, _args
)
325 PyObject
*_res
= NULL
;
327 if (!PyArg_ParseTuple(_args
, ""))
329 GetGlobalMouse(&globalMouse
);
330 _res
= Py_BuildValue("O&",
331 PyMac_BuildPoint
, globalMouse
);
336 #if TARGET_API_MAC_CARBON
338 static PyObject
*Evt_GetCurrentKeyModifiers(_self
, _args
)
342 PyObject
*_res
= NULL
;
344 if (!PyArg_ParseTuple(_args
, ""))
346 _rv
= GetCurrentKeyModifiers();
347 _res
= Py_BuildValue("l",
353 #if TARGET_API_MAC_CARBON
355 static PyObject
*Evt_CheckEventQueueForUserCancel(_self
, _args
)
359 PyObject
*_res
= NULL
;
361 if (!PyArg_ParseTuple(_args
, ""))
363 _rv
= CheckEventQueueForUserCancel();
364 _res
= Py_BuildValue("b",
370 static PyObject
*Evt_WaitNextEvent(_self
, _args
)
374 PyObject
*_res
= NULL
;
378 EventRecord theEvent
;
380 Handle mouseregion
= (Handle
)0;
382 if (!PyArg_ParseTuple(_args
, "Hl|O&",
385 OptResObj_Convert
, &mouseregion
))
387 _rv
= WaitNextEvent(eventMask
,
390 (RgnHandle
)mouseregion
);
391 _res
= Py_BuildValue("bO&",
393 PyMac_BuildEventRecord
, &theEvent
);
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)"},
429 #if !TARGET_API_MAC_CARBON
430 {"GetOSEvent", (PyCFunction
)Evt_GetOSEvent
, 1,
431 "(EventMask mask) -> (Boolean _rv, EventRecord theEvent)"},
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"},
441 #if !TARGET_API_MAC_CARBON
442 {"SystemTask", (PyCFunction
)Evt_SystemTask
, 1,
446 #if !TARGET_API_MAC_CARBON
447 {"SystemEvent", (PyCFunction
)Evt_SystemEvent
, 1,
448 "(EventRecord theEvent) -> (Boolean _rv)"},
451 #if TARGET_API_MAC_CARBON
452 {"GetGlobalMouse", (PyCFunction
)Evt_GetGlobalMouse
, 1,
453 "() -> (Point globalMouse)"},
456 #if TARGET_API_MAC_CARBON
457 {"GetCurrentKeyModifiers", (PyCFunction
)Evt_GetCurrentKeyModifiers
, 1,
458 "() -> (UInt32 _rv)"},
461 #if TARGET_API_MAC_CARBON
462 {"CheckEventQueueForUserCancel", (PyCFunction
)Evt_CheckEventQueueForUserCancel
, 1,
463 "() -> (Boolean _rv)"},
465 {"WaitNextEvent", (PyCFunction
)Evt_WaitNextEvent
, 1,
466 "(EventMask eventMask, UInt32 sleep [,RegionHandle]) -> (Boolean _rv, EventRecord theEvent)"},
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)
489 /* ========================= End module Evt ========================= */