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