2 /* =========================== Module Evt =========================== */
8 #define SystemSevenOrLater 1
16 extern PyObject
*ResObj_New(Handle
);
17 extern PyObject
*ResObj_OptNew(Handle
);
18 extern int ResObj_Convert(PyObject
*, Handle
*);
20 extern PyObject
*WinObj_New(WindowPtr
);
21 extern int WinObj_Convert(PyObject
*, WindowPtr
*);
23 extern PyObject
*DlgObj_New(DialogPtr
);
24 extern int DlgObj_Convert(PyObject
*, DialogPtr
*);
25 extern PyTypeObject Dialog_Type
;
26 #define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
28 extern PyObject
*MenuObj_New(MenuHandle
);
29 extern int MenuObj_Convert(PyObject
*, MenuHandle
*);
31 extern PyObject
*CtlObj_New(ControlHandle
);
32 extern int CtlObj_Convert(PyObject
*, ControlHandle
*);
34 extern PyObject
*WinObj_WhichWindow(WindowPtr
);
39 #define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
41 static PyObject
*Evt_Error
;
43 static PyObject
*Evt_GetCaretTime(_self
, _args
)
47 PyObject
*_res
= NULL
;
49 if (!PyArg_ParseTuple(_args
, ""))
52 _res
= Py_BuildValue("l",
57 static PyObject
*Evt_SetEventMask(_self
, _args
)
61 PyObject
*_res
= NULL
;
63 if (!PyArg_ParseTuple(_args
, "h",
72 static PyObject
*Evt_GetDblTime(_self
, _args
)
76 PyObject
*_res
= NULL
;
78 if (!PyArg_ParseTuple(_args
, ""))
81 _res
= Py_BuildValue("l",
86 static PyObject
*Evt_GetNextEvent(_self
, _args
)
90 PyObject
*_res
= NULL
;
92 MacOSEventMask eventMask
;
94 if (!PyArg_ParseTuple(_args
, "h",
97 _rv
= GetNextEvent(eventMask
,
99 _res
= Py_BuildValue("bO&",
101 PyMac_BuildEventRecord
, &theEvent
);
105 static PyObject
*Evt_WaitNextEvent(_self
, _args
)
109 PyObject
*_res
= NULL
;
111 MacOSEventMask eventMask
;
112 EventRecord theEvent
;
114 if (!PyArg_ParseTuple(_args
, "hl",
118 _rv
= WaitNextEvent(eventMask
,
122 _res
= Py_BuildValue("bO&",
124 PyMac_BuildEventRecord
, &theEvent
);
128 static PyObject
*Evt_EventAvail(_self
, _args
)
132 PyObject
*_res
= NULL
;
134 MacOSEventMask eventMask
;
135 EventRecord theEvent
;
136 if (!PyArg_ParseTuple(_args
, "h",
139 _rv
= EventAvail(eventMask
,
141 _res
= Py_BuildValue("bO&",
143 PyMac_BuildEventRecord
, &theEvent
);
147 static PyObject
*Evt_GetMouse(_self
, _args
)
151 PyObject
*_res
= NULL
;
153 if (!PyArg_ParseTuple(_args
, ""))
156 _res
= Py_BuildValue("O&",
157 PyMac_BuildPoint
, mouseLoc
);
161 static PyObject
*Evt_Button(_self
, _args
)
165 PyObject
*_res
= NULL
;
167 if (!PyArg_ParseTuple(_args
, ""))
170 _res
= Py_BuildValue("b",
175 static PyObject
*Evt_StillDown(_self
, _args
)
179 PyObject
*_res
= NULL
;
181 if (!PyArg_ParseTuple(_args
, ""))
184 _res
= Py_BuildValue("b",
189 static PyObject
*Evt_WaitMouseUp(_self
, _args
)
193 PyObject
*_res
= NULL
;
195 if (!PyArg_ParseTuple(_args
, ""))
198 _res
= Py_BuildValue("b",
203 static PyObject
*Evt_GetKeys(_self
, _args
)
207 PyObject
*_res
= NULL
;
208 KeyMap theKeys__out__
;
209 if (!PyArg_ParseTuple(_args
, ""))
211 GetKeys(theKeys__out__
);
212 _res
= Py_BuildValue("s#",
213 (char *)&theKeys__out__
, (int)sizeof(KeyMap
));
218 static PyObject
*Evt_TickCount(_self
, _args
)
222 PyObject
*_res
= NULL
;
224 if (!PyArg_ParseTuple(_args
, ""))
227 _res
= Py_BuildValue("l",
232 static PyObject
*Evt_PostEvent(_self
, _args
)
236 PyObject
*_res
= NULL
;
238 MacOSEventKind eventNum
;
240 if (!PyArg_ParseTuple(_args
, "hl",
244 _err
= PostEvent(eventNum
,
246 if (_err
!= noErr
) return PyMac_Error(_err
);
252 static PyObject
*Evt_OSEventAvail(_self
, _args
)
256 PyObject
*_res
= NULL
;
259 EventRecord theEvent
;
260 if (!PyArg_ParseTuple(_args
, "h",
263 _rv
= OSEventAvail(mask
,
265 _res
= Py_BuildValue("bO&",
267 PyMac_BuildEventRecord
, &theEvent
);
271 static PyObject
*Evt_GetOSEvent(_self
, _args
)
275 PyObject
*_res
= NULL
;
278 EventRecord theEvent
;
279 if (!PyArg_ParseTuple(_args
, "h",
282 _rv
= GetOSEvent(mask
,
284 _res
= Py_BuildValue("bO&",
286 PyMac_BuildEventRecord
, &theEvent
);
290 static PyObject
*Evt_FlushEvents(_self
, _args
)
294 PyObject
*_res
= NULL
;
295 MacOSEventMask whichMask
;
296 MacOSEventMask stopMask
;
297 if (!PyArg_ParseTuple(_args
, "hh",
301 FlushEvents(whichMask
,
308 static PyObject
*Evt_SystemClick(_self
, _args
)
312 PyObject
*_res
= NULL
;
313 EventRecord theEvent
;
315 if (!PyArg_ParseTuple(_args
, "O&O&",
316 PyMac_GetEventRecord
, &theEvent
,
317 WinObj_Convert
, &theWindow
))
319 SystemClick(&theEvent
,
326 static PyObject
*Evt_SystemTask(_self
, _args
)
330 PyObject
*_res
= NULL
;
331 if (!PyArg_ParseTuple(_args
, ""))
339 static PyObject
*Evt_SystemEvent(_self
, _args
)
343 PyObject
*_res
= NULL
;
345 EventRecord theEvent
;
346 if (!PyArg_ParseTuple(_args
, "O&",
347 PyMac_GetEventRecord
, &theEvent
))
349 _rv
= SystemEvent(&theEvent
);
350 _res
= Py_BuildValue("b",
355 static PyMethodDef Evt_methods
[] = {
356 {"GetCaretTime", (PyCFunction
)Evt_GetCaretTime
, 1,
357 "() -> (UInt32 _rv)"},
358 {"SetEventMask", (PyCFunction
)Evt_SetEventMask
, 1,
359 "(MacOSEventMask value) -> None"},
360 {"GetDblTime", (PyCFunction
)Evt_GetDblTime
, 1,
361 "() -> (UInt32 _rv)"},
362 {"GetNextEvent", (PyCFunction
)Evt_GetNextEvent
, 1,
363 "(MacOSEventMask eventMask) -> (Boolean _rv, EventRecord theEvent)"},
364 {"WaitNextEvent", (PyCFunction
)Evt_WaitNextEvent
, 1,
365 "(MacOSEventMask eventMask, UInt32 sleep) -> (Boolean _rv, EventRecord theEvent)"},
366 {"EventAvail", (PyCFunction
)Evt_EventAvail
, 1,
367 "(MacOSEventMask eventMask) -> (Boolean _rv, EventRecord theEvent)"},
368 {"GetMouse", (PyCFunction
)Evt_GetMouse
, 1,
369 "() -> (Point mouseLoc)"},
370 {"Button", (PyCFunction
)Evt_Button
, 1,
371 "() -> (Boolean _rv)"},
372 {"StillDown", (PyCFunction
)Evt_StillDown
, 1,
373 "() -> (Boolean _rv)"},
374 {"WaitMouseUp", (PyCFunction
)Evt_WaitMouseUp
, 1,
375 "() -> (Boolean _rv)"},
376 {"GetKeys", (PyCFunction
)Evt_GetKeys
, 1,
377 "() -> (KeyMap theKeys)"},
378 {"TickCount", (PyCFunction
)Evt_TickCount
, 1,
379 "() -> (UInt32 _rv)"},
380 {"PostEvent", (PyCFunction
)Evt_PostEvent
, 1,
381 "(MacOSEventKind eventNum, UInt32 eventMsg) -> None"},
382 {"OSEventAvail", (PyCFunction
)Evt_OSEventAvail
, 1,
383 "(MacOSEventMask mask) -> (Boolean _rv, EventRecord theEvent)"},
384 {"GetOSEvent", (PyCFunction
)Evt_GetOSEvent
, 1,
385 "(MacOSEventMask mask) -> (Boolean _rv, EventRecord theEvent)"},
386 {"FlushEvents", (PyCFunction
)Evt_FlushEvents
, 1,
387 "(MacOSEventMask whichMask, MacOSEventMask stopMask) -> None"},
388 {"SystemClick", (PyCFunction
)Evt_SystemClick
, 1,
389 "(EventRecord theEvent, WindowPtr theWindow) -> None"},
390 {"SystemTask", (PyCFunction
)Evt_SystemTask
, 1,
392 {"SystemEvent", (PyCFunction
)Evt_SystemEvent
, 1,
393 "(EventRecord theEvent) -> (Boolean _rv)"},
408 m
= Py_InitModule("Evt", Evt_methods
);
409 d
= PyModule_GetDict(m
);
410 Evt_Error
= PyMac_GetOSErrException();
411 if (Evt_Error
== NULL
||
412 PyDict_SetItemString(d
, "Error", Evt_Error
) != 0)
413 Py_FatalError("can't initialize Evt.Error");
416 /* ========================= End module Evt ========================= */