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 static PyObject
*Evt_WaitNextEvent(_self
, _args
)
323 PyObject
*_res
= NULL
;
327 EventRecord theEvent
;
329 Handle mouseregion
= (Handle
)0;
331 if (!PyArg_ParseTuple(_args
, "Hl|O&",
334 OptResObj_Convert
, &mouseregion
))
336 _rv
= WaitNextEvent(eventMask
,
339 (RgnHandle
)mouseregion
);
340 _res
= Py_BuildValue("bO&",
342 PyMac_BuildEventRecord
, &theEvent
);
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)"},
378 #if !TARGET_API_MAC_CARBON
379 {"GetOSEvent", (PyCFunction
)Evt_GetOSEvent
, 1,
380 "(EventMask mask) -> (Boolean _rv, EventRecord theEvent)"},
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"},
390 #if !TARGET_API_MAC_CARBON
391 {"SystemTask", (PyCFunction
)Evt_SystemTask
, 1,
395 #if !TARGET_API_MAC_CARBON
396 {"SystemEvent", (PyCFunction
)Evt_SystemEvent
, 1,
397 "(EventRecord theEvent) -> (Boolean _rv)"},
399 {"WaitNextEvent", (PyCFunction
)Evt_WaitNextEvent
, 1,
400 "(EventMask eventMask, UInt32 sleep [,RegionHandle]) -> (Boolean _rv, EventRecord theEvent)"},
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 ========================= */