Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame^] | 1 | |
| 2 | /* =========================== Module Evt =========================== */ |
| 3 | |
| 4 | #include "Python.h" |
| 5 | |
| 6 | |
| 7 | |
| 8 | #define SystemSevenOrLater 1 |
| 9 | |
| 10 | #include "macglue.h" |
| 11 | #include <Memory.h> |
| 12 | #include <Dialogs.h> |
| 13 | #include <Menus.h> |
| 14 | #include <Controls.h> |
| 15 | |
| 16 | extern PyObject *ResObj_New(Handle); |
| 17 | extern int ResObj_Convert(PyObject *, Handle *); |
| 18 | |
| 19 | extern PyObject *WinObj_New(WindowPtr); |
| 20 | extern int WinObj_Convert(PyObject *, WindowPtr *); |
| 21 | |
| 22 | extern PyObject *DlgObj_New(DialogPtr); |
| 23 | extern int DlgObj_Convert(PyObject *, DialogPtr *); |
| 24 | extern PyTypeObject Dialog_Type; |
| 25 | #define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type) |
| 26 | |
| 27 | extern PyObject *MenuObj_New(MenuHandle); |
| 28 | extern int MenuObj_Convert(PyObject *, MenuHandle *); |
| 29 | |
| 30 | extern PyObject *CtlObj_New(ControlHandle); |
| 31 | extern int CtlObj_Convert(PyObject *, ControlHandle *); |
| 32 | |
| 33 | #include <Events.h> |
| 34 | |
| 35 | #define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */ |
| 36 | |
| 37 | static PyObject *Evt_Error; |
| 38 | |
| 39 | static PyObject *Evt_GetNextEvent(_self, _args) |
| 40 | PyObject *_self; |
| 41 | PyObject *_args; |
| 42 | { |
| 43 | PyObject *_res = NULL; |
| 44 | Boolean _rv; |
| 45 | short eventMask; |
| 46 | EventRecord theEvent; |
| 47 | if (!PyArg_ParseTuple(_args, "h", |
| 48 | &eventMask)) |
| 49 | return NULL; |
| 50 | _rv = GetNextEvent(eventMask, |
| 51 | &theEvent); |
| 52 | _res = Py_BuildValue("bO&", |
| 53 | _rv, |
| 54 | PyMac_BuildEventRecord, &theEvent); |
| 55 | return _res; |
| 56 | } |
| 57 | |
| 58 | static PyObject *Evt_WaitNextEvent(_self, _args) |
| 59 | PyObject *_self; |
| 60 | PyObject *_args; |
| 61 | { |
| 62 | PyObject *_res = NULL; |
| 63 | Boolean _rv; |
| 64 | short eventMask; |
| 65 | EventRecord theEvent; |
| 66 | unsigned long sleep; |
| 67 | if (!PyArg_ParseTuple(_args, "hl", |
| 68 | &eventMask, |
| 69 | &sleep)) |
| 70 | return NULL; |
| 71 | _rv = WaitNextEvent(eventMask, |
| 72 | &theEvent, |
| 73 | sleep, |
| 74 | (RgnHandle)0); |
| 75 | _res = Py_BuildValue("bO&", |
| 76 | _rv, |
| 77 | PyMac_BuildEventRecord, &theEvent); |
| 78 | return _res; |
| 79 | } |
| 80 | |
| 81 | static PyObject *Evt_EventAvail(_self, _args) |
| 82 | PyObject *_self; |
| 83 | PyObject *_args; |
| 84 | { |
| 85 | PyObject *_res = NULL; |
| 86 | Boolean _rv; |
| 87 | short eventMask; |
| 88 | EventRecord theEvent; |
| 89 | if (!PyArg_ParseTuple(_args, "h", |
| 90 | &eventMask)) |
| 91 | return NULL; |
| 92 | _rv = EventAvail(eventMask, |
| 93 | &theEvent); |
| 94 | _res = Py_BuildValue("bO&", |
| 95 | _rv, |
| 96 | PyMac_BuildEventRecord, &theEvent); |
| 97 | return _res; |
| 98 | } |
| 99 | |
| 100 | static PyObject *Evt_GetMouse(_self, _args) |
| 101 | PyObject *_self; |
| 102 | PyObject *_args; |
| 103 | { |
| 104 | PyObject *_res = NULL; |
| 105 | Point mouseLoc; |
| 106 | if (!PyArg_ParseTuple(_args, "")) |
| 107 | return NULL; |
| 108 | GetMouse(&mouseLoc); |
| 109 | _res = Py_BuildValue("O&", |
| 110 | PyMac_BuildPoint, mouseLoc); |
| 111 | return _res; |
| 112 | } |
| 113 | |
| 114 | static PyObject *Evt_Button(_self, _args) |
| 115 | PyObject *_self; |
| 116 | PyObject *_args; |
| 117 | { |
| 118 | PyObject *_res = NULL; |
| 119 | Boolean _rv; |
| 120 | if (!PyArg_ParseTuple(_args, "")) |
| 121 | return NULL; |
| 122 | _rv = Button(); |
| 123 | _res = Py_BuildValue("b", |
| 124 | _rv); |
| 125 | return _res; |
| 126 | } |
| 127 | |
| 128 | static PyObject *Evt_StillDown(_self, _args) |
| 129 | PyObject *_self; |
| 130 | PyObject *_args; |
| 131 | { |
| 132 | PyObject *_res = NULL; |
| 133 | Boolean _rv; |
| 134 | if (!PyArg_ParseTuple(_args, "")) |
| 135 | return NULL; |
| 136 | _rv = StillDown(); |
| 137 | _res = Py_BuildValue("b", |
| 138 | _rv); |
| 139 | return _res; |
| 140 | } |
| 141 | |
| 142 | static PyObject *Evt_WaitMouseUp(_self, _args) |
| 143 | PyObject *_self; |
| 144 | PyObject *_args; |
| 145 | { |
| 146 | PyObject *_res = NULL; |
| 147 | Boolean _rv; |
| 148 | if (!PyArg_ParseTuple(_args, "")) |
| 149 | return NULL; |
| 150 | _rv = WaitMouseUp(); |
| 151 | _res = Py_BuildValue("b", |
| 152 | _rv); |
| 153 | return _res; |
| 154 | } |
| 155 | |
| 156 | static PyObject *Evt_GetKeys(_self, _args) |
| 157 | PyObject *_self; |
| 158 | PyObject *_args; |
| 159 | { |
| 160 | PyObject *_res = NULL; |
| 161 | KeyMap theKeys__out__; |
| 162 | int theKeys__len__; |
| 163 | if (!PyArg_ParseTuple(_args, "")) |
| 164 | return NULL; |
| 165 | GetKeys(theKeys__out__); |
| 166 | _res = Py_BuildValue("s#", |
| 167 | (char *)&theKeys__out__, sizeof(KeyMap)); |
| 168 | theKeys__error__: ; |
| 169 | return _res; |
| 170 | } |
| 171 | |
| 172 | static PyObject *Evt_TickCount(_self, _args) |
| 173 | PyObject *_self; |
| 174 | PyObject *_args; |
| 175 | { |
| 176 | PyObject *_res = NULL; |
| 177 | long _rv; |
| 178 | if (!PyArg_ParseTuple(_args, "")) |
| 179 | return NULL; |
| 180 | _rv = TickCount(); |
| 181 | _res = Py_BuildValue("l", |
| 182 | _rv); |
| 183 | return _res; |
| 184 | } |
| 185 | |
| 186 | static PyMethodDef Evt_methods[] = { |
| 187 | {"GetNextEvent", (PyCFunction)Evt_GetNextEvent, 1, |
| 188 | "(short eventMask) -> (Boolean _rv, EventRecord theEvent)"}, |
| 189 | {"WaitNextEvent", (PyCFunction)Evt_WaitNextEvent, 1, |
| 190 | "(short eventMask, unsigned long sleep) -> (Boolean _rv, EventRecord theEvent)"}, |
| 191 | {"EventAvail", (PyCFunction)Evt_EventAvail, 1, |
| 192 | "(short eventMask) -> (Boolean _rv, EventRecord theEvent)"}, |
| 193 | {"GetMouse", (PyCFunction)Evt_GetMouse, 1, |
| 194 | "() -> (Point mouseLoc)"}, |
| 195 | {"Button", (PyCFunction)Evt_Button, 1, |
| 196 | "() -> (Boolean _rv)"}, |
| 197 | {"StillDown", (PyCFunction)Evt_StillDown, 1, |
| 198 | "() -> (Boolean _rv)"}, |
| 199 | {"WaitMouseUp", (PyCFunction)Evt_WaitMouseUp, 1, |
| 200 | "() -> (Boolean _rv)"}, |
| 201 | {"GetKeys", (PyCFunction)Evt_GetKeys, 1, |
| 202 | "() -> (KeyMap theKeys)"}, |
| 203 | {"TickCount", (PyCFunction)Evt_TickCount, 1, |
| 204 | "() -> (long _rv)"}, |
| 205 | {NULL, NULL, 0} |
| 206 | }; |
| 207 | |
| 208 | |
| 209 | |
| 210 | |
| 211 | void initEvt() |
| 212 | { |
| 213 | PyObject *m; |
| 214 | PyObject *d; |
| 215 | |
| 216 | |
| 217 | |
| 218 | |
| 219 | m = Py_InitModule("Evt", Evt_methods); |
| 220 | d = PyModule_GetDict(m); |
| 221 | Evt_Error = PyMac_GetOSErrException(); |
| 222 | if (Evt_Error == NULL || |
| 223 | PyDict_SetItemString(d, "Error", Evt_Error) != 0) |
| 224 | Py_FatalError("can't initialize Evt.Error"); |
| 225 | } |
| 226 | |
| 227 | /* ========================= End module Evt ========================= */ |
| 228 | |