blob: 1230dda74dca3bf19e4f32f8c296a0413c76e7a3 [file] [log] [blame]
Jack Jansen9c2b5142001-11-05 16:21:45 +00001
Just van Rossumc3baa0e2001-12-11 21:52:02 +00002/* ======================= Module _CarbonEvt ======================== */
Jack Jansen9c2b5142001-11-05 16:21:45 +00003
4#include "Python.h"
5
6
7
Just van Rossumc3baa0e2001-12-11 21:52:02 +00008#ifdef WITHOUT_FRAMEWORKS
9#include <CarbonEvents.h>
10#else
Jack Jansen9c2b5142001-11-05 16:21:45 +000011#include <Carbon/Carbon.h>
Just van Rossumc3baa0e2001-12-11 21:52:02 +000012#endif
13
Jack Jansen9c2b5142001-11-05 16:21:45 +000014#include "macglue.h"
15
16#define USE_MAC_MP_MULTITHREADING 1
17
18#if USE_MAC_MP_MULTITHREADING
19static PyThreadState *_save;
20static MPCriticalRegionID reentrantLock;
21#endif /* USE_MAC_MP_MULTITHREADING */
22
23extern int CFStringRef_New(CFStringRef *);
24
25extern int CFStringRef_Convert(PyObject *, CFStringRef *);
26extern int CFBundleRef_Convert(PyObject *, CFBundleRef *);
27
28int EventTargetRef_Convert(PyObject *, EventTargetRef *);
29PyObject *EventHandlerCallRef_New(EventHandlerCallRef itself);
30PyObject *EventRef_New(EventRef itself);
31
32/********** EventTypeSpec *******/
33static PyObject*
34EventTypeSpec_New(EventTypeSpec *in)
35{
36 return Py_BuildValue("ll", in->eventClass, in->eventKind);
37}
38
39static int
40EventTypeSpec_Convert(PyObject *v, EventTypeSpec *out)
41{
Just van Rossumc3baa0e2001-12-11 21:52:02 +000042 if (PyArg_Parse(v, "(O&l)", PyMac_GetOSType, &(out->eventClass), &(out->eventKind)))
Jack Jansen9c2b5142001-11-05 16:21:45 +000043 return 1;
44 return NULL;
45}
46
47/********** end EventTypeSpec *******/
48
49/********** HIPoint *******/
50
Just van Rossumc3baa0e2001-12-11 21:52:02 +000051#if 0 /* XXX doesn't compile */
Jack Jansen9c2b5142001-11-05 16:21:45 +000052static PyObject*
53HIPoint_New(HIPoint *in)
54{
55 return Py_BuildValue("ff", in->x, in->y);
56}
57
58static int
59HIPoint_Convert(PyObject *v, HIPoint *out)
60{
61 if (PyArg_ParseTuple(v, "ff", &(out->x), &(out->y)))
62 return 1;
63 return NULL;
64}
Just van Rossumc3baa0e2001-12-11 21:52:02 +000065#endif
Jack Jansen9c2b5142001-11-05 16:21:45 +000066
67/********** end HIPoint *******/
68
69/********** EventHotKeyID *******/
70
71static PyObject*
72EventHotKeyID_New(EventHotKeyID *in)
73{
74 return Py_BuildValue("ll", in->signature, in->id);
75}
76
77static int
78EventHotKeyID_Convert(PyObject *v, EventHotKeyID *out)
79{
80 if (PyArg_ParseTuple(v, "ll", &out->signature, &out->id))
81 return 1;
82 return NULL;
83}
84
85/********** end EventHotKeyID *******/
86
87/******** handlecommand ***********/
88
Just van Rossumc3baa0e2001-12-11 21:52:02 +000089static EventHandlerUPP gEventHandlerUPP;
90
91pascal OSStatus CarbonEvents_HandleEvent(EventHandlerCallRef handlerRef, EventRef event, void *outPyObject) {
Jack Jansen9c2b5142001-11-05 16:21:45 +000092 PyObject *retValue;
93 int status;
94
95#if USE_MAC_MP_MULTITHREADING
96 MPEnterCriticalRegion(reentrantLock, kDurationForever);
97 PyEval_RestoreThread(_save);
98#endif /* USE_MAC_MP_MULTITHREADING */
99
100 retValue = PyObject_CallFunction((PyObject *)outPyObject, "O&O&", EventHandlerCallRef_New, handlerRef, EventRef_New, event);
101 status = PyInt_AsLong(retValue);
102
103#if USE_MAC_MP_MULTITHREADING
104 _save = PyEval_SaveThread();
105 MPExitCriticalRegion(reentrantLock);
106#endif /* USE_MAC_MP_MULTITHREADING */
107
108 return status;
109}
110
111/******** end handlecommand ***********/
112
113
114static PyObject *CarbonEvents_Error;
115
116/* ---------------------- Object type EventRef ---------------------- */
117
118PyTypeObject EventRef_Type;
119
120#define EventRef_Check(x) ((x)->ob_type == &EventRef_Type)
121
122typedef struct EventRefObject {
123 PyObject_HEAD
124 EventRef ob_itself;
125} EventRefObject;
126
127PyObject *EventRef_New(EventRef itself)
128{
129 EventRefObject *it;
130 it = PyObject_NEW(EventRefObject, &EventRef_Type);
131 if (it == NULL) return NULL;
132 it->ob_itself = itself;
133 return (PyObject *)it;
134}
135int EventRef_Convert(PyObject *v, EventRef *p_itself)
136{
137 if (!EventRef_Check(v))
138 {
139 PyErr_SetString(PyExc_TypeError, "EventRef required");
140 return 0;
141 }
142 *p_itself = ((EventRefObject *)v)->ob_itself;
143 return 1;
144}
145
146static void EventRef_dealloc(EventRefObject *self)
147{
148 /* Cleanup of self->ob_itself goes here */
149 PyMem_DEL(self);
150}
151
152static PyObject *EventRef_RetainEvent(EventRefObject *_self, PyObject *_args)
153{
154 PyObject *_res = NULL;
155 EventRef _rv;
156 if (!PyArg_ParseTuple(_args, ""))
157 return NULL;
158 _rv = RetainEvent(_self->ob_itself);
159 _res = Py_BuildValue("O&",
160 EventRef_New, _rv);
161 return _res;
162}
163
164static PyObject *EventRef_GetEventRetainCount(EventRefObject *_self, PyObject *_args)
165{
166 PyObject *_res = NULL;
167 UInt32 _rv;
168 if (!PyArg_ParseTuple(_args, ""))
169 return NULL;
170 _rv = GetEventRetainCount(_self->ob_itself);
171 _res = Py_BuildValue("l",
172 _rv);
173 return _res;
174}
175
176static PyObject *EventRef_ReleaseEvent(EventRefObject *_self, PyObject *_args)
177{
178 PyObject *_res = NULL;
179 if (!PyArg_ParseTuple(_args, ""))
180 return NULL;
181 ReleaseEvent(_self->ob_itself);
182 Py_INCREF(Py_None);
183 _res = Py_None;
184 return _res;
185}
186
187static PyObject *EventRef_SetEventParameter(EventRefObject *_self, PyObject *_args)
188{
189 PyObject *_res = NULL;
190 OSStatus _err;
191 OSType inName;
192 OSType inType;
193 UInt32 inSize;
194 char* inDataPtr;
195 if (!PyArg_ParseTuple(_args, "O&O&ls",
196 PyMac_GetOSType, &inName,
197 PyMac_GetOSType, &inType,
198 &inSize,
199 &inDataPtr))
200 return NULL;
201 _err = SetEventParameter(_self->ob_itself,
202 inName,
203 inType,
204 inSize,
205 inDataPtr);
206 if (_err != noErr) return PyMac_Error(_err);
207 Py_INCREF(Py_None);
208 _res = Py_None;
209 return _res;
210}
211
212static PyObject *EventRef_GetEventClass(EventRefObject *_self, PyObject *_args)
213{
214 PyObject *_res = NULL;
215 UInt32 _rv;
216 if (!PyArg_ParseTuple(_args, ""))
217 return NULL;
218 _rv = GetEventClass(_self->ob_itself);
219 _res = Py_BuildValue("l",
220 _rv);
221 return _res;
222}
223
224static PyObject *EventRef_GetEventKind(EventRefObject *_self, PyObject *_args)
225{
226 PyObject *_res = NULL;
227 UInt32 _rv;
228 if (!PyArg_ParseTuple(_args, ""))
229 return NULL;
230 _rv = GetEventKind(_self->ob_itself);
231 _res = Py_BuildValue("l",
232 _rv);
233 return _res;
234}
235
236static PyObject *EventRef_GetEventTime(EventRefObject *_self, PyObject *_args)
237{
238 PyObject *_res = NULL;
239 double _rv;
240 if (!PyArg_ParseTuple(_args, ""))
241 return NULL;
242 _rv = GetEventTime(_self->ob_itself);
243 _res = Py_BuildValue("d",
244 _rv);
245 return _res;
246}
247
248static PyObject *EventRef_SetEventTime(EventRefObject *_self, PyObject *_args)
249{
250 PyObject *_res = NULL;
251 OSStatus _err;
252 double inTime;
253 if (!PyArg_ParseTuple(_args, "d",
254 &inTime))
255 return NULL;
256 _err = SetEventTime(_self->ob_itself,
257 inTime);
258 if (_err != noErr) return PyMac_Error(_err);
259 Py_INCREF(Py_None);
260 _res = Py_None;
261 return _res;
262}
263
264static PyObject *EventRef_IsUserCancelEventRef(EventRefObject *_self, PyObject *_args)
265{
266 PyObject *_res = NULL;
267 Boolean _rv;
268 if (!PyArg_ParseTuple(_args, ""))
269 return NULL;
270 _rv = IsUserCancelEventRef(_self->ob_itself);
271 _res = Py_BuildValue("b",
272 _rv);
273 return _res;
274}
275
276static PyObject *EventRef_ConvertEventRefToEventRecord(EventRefObject *_self, PyObject *_args)
277{
278 PyObject *_res = NULL;
279 Boolean _rv;
280 EventRecord outEvent;
281 if (!PyArg_ParseTuple(_args, ""))
282 return NULL;
283 _rv = ConvertEventRefToEventRecord(_self->ob_itself,
284 &outEvent);
285 _res = Py_BuildValue("bO&",
286 _rv,
287 PyMac_BuildEventRecord, &outEvent);
288 return _res;
289}
290
291static PyObject *EventRef_IsEventInMask(EventRefObject *_self, PyObject *_args)
292{
293 PyObject *_res = NULL;
294 Boolean _rv;
295 UInt16 inMask;
296 if (!PyArg_ParseTuple(_args, "H",
297 &inMask))
298 return NULL;
299 _rv = IsEventInMask(_self->ob_itself,
300 inMask);
301 _res = Py_BuildValue("b",
302 _rv);
303 return _res;
304}
305
306static PyObject *EventRef_SendEventToEventTarget(EventRefObject *_self, PyObject *_args)
307{
308 PyObject *_res = NULL;
309 OSStatus _err;
310 EventTargetRef inTarget;
311 if (!PyArg_ParseTuple(_args, "O&",
312 EventTargetRef_Convert, &inTarget))
313 return NULL;
314 _err = SendEventToEventTarget(_self->ob_itself,
315 inTarget);
316 if (_err != noErr) return PyMac_Error(_err);
317 Py_INCREF(Py_None);
318 _res = Py_None;
319 return _res;
320}
321
322static PyMethodDef EventRef_methods[] = {
323 {"RetainEvent", (PyCFunction)EventRef_RetainEvent, 1,
324 "() -> (EventRef _rv)"},
325 {"GetEventRetainCount", (PyCFunction)EventRef_GetEventRetainCount, 1,
326 "() -> (UInt32 _rv)"},
327 {"ReleaseEvent", (PyCFunction)EventRef_ReleaseEvent, 1,
328 "() -> None"},
329 {"SetEventParameter", (PyCFunction)EventRef_SetEventParameter, 1,
330 "(OSType inName, OSType inType, UInt32 inSize, char* inDataPtr) -> None"},
331 {"GetEventClass", (PyCFunction)EventRef_GetEventClass, 1,
332 "() -> (UInt32 _rv)"},
333 {"GetEventKind", (PyCFunction)EventRef_GetEventKind, 1,
334 "() -> (UInt32 _rv)"},
335 {"GetEventTime", (PyCFunction)EventRef_GetEventTime, 1,
336 "() -> (double _rv)"},
337 {"SetEventTime", (PyCFunction)EventRef_SetEventTime, 1,
338 "(double inTime) -> None"},
339 {"IsUserCancelEventRef", (PyCFunction)EventRef_IsUserCancelEventRef, 1,
340 "() -> (Boolean _rv)"},
341 {"ConvertEventRefToEventRecord", (PyCFunction)EventRef_ConvertEventRefToEventRecord, 1,
342 "() -> (Boolean _rv, EventRecord outEvent)"},
343 {"IsEventInMask", (PyCFunction)EventRef_IsEventInMask, 1,
344 "(UInt16 inMask) -> (Boolean _rv)"},
345 {"SendEventToEventTarget", (PyCFunction)EventRef_SendEventToEventTarget, 1,
346 "(EventTargetRef inTarget) -> None"},
347 {NULL, NULL, 0}
348};
349
350PyMethodChain EventRef_chain = { EventRef_methods, NULL };
351
352static PyObject *EventRef_getattr(EventRefObject *self, char *name)
353{
354 return Py_FindMethodInChain(&EventRef_chain, (PyObject *)self, name);
355}
356
357#define EventRef_setattr NULL
358
359#define EventRef_compare NULL
360
361#define EventRef_repr NULL
362
363#define EventRef_hash NULL
364
365PyTypeObject EventRef_Type = {
Just van Rossumc3baa0e2001-12-11 21:52:02 +0000366 PyObject_HEAD_INIT(NULL)
Jack Jansen9c2b5142001-11-05 16:21:45 +0000367 0, /*ob_size*/
Just van Rossumc3baa0e2001-12-11 21:52:02 +0000368 "_CarbonEvt.EventRef", /*tp_name*/
Jack Jansen9c2b5142001-11-05 16:21:45 +0000369 sizeof(EventRefObject), /*tp_basicsize*/
370 0, /*tp_itemsize*/
371 /* methods */
372 (destructor) EventRef_dealloc, /*tp_dealloc*/
373 0, /*tp_print*/
374 (getattrfunc) EventRef_getattr, /*tp_getattr*/
375 (setattrfunc) EventRef_setattr, /*tp_setattr*/
376 (cmpfunc) EventRef_compare, /*tp_compare*/
377 (reprfunc) EventRef_repr, /*tp_repr*/
378 (PyNumberMethods *)0, /* tp_as_number */
379 (PySequenceMethods *)0, /* tp_as_sequence */
380 (PyMappingMethods *)0, /* tp_as_mapping */
381 (hashfunc) EventRef_hash, /*tp_hash*/
382};
383
384/* -------------------- End object type EventRef -------------------- */
385
386
387/* ------------------- Object type EventQueueRef -------------------- */
388
389PyTypeObject EventQueueRef_Type;
390
391#define EventQueueRef_Check(x) ((x)->ob_type == &EventQueueRef_Type)
392
393typedef struct EventQueueRefObject {
394 PyObject_HEAD
395 EventQueueRef ob_itself;
396} EventQueueRefObject;
397
398PyObject *EventQueueRef_New(EventQueueRef itself)
399{
400 EventQueueRefObject *it;
401 it = PyObject_NEW(EventQueueRefObject, &EventQueueRef_Type);
402 if (it == NULL) return NULL;
403 it->ob_itself = itself;
404 return (PyObject *)it;
405}
406int EventQueueRef_Convert(PyObject *v, EventQueueRef *p_itself)
407{
408 if (!EventQueueRef_Check(v))
409 {
410 PyErr_SetString(PyExc_TypeError, "EventQueueRef required");
411 return 0;
412 }
413 *p_itself = ((EventQueueRefObject *)v)->ob_itself;
414 return 1;
415}
416
417static void EventQueueRef_dealloc(EventQueueRefObject *self)
418{
419 /* Cleanup of self->ob_itself goes here */
420 PyMem_DEL(self);
421}
422
423static PyObject *EventQueueRef_PostEventToQueue(EventQueueRefObject *_self, PyObject *_args)
424{
425 PyObject *_res = NULL;
426 OSStatus _err;
427 EventRef inEvent;
428 SInt16 inPriority;
429 if (!PyArg_ParseTuple(_args, "O&h",
430 EventRef_Convert, &inEvent,
431 &inPriority))
432 return NULL;
433 _err = PostEventToQueue(_self->ob_itself,
434 inEvent,
435 inPriority);
436 if (_err != noErr) return PyMac_Error(_err);
437 Py_INCREF(Py_None);
438 _res = Py_None;
439 return _res;
440}
441
442static PyObject *EventQueueRef_FlushEventsMatchingListFromQueue(EventQueueRefObject *_self, PyObject *_args)
443{
444 PyObject *_res = NULL;
445 OSStatus _err;
446 UInt32 inNumTypes;
Just van Rossumc3baa0e2001-12-11 21:52:02 +0000447 EventTypeSpec inList;
Jack Jansen9c2b5142001-11-05 16:21:45 +0000448 if (!PyArg_ParseTuple(_args, "lO&",
449 &inNumTypes,
450 EventTypeSpec_Convert, &inList))
451 return NULL;
452 _err = FlushEventsMatchingListFromQueue(_self->ob_itself,
453 inNumTypes,
454 &inList);
455 if (_err != noErr) return PyMac_Error(_err);
456 Py_INCREF(Py_None);
457 _res = Py_None;
458 return _res;
459}
460
461static PyObject *EventQueueRef_FlushEventQueue(EventQueueRefObject *_self, PyObject *_args)
462{
463 PyObject *_res = NULL;
464 OSStatus _err;
465 if (!PyArg_ParseTuple(_args, ""))
466 return NULL;
467 _err = FlushEventQueue(_self->ob_itself);
468 if (_err != noErr) return PyMac_Error(_err);
469 Py_INCREF(Py_None);
470 _res = Py_None;
471 return _res;
472}
473
474static PyObject *EventQueueRef_GetNumEventsInQueue(EventQueueRefObject *_self, PyObject *_args)
475{
476 PyObject *_res = NULL;
477 UInt32 _rv;
478 if (!PyArg_ParseTuple(_args, ""))
479 return NULL;
480 _rv = GetNumEventsInQueue(_self->ob_itself);
481 _res = Py_BuildValue("l",
482 _rv);
483 return _res;
484}
485
486static PyObject *EventQueueRef_RemoveEventFromQueue(EventQueueRefObject *_self, PyObject *_args)
487{
488 PyObject *_res = NULL;
489 OSStatus _err;
490 EventRef inEvent;
491 if (!PyArg_ParseTuple(_args, "O&",
492 EventRef_Convert, &inEvent))
493 return NULL;
494 _err = RemoveEventFromQueue(_self->ob_itself,
495 inEvent);
496 if (_err != noErr) return PyMac_Error(_err);
497 Py_INCREF(Py_None);
498 _res = Py_None;
499 return _res;
500}
501
502static PyObject *EventQueueRef_IsEventInQueue(EventQueueRefObject *_self, PyObject *_args)
503{
504 PyObject *_res = NULL;
505 Boolean _rv;
506 EventRef inEvent;
507 if (!PyArg_ParseTuple(_args, "O&",
508 EventRef_Convert, &inEvent))
509 return NULL;
510 _rv = IsEventInQueue(_self->ob_itself,
511 inEvent);
512 _res = Py_BuildValue("b",
513 _rv);
514 return _res;
515}
516
517static PyMethodDef EventQueueRef_methods[] = {
518 {"PostEventToQueue", (PyCFunction)EventQueueRef_PostEventToQueue, 1,
519 "(EventRef inEvent, SInt16 inPriority) -> None"},
520 {"FlushEventsMatchingListFromQueue", (PyCFunction)EventQueueRef_FlushEventsMatchingListFromQueue, 1,
Just van Rossumc3baa0e2001-12-11 21:52:02 +0000521 "(UInt32 inNumTypes, EventTypeSpec inList) -> None"},
Jack Jansen9c2b5142001-11-05 16:21:45 +0000522 {"FlushEventQueue", (PyCFunction)EventQueueRef_FlushEventQueue, 1,
523 "() -> None"},
524 {"GetNumEventsInQueue", (PyCFunction)EventQueueRef_GetNumEventsInQueue, 1,
525 "() -> (UInt32 _rv)"},
526 {"RemoveEventFromQueue", (PyCFunction)EventQueueRef_RemoveEventFromQueue, 1,
527 "(EventRef inEvent) -> None"},
528 {"IsEventInQueue", (PyCFunction)EventQueueRef_IsEventInQueue, 1,
529 "(EventRef inEvent) -> (Boolean _rv)"},
530 {NULL, NULL, 0}
531};
532
533PyMethodChain EventQueueRef_chain = { EventQueueRef_methods, NULL };
534
535static PyObject *EventQueueRef_getattr(EventQueueRefObject *self, char *name)
536{
537 return Py_FindMethodInChain(&EventQueueRef_chain, (PyObject *)self, name);
538}
539
540#define EventQueueRef_setattr NULL
541
542#define EventQueueRef_compare NULL
543
544#define EventQueueRef_repr NULL
545
546#define EventQueueRef_hash NULL
547
548PyTypeObject EventQueueRef_Type = {
Just van Rossumc3baa0e2001-12-11 21:52:02 +0000549 PyObject_HEAD_INIT(NULL)
Jack Jansen9c2b5142001-11-05 16:21:45 +0000550 0, /*ob_size*/
Just van Rossumc3baa0e2001-12-11 21:52:02 +0000551 "_CarbonEvt.EventQueueRef", /*tp_name*/
Jack Jansen9c2b5142001-11-05 16:21:45 +0000552 sizeof(EventQueueRefObject), /*tp_basicsize*/
553 0, /*tp_itemsize*/
554 /* methods */
555 (destructor) EventQueueRef_dealloc, /*tp_dealloc*/
556 0, /*tp_print*/
557 (getattrfunc) EventQueueRef_getattr, /*tp_getattr*/
558 (setattrfunc) EventQueueRef_setattr, /*tp_setattr*/
559 (cmpfunc) EventQueueRef_compare, /*tp_compare*/
560 (reprfunc) EventQueueRef_repr, /*tp_repr*/
561 (PyNumberMethods *)0, /* tp_as_number */
562 (PySequenceMethods *)0, /* tp_as_sequence */
563 (PyMappingMethods *)0, /* tp_as_mapping */
564 (hashfunc) EventQueueRef_hash, /*tp_hash*/
565};
566
567/* ----------------- End object type EventQueueRef ------------------ */
568
569
570/* -------------------- Object type EventLoopRef -------------------- */
571
572PyTypeObject EventLoopRef_Type;
573
574#define EventLoopRef_Check(x) ((x)->ob_type == &EventLoopRef_Type)
575
576typedef struct EventLoopRefObject {
577 PyObject_HEAD
578 EventLoopRef ob_itself;
579} EventLoopRefObject;
580
581PyObject *EventLoopRef_New(EventLoopRef itself)
582{
583 EventLoopRefObject *it;
584 it = PyObject_NEW(EventLoopRefObject, &EventLoopRef_Type);
585 if (it == NULL) return NULL;
586 it->ob_itself = itself;
587 return (PyObject *)it;
588}
589int EventLoopRef_Convert(PyObject *v, EventLoopRef *p_itself)
590{
591 if (!EventLoopRef_Check(v))
592 {
593 PyErr_SetString(PyExc_TypeError, "EventLoopRef required");
594 return 0;
595 }
596 *p_itself = ((EventLoopRefObject *)v)->ob_itself;
597 return 1;
598}
599
600static void EventLoopRef_dealloc(EventLoopRefObject *self)
601{
602 /* Cleanup of self->ob_itself goes here */
603 PyMem_DEL(self);
604}
605
606static PyObject *EventLoopRef_QuitEventLoop(EventLoopRefObject *_self, PyObject *_args)
607{
608 PyObject *_res = NULL;
609 OSStatus _err;
610 if (!PyArg_ParseTuple(_args, ""))
611 return NULL;
612 _err = QuitEventLoop(_self->ob_itself);
613 if (_err != noErr) return PyMac_Error(_err);
614 Py_INCREF(Py_None);
615 _res = Py_None;
616 return _res;
617}
618
619static PyMethodDef EventLoopRef_methods[] = {
620 {"QuitEventLoop", (PyCFunction)EventLoopRef_QuitEventLoop, 1,
621 "() -> None"},
622 {NULL, NULL, 0}
623};
624
625PyMethodChain EventLoopRef_chain = { EventLoopRef_methods, NULL };
626
627static PyObject *EventLoopRef_getattr(EventLoopRefObject *self, char *name)
628{
629 return Py_FindMethodInChain(&EventLoopRef_chain, (PyObject *)self, name);
630}
631
632#define EventLoopRef_setattr NULL
633
634#define EventLoopRef_compare NULL
635
636#define EventLoopRef_repr NULL
637
638#define EventLoopRef_hash NULL
639
640PyTypeObject EventLoopRef_Type = {
Just van Rossumc3baa0e2001-12-11 21:52:02 +0000641 PyObject_HEAD_INIT(NULL)
Jack Jansen9c2b5142001-11-05 16:21:45 +0000642 0, /*ob_size*/
Just van Rossumc3baa0e2001-12-11 21:52:02 +0000643 "_CarbonEvt.EventLoopRef", /*tp_name*/
Jack Jansen9c2b5142001-11-05 16:21:45 +0000644 sizeof(EventLoopRefObject), /*tp_basicsize*/
645 0, /*tp_itemsize*/
646 /* methods */
647 (destructor) EventLoopRef_dealloc, /*tp_dealloc*/
648 0, /*tp_print*/
649 (getattrfunc) EventLoopRef_getattr, /*tp_getattr*/
650 (setattrfunc) EventLoopRef_setattr, /*tp_setattr*/
651 (cmpfunc) EventLoopRef_compare, /*tp_compare*/
652 (reprfunc) EventLoopRef_repr, /*tp_repr*/
653 (PyNumberMethods *)0, /* tp_as_number */
654 (PySequenceMethods *)0, /* tp_as_sequence */
655 (PyMappingMethods *)0, /* tp_as_mapping */
656 (hashfunc) EventLoopRef_hash, /*tp_hash*/
657};
658
659/* ------------------ End object type EventLoopRef ------------------ */
660
661
662/* ----------------- Object type EventLoopTimerRef ------------------ */
663
664PyTypeObject EventLoopTimerRef_Type;
665
666#define EventLoopTimerRef_Check(x) ((x)->ob_type == &EventLoopTimerRef_Type)
667
668typedef struct EventLoopTimerRefObject {
669 PyObject_HEAD
670 EventLoopTimerRef ob_itself;
671} EventLoopTimerRefObject;
672
673PyObject *EventLoopTimerRef_New(EventLoopTimerRef itself)
674{
675 EventLoopTimerRefObject *it;
676 it = PyObject_NEW(EventLoopTimerRefObject, &EventLoopTimerRef_Type);
677 if (it == NULL) return NULL;
678 it->ob_itself = itself;
679 return (PyObject *)it;
680}
681int EventLoopTimerRef_Convert(PyObject *v, EventLoopTimerRef *p_itself)
682{
683 if (!EventLoopTimerRef_Check(v))
684 {
685 PyErr_SetString(PyExc_TypeError, "EventLoopTimerRef required");
686 return 0;
687 }
688 *p_itself = ((EventLoopTimerRefObject *)v)->ob_itself;
689 return 1;
690}
691
692static void EventLoopTimerRef_dealloc(EventLoopTimerRefObject *self)
693{
694 /* Cleanup of self->ob_itself goes here */
695 PyMem_DEL(self);
696}
697
698static PyObject *EventLoopTimerRef_RemoveEventLoopTimer(EventLoopTimerRefObject *_self, PyObject *_args)
699{
700 PyObject *_res = NULL;
701 OSStatus _err;
702 if (!PyArg_ParseTuple(_args, ""))
703 return NULL;
704 _err = RemoveEventLoopTimer(_self->ob_itself);
705 if (_err != noErr) return PyMac_Error(_err);
706 Py_INCREF(Py_None);
707 _res = Py_None;
708 return _res;
709}
710
711static PyObject *EventLoopTimerRef_SetEventLoopTimerNextFireTime(EventLoopTimerRefObject *_self, PyObject *_args)
712{
713 PyObject *_res = NULL;
714 OSStatus _err;
715 double inNextFire;
716 if (!PyArg_ParseTuple(_args, "d",
717 &inNextFire))
718 return NULL;
719 _err = SetEventLoopTimerNextFireTime(_self->ob_itself,
720 inNextFire);
721 if (_err != noErr) return PyMac_Error(_err);
722 Py_INCREF(Py_None);
723 _res = Py_None;
724 return _res;
725}
726
727static PyMethodDef EventLoopTimerRef_methods[] = {
728 {"RemoveEventLoopTimer", (PyCFunction)EventLoopTimerRef_RemoveEventLoopTimer, 1,
729 "() -> None"},
730 {"SetEventLoopTimerNextFireTime", (PyCFunction)EventLoopTimerRef_SetEventLoopTimerNextFireTime, 1,
731 "(double inNextFire) -> None"},
732 {NULL, NULL, 0}
733};
734
735PyMethodChain EventLoopTimerRef_chain = { EventLoopTimerRef_methods, NULL };
736
737static PyObject *EventLoopTimerRef_getattr(EventLoopTimerRefObject *self, char *name)
738{
739 return Py_FindMethodInChain(&EventLoopTimerRef_chain, (PyObject *)self, name);
740}
741
742#define EventLoopTimerRef_setattr NULL
743
744#define EventLoopTimerRef_compare NULL
745
746#define EventLoopTimerRef_repr NULL
747
748#define EventLoopTimerRef_hash NULL
749
750PyTypeObject EventLoopTimerRef_Type = {
Just van Rossumc3baa0e2001-12-11 21:52:02 +0000751 PyObject_HEAD_INIT(NULL)
Jack Jansen9c2b5142001-11-05 16:21:45 +0000752 0, /*ob_size*/
Just van Rossumc3baa0e2001-12-11 21:52:02 +0000753 "_CarbonEvt.EventLoopTimerRef", /*tp_name*/
Jack Jansen9c2b5142001-11-05 16:21:45 +0000754 sizeof(EventLoopTimerRefObject), /*tp_basicsize*/
755 0, /*tp_itemsize*/
756 /* methods */
757 (destructor) EventLoopTimerRef_dealloc, /*tp_dealloc*/
758 0, /*tp_print*/
759 (getattrfunc) EventLoopTimerRef_getattr, /*tp_getattr*/
760 (setattrfunc) EventLoopTimerRef_setattr, /*tp_setattr*/
761 (cmpfunc) EventLoopTimerRef_compare, /*tp_compare*/
762 (reprfunc) EventLoopTimerRef_repr, /*tp_repr*/
763 (PyNumberMethods *)0, /* tp_as_number */
764 (PySequenceMethods *)0, /* tp_as_sequence */
765 (PyMappingMethods *)0, /* tp_as_mapping */
766 (hashfunc) EventLoopTimerRef_hash, /*tp_hash*/
767};
768
769/* --------------- End object type EventLoopTimerRef ---------------- */
770
771
772/* ------------------ Object type EventHandlerRef ------------------- */
773
774PyTypeObject EventHandlerRef_Type;
775
776#define EventHandlerRef_Check(x) ((x)->ob_type == &EventHandlerRef_Type)
777
778typedef struct EventHandlerRefObject {
779 PyObject_HEAD
780 EventHandlerRef ob_itself;
781} EventHandlerRefObject;
782
783PyObject *EventHandlerRef_New(EventHandlerRef itself)
784{
785 EventHandlerRefObject *it;
786 it = PyObject_NEW(EventHandlerRefObject, &EventHandlerRef_Type);
787 if (it == NULL) return NULL;
788 it->ob_itself = itself;
789 return (PyObject *)it;
790}
791int EventHandlerRef_Convert(PyObject *v, EventHandlerRef *p_itself)
792{
793 if (!EventHandlerRef_Check(v))
794 {
795 PyErr_SetString(PyExc_TypeError, "EventHandlerRef required");
796 return 0;
797 }
798 *p_itself = ((EventHandlerRefObject *)v)->ob_itself;
799 return 1;
800}
801
802static void EventHandlerRef_dealloc(EventHandlerRefObject *self)
803{
804 /* Cleanup of self->ob_itself goes here */
805 PyMem_DEL(self);
806}
807
808static PyObject *EventHandlerRef_RemoveEventHandler(EventHandlerRefObject *_self, PyObject *_args)
809{
810 PyObject *_res = NULL;
811 OSStatus _err;
812 if (!PyArg_ParseTuple(_args, ""))
813 return NULL;
814 _err = RemoveEventHandler(_self->ob_itself);
815 if (_err != noErr) return PyMac_Error(_err);
816 Py_INCREF(Py_None);
817 _res = Py_None;
818 return _res;
819}
820
821static PyObject *EventHandlerRef_AddEventTypesToHandler(EventHandlerRefObject *_self, PyObject *_args)
822{
823 PyObject *_res = NULL;
824 OSStatus _err;
825 UInt32 inNumTypes;
Just van Rossumc3baa0e2001-12-11 21:52:02 +0000826 EventTypeSpec inList;
Jack Jansen9c2b5142001-11-05 16:21:45 +0000827 if (!PyArg_ParseTuple(_args, "lO&",
828 &inNumTypes,
829 EventTypeSpec_Convert, &inList))
830 return NULL;
831 _err = AddEventTypesToHandler(_self->ob_itself,
832 inNumTypes,
833 &inList);
834 if (_err != noErr) return PyMac_Error(_err);
835 Py_INCREF(Py_None);
836 _res = Py_None;
837 return _res;
838}
839
840static PyObject *EventHandlerRef_RemoveEventTypesFromHandler(EventHandlerRefObject *_self, PyObject *_args)
841{
842 PyObject *_res = NULL;
843 OSStatus _err;
844 UInt32 inNumTypes;
Just van Rossumc3baa0e2001-12-11 21:52:02 +0000845 EventTypeSpec inList;
Jack Jansen9c2b5142001-11-05 16:21:45 +0000846 if (!PyArg_ParseTuple(_args, "lO&",
847 &inNumTypes,
848 EventTypeSpec_Convert, &inList))
849 return NULL;
850 _err = RemoveEventTypesFromHandler(_self->ob_itself,
851 inNumTypes,
852 &inList);
853 if (_err != noErr) return PyMac_Error(_err);
854 Py_INCREF(Py_None);
855 _res = Py_None;
856 return _res;
857}
858
859static PyMethodDef EventHandlerRef_methods[] = {
860 {"RemoveEventHandler", (PyCFunction)EventHandlerRef_RemoveEventHandler, 1,
861 "() -> None"},
862 {"AddEventTypesToHandler", (PyCFunction)EventHandlerRef_AddEventTypesToHandler, 1,
Just van Rossumc3baa0e2001-12-11 21:52:02 +0000863 "(UInt32 inNumTypes, EventTypeSpec inList) -> None"},
Jack Jansen9c2b5142001-11-05 16:21:45 +0000864 {"RemoveEventTypesFromHandler", (PyCFunction)EventHandlerRef_RemoveEventTypesFromHandler, 1,
Just van Rossumc3baa0e2001-12-11 21:52:02 +0000865 "(UInt32 inNumTypes, EventTypeSpec inList) -> None"},
Jack Jansen9c2b5142001-11-05 16:21:45 +0000866 {NULL, NULL, 0}
867};
868
869PyMethodChain EventHandlerRef_chain = { EventHandlerRef_methods, NULL };
870
871static PyObject *EventHandlerRef_getattr(EventHandlerRefObject *self, char *name)
872{
873 return Py_FindMethodInChain(&EventHandlerRef_chain, (PyObject *)self, name);
874}
875
876#define EventHandlerRef_setattr NULL
877
878#define EventHandlerRef_compare NULL
879
880#define EventHandlerRef_repr NULL
881
882#define EventHandlerRef_hash NULL
883
884PyTypeObject EventHandlerRef_Type = {
Just van Rossumc3baa0e2001-12-11 21:52:02 +0000885 PyObject_HEAD_INIT(NULL)
Jack Jansen9c2b5142001-11-05 16:21:45 +0000886 0, /*ob_size*/
Just van Rossumc3baa0e2001-12-11 21:52:02 +0000887 "_CarbonEvt.EventHandlerRef", /*tp_name*/
Jack Jansen9c2b5142001-11-05 16:21:45 +0000888 sizeof(EventHandlerRefObject), /*tp_basicsize*/
889 0, /*tp_itemsize*/
890 /* methods */
891 (destructor) EventHandlerRef_dealloc, /*tp_dealloc*/
892 0, /*tp_print*/
893 (getattrfunc) EventHandlerRef_getattr, /*tp_getattr*/
894 (setattrfunc) EventHandlerRef_setattr, /*tp_setattr*/
895 (cmpfunc) EventHandlerRef_compare, /*tp_compare*/
896 (reprfunc) EventHandlerRef_repr, /*tp_repr*/
897 (PyNumberMethods *)0, /* tp_as_number */
898 (PySequenceMethods *)0, /* tp_as_sequence */
899 (PyMappingMethods *)0, /* tp_as_mapping */
900 (hashfunc) EventHandlerRef_hash, /*tp_hash*/
901};
902
903/* ---------------- End object type EventHandlerRef ----------------- */
904
905
906/* ---------------- Object type EventHandlerCallRef ----------------- */
907
908PyTypeObject EventHandlerCallRef_Type;
909
910#define EventHandlerCallRef_Check(x) ((x)->ob_type == &EventHandlerCallRef_Type)
911
912typedef struct EventHandlerCallRefObject {
913 PyObject_HEAD
914 EventHandlerCallRef ob_itself;
915} EventHandlerCallRefObject;
916
917PyObject *EventHandlerCallRef_New(EventHandlerCallRef itself)
918{
919 EventHandlerCallRefObject *it;
920 it = PyObject_NEW(EventHandlerCallRefObject, &EventHandlerCallRef_Type);
921 if (it == NULL) return NULL;
922 it->ob_itself = itself;
923 return (PyObject *)it;
924}
925int EventHandlerCallRef_Convert(PyObject *v, EventHandlerCallRef *p_itself)
926{
927 if (!EventHandlerCallRef_Check(v))
928 {
929 PyErr_SetString(PyExc_TypeError, "EventHandlerCallRef required");
930 return 0;
931 }
932 *p_itself = ((EventHandlerCallRefObject *)v)->ob_itself;
933 return 1;
934}
935
936static void EventHandlerCallRef_dealloc(EventHandlerCallRefObject *self)
937{
938 /* Cleanup of self->ob_itself goes here */
939 PyMem_DEL(self);
940}
941
942static PyObject *EventHandlerCallRef_CallNextEventHandler(EventHandlerCallRefObject *_self, PyObject *_args)
943{
944 PyObject *_res = NULL;
945 OSStatus _err;
946 EventRef inEvent;
947 if (!PyArg_ParseTuple(_args, "O&",
948 EventRef_Convert, &inEvent))
949 return NULL;
950 _err = CallNextEventHandler(_self->ob_itself,
951 inEvent);
952 if (_err != noErr) return PyMac_Error(_err);
953 Py_INCREF(Py_None);
954 _res = Py_None;
955 return _res;
956}
957
958static PyMethodDef EventHandlerCallRef_methods[] = {
959 {"CallNextEventHandler", (PyCFunction)EventHandlerCallRef_CallNextEventHandler, 1,
960 "(EventRef inEvent) -> None"},
961 {NULL, NULL, 0}
962};
963
964PyMethodChain EventHandlerCallRef_chain = { EventHandlerCallRef_methods, NULL };
965
966static PyObject *EventHandlerCallRef_getattr(EventHandlerCallRefObject *self, char *name)
967{
968 return Py_FindMethodInChain(&EventHandlerCallRef_chain, (PyObject *)self, name);
969}
970
971#define EventHandlerCallRef_setattr NULL
972
973#define EventHandlerCallRef_compare NULL
974
975#define EventHandlerCallRef_repr NULL
976
977#define EventHandlerCallRef_hash NULL
978
979PyTypeObject EventHandlerCallRef_Type = {
Just van Rossumc3baa0e2001-12-11 21:52:02 +0000980 PyObject_HEAD_INIT(NULL)
Jack Jansen9c2b5142001-11-05 16:21:45 +0000981 0, /*ob_size*/
Just van Rossumc3baa0e2001-12-11 21:52:02 +0000982 "_CarbonEvt.EventHandlerCallRef", /*tp_name*/
Jack Jansen9c2b5142001-11-05 16:21:45 +0000983 sizeof(EventHandlerCallRefObject), /*tp_basicsize*/
984 0, /*tp_itemsize*/
985 /* methods */
986 (destructor) EventHandlerCallRef_dealloc, /*tp_dealloc*/
987 0, /*tp_print*/
988 (getattrfunc) EventHandlerCallRef_getattr, /*tp_getattr*/
989 (setattrfunc) EventHandlerCallRef_setattr, /*tp_setattr*/
990 (cmpfunc) EventHandlerCallRef_compare, /*tp_compare*/
991 (reprfunc) EventHandlerCallRef_repr, /*tp_repr*/
992 (PyNumberMethods *)0, /* tp_as_number */
993 (PySequenceMethods *)0, /* tp_as_sequence */
994 (PyMappingMethods *)0, /* tp_as_mapping */
995 (hashfunc) EventHandlerCallRef_hash, /*tp_hash*/
996};
997
998/* -------------- End object type EventHandlerCallRef --------------- */
999
1000
1001/* ------------------- Object type EventTargetRef ------------------- */
1002
1003PyTypeObject EventTargetRef_Type;
1004
1005#define EventTargetRef_Check(x) ((x)->ob_type == &EventTargetRef_Type)
1006
1007typedef struct EventTargetRefObject {
1008 PyObject_HEAD
1009 EventTargetRef ob_itself;
1010} EventTargetRefObject;
1011
1012PyObject *EventTargetRef_New(EventTargetRef itself)
1013{
1014 EventTargetRefObject *it;
1015 it = PyObject_NEW(EventTargetRefObject, &EventTargetRef_Type);
1016 if (it == NULL) return NULL;
1017 it->ob_itself = itself;
1018 return (PyObject *)it;
1019}
1020int EventTargetRef_Convert(PyObject *v, EventTargetRef *p_itself)
1021{
1022 if (!EventTargetRef_Check(v))
1023 {
1024 PyErr_SetString(PyExc_TypeError, "EventTargetRef required");
1025 return 0;
1026 }
1027 *p_itself = ((EventTargetRefObject *)v)->ob_itself;
1028 return 1;
1029}
1030
1031static void EventTargetRef_dealloc(EventTargetRefObject *self)
1032{
1033 /* Cleanup of self->ob_itself goes here */
1034 PyMem_DEL(self);
1035}
1036
1037static PyObject *EventTargetRef_InstallStandardEventHandler(EventTargetRefObject *_self, PyObject *_args)
1038{
1039 PyObject *_res = NULL;
1040 OSStatus _err;
1041 if (!PyArg_ParseTuple(_args, ""))
1042 return NULL;
1043 _err = InstallStandardEventHandler(_self->ob_itself);
1044 if (_err != noErr) return PyMac_Error(_err);
1045 Py_INCREF(Py_None);
1046 _res = Py_None;
1047 return _res;
1048}
1049
1050static PyObject *EventTargetRef_InstallEventHandler(EventTargetRefObject *_self, PyObject *_args)
1051{
1052 PyObject *_res = NULL;
1053
1054 EventTypeSpec inSpec;
1055 PyObject *callback;
1056 EventHandlerRef outRef;
1057 OSStatus _err;
Jack Jansen9c2b5142001-11-05 16:21:45 +00001058
1059 if (!PyArg_ParseTuple(_args, "O&O", EventTypeSpec_Convert, &inSpec, &callback))
1060 return NULL;
1061
Just van Rossumc3baa0e2001-12-11 21:52:02 +00001062 _err = InstallEventHandler(_self->ob_itself, gEventHandlerUPP, 1, &inSpec, (void *)callback, &outRef);
Jack Jansen9c2b5142001-11-05 16:21:45 +00001063 if (_err != noErr) return PyMac_Error(_err);
1064
Just van Rossumc3baa0e2001-12-11 21:52:02 +00001065 return Py_BuildValue("O&", EventHandlerRef_New, outRef);
Jack Jansen9c2b5142001-11-05 16:21:45 +00001066}
1067
1068static PyMethodDef EventTargetRef_methods[] = {
1069 {"InstallStandardEventHandler", (PyCFunction)EventTargetRef_InstallStandardEventHandler, 1,
1070 "() -> None"},
1071 {"InstallEventHandler", (PyCFunction)EventTargetRef_InstallEventHandler, 1,
1072 "(EventTargetRef inTarget, EventTypeSpec inSpec, Method callback) -> (EventHandlerRef outRef)"},
1073 {NULL, NULL, 0}
1074};
1075
1076PyMethodChain EventTargetRef_chain = { EventTargetRef_methods, NULL };
1077
1078static PyObject *EventTargetRef_getattr(EventTargetRefObject *self, char *name)
1079{
1080 return Py_FindMethodInChain(&EventTargetRef_chain, (PyObject *)self, name);
1081}
1082
1083#define EventTargetRef_setattr NULL
1084
1085#define EventTargetRef_compare NULL
1086
1087#define EventTargetRef_repr NULL
1088
1089#define EventTargetRef_hash NULL
1090
1091PyTypeObject EventTargetRef_Type = {
Just van Rossumc3baa0e2001-12-11 21:52:02 +00001092 PyObject_HEAD_INIT(NULL)
Jack Jansen9c2b5142001-11-05 16:21:45 +00001093 0, /*ob_size*/
Just van Rossumc3baa0e2001-12-11 21:52:02 +00001094 "_CarbonEvt.EventTargetRef", /*tp_name*/
Jack Jansen9c2b5142001-11-05 16:21:45 +00001095 sizeof(EventTargetRefObject), /*tp_basicsize*/
1096 0, /*tp_itemsize*/
1097 /* methods */
1098 (destructor) EventTargetRef_dealloc, /*tp_dealloc*/
1099 0, /*tp_print*/
1100 (getattrfunc) EventTargetRef_getattr, /*tp_getattr*/
1101 (setattrfunc) EventTargetRef_setattr, /*tp_setattr*/
1102 (cmpfunc) EventTargetRef_compare, /*tp_compare*/
1103 (reprfunc) EventTargetRef_repr, /*tp_repr*/
1104 (PyNumberMethods *)0, /* tp_as_number */
1105 (PySequenceMethods *)0, /* tp_as_sequence */
1106 (PyMappingMethods *)0, /* tp_as_mapping */
1107 (hashfunc) EventTargetRef_hash, /*tp_hash*/
1108};
1109
1110/* ----------------- End object type EventTargetRef ----------------- */
1111
1112
1113/* ------------------- Object type EventHotKeyRef ------------------- */
1114
1115PyTypeObject EventHotKeyRef_Type;
1116
1117#define EventHotKeyRef_Check(x) ((x)->ob_type == &EventHotKeyRef_Type)
1118
1119typedef struct EventHotKeyRefObject {
1120 PyObject_HEAD
1121 EventHotKeyRef ob_itself;
1122} EventHotKeyRefObject;
1123
1124PyObject *EventHotKeyRef_New(EventHotKeyRef itself)
1125{
1126 EventHotKeyRefObject *it;
1127 it = PyObject_NEW(EventHotKeyRefObject, &EventHotKeyRef_Type);
1128 if (it == NULL) return NULL;
1129 it->ob_itself = itself;
1130 return (PyObject *)it;
1131}
1132int EventHotKeyRef_Convert(PyObject *v, EventHotKeyRef *p_itself)
1133{
1134 if (!EventHotKeyRef_Check(v))
1135 {
1136 PyErr_SetString(PyExc_TypeError, "EventHotKeyRef required");
1137 return 0;
1138 }
1139 *p_itself = ((EventHotKeyRefObject *)v)->ob_itself;
1140 return 1;
1141}
1142
1143static void EventHotKeyRef_dealloc(EventHotKeyRefObject *self)
1144{
1145 /* Cleanup of self->ob_itself goes here */
1146 PyMem_DEL(self);
1147}
1148
1149static PyMethodDef EventHotKeyRef_methods[] = {
1150 {NULL, NULL, 0}
1151};
1152
1153PyMethodChain EventHotKeyRef_chain = { EventHotKeyRef_methods, NULL };
1154
1155static PyObject *EventHotKeyRef_getattr(EventHotKeyRefObject *self, char *name)
1156{
1157 return Py_FindMethodInChain(&EventHotKeyRef_chain, (PyObject *)self, name);
1158}
1159
1160#define EventHotKeyRef_setattr NULL
1161
1162#define EventHotKeyRef_compare NULL
1163
1164#define EventHotKeyRef_repr NULL
1165
1166#define EventHotKeyRef_hash NULL
1167
1168PyTypeObject EventHotKeyRef_Type = {
Just van Rossumc3baa0e2001-12-11 21:52:02 +00001169 PyObject_HEAD_INIT(NULL)
Jack Jansen9c2b5142001-11-05 16:21:45 +00001170 0, /*ob_size*/
Just van Rossumc3baa0e2001-12-11 21:52:02 +00001171 "_CarbonEvt.EventHotKeyRef", /*tp_name*/
Jack Jansen9c2b5142001-11-05 16:21:45 +00001172 sizeof(EventHotKeyRefObject), /*tp_basicsize*/
1173 0, /*tp_itemsize*/
1174 /* methods */
1175 (destructor) EventHotKeyRef_dealloc, /*tp_dealloc*/
1176 0, /*tp_print*/
1177 (getattrfunc) EventHotKeyRef_getattr, /*tp_getattr*/
1178 (setattrfunc) EventHotKeyRef_setattr, /*tp_setattr*/
1179 (cmpfunc) EventHotKeyRef_compare, /*tp_compare*/
1180 (reprfunc) EventHotKeyRef_repr, /*tp_repr*/
1181 (PyNumberMethods *)0, /* tp_as_number */
1182 (PySequenceMethods *)0, /* tp_as_sequence */
1183 (PyMappingMethods *)0, /* tp_as_mapping */
1184 (hashfunc) EventHotKeyRef_hash, /*tp_hash*/
1185};
1186
1187/* ----------------- End object type EventHotKeyRef ----------------- */
1188
1189
1190static PyObject *CarbonEvents_GetCurrentEventLoop(PyObject *_self, PyObject *_args)
1191{
1192 PyObject *_res = NULL;
1193 EventLoopRef _rv;
1194 if (!PyArg_ParseTuple(_args, ""))
1195 return NULL;
1196 _rv = GetCurrentEventLoop();
1197 _res = Py_BuildValue("O&",
1198 EventLoopRef_New, _rv);
1199 return _res;
1200}
1201
1202static PyObject *CarbonEvents_GetMainEventLoop(PyObject *_self, PyObject *_args)
1203{
1204 PyObject *_res = NULL;
1205 EventLoopRef _rv;
1206 if (!PyArg_ParseTuple(_args, ""))
1207 return NULL;
1208 _rv = GetMainEventLoop();
1209 _res = Py_BuildValue("O&",
1210 EventLoopRef_New, _rv);
1211 return _res;
1212}
1213
1214static PyObject *CarbonEvents_RunCurrentEventLoop(PyObject *_self, PyObject *_args)
1215{
1216 PyObject *_res = NULL;
1217 OSStatus _err;
1218 double inTimeout;
1219 if (!PyArg_ParseTuple(_args, "d",
1220 &inTimeout))
1221 return NULL;
1222 _err = RunCurrentEventLoop(inTimeout);
1223 if (_err != noErr) return PyMac_Error(_err);
1224 Py_INCREF(Py_None);
1225 _res = Py_None;
1226 return _res;
1227}
1228
1229static PyObject *CarbonEvents_ReceiveNextEvent(PyObject *_self, PyObject *_args)
1230{
1231 PyObject *_res = NULL;
1232 OSStatus _err;
1233 UInt32 inNumTypes;
Just van Rossumc3baa0e2001-12-11 21:52:02 +00001234 EventTypeSpec inList;
Jack Jansen9c2b5142001-11-05 16:21:45 +00001235 double inTimeout;
1236 Boolean inPullEvent;
1237 EventRef outEvent;
1238 if (!PyArg_ParseTuple(_args, "lO&db",
1239 &inNumTypes,
1240 EventTypeSpec_Convert, &inList,
1241 &inTimeout,
1242 &inPullEvent))
1243 return NULL;
1244 _err = ReceiveNextEvent(inNumTypes,
1245 &inList,
1246 inTimeout,
1247 inPullEvent,
1248 &outEvent);
1249 if (_err != noErr) return PyMac_Error(_err);
1250 _res = Py_BuildValue("O&",
1251 EventRef_New, outEvent);
1252 return _res;
1253}
1254
1255static PyObject *CarbonEvents_GetCurrentEventQueue(PyObject *_self, PyObject *_args)
1256{
1257 PyObject *_res = NULL;
1258 EventQueueRef _rv;
1259 if (!PyArg_ParseTuple(_args, ""))
1260 return NULL;
1261 _rv = GetCurrentEventQueue();
1262 _res = Py_BuildValue("O&",
1263 EventQueueRef_New, _rv);
1264 return _res;
1265}
1266
1267static PyObject *CarbonEvents_GetMainEventQueue(PyObject *_self, PyObject *_args)
1268{
1269 PyObject *_res = NULL;
1270 EventQueueRef _rv;
1271 if (!PyArg_ParseTuple(_args, ""))
1272 return NULL;
1273 _rv = GetMainEventQueue();
1274 _res = Py_BuildValue("O&",
1275 EventQueueRef_New, _rv);
1276 return _res;
1277}
1278
1279static PyObject *CarbonEvents_GetCurrentEventTime(PyObject *_self, PyObject *_args)
1280{
1281 PyObject *_res = NULL;
1282 double _rv;
1283 if (!PyArg_ParseTuple(_args, ""))
1284 return NULL;
1285 _rv = GetCurrentEventTime();
1286 _res = Py_BuildValue("d",
1287 _rv);
1288 return _res;
1289}
1290
1291static PyObject *CarbonEvents_GetLastUserEventTime(PyObject *_self, PyObject *_args)
1292{
1293 PyObject *_res = NULL;
1294 double _rv;
1295 if (!PyArg_ParseTuple(_args, ""))
1296 return NULL;
1297 _rv = GetLastUserEventTime();
1298 _res = Py_BuildValue("d",
1299 _rv);
1300 return _res;
1301}
1302
1303static PyObject *CarbonEvents_GetWindowEventTarget(PyObject *_self, PyObject *_args)
1304{
1305 PyObject *_res = NULL;
1306 EventTargetRef _rv;
1307 WindowPtr inWindow;
1308 if (!PyArg_ParseTuple(_args, "O&",
1309 WinObj_Convert, &inWindow))
1310 return NULL;
1311 _rv = GetWindowEventTarget(inWindow);
1312 _res = Py_BuildValue("O&",
1313 EventTargetRef_New, _rv);
1314 return _res;
1315}
1316
1317static PyObject *CarbonEvents_GetControlEventTarget(PyObject *_self, PyObject *_args)
1318{
1319 PyObject *_res = NULL;
1320 EventTargetRef _rv;
1321 ControlHandle inControl;
1322 if (!PyArg_ParseTuple(_args, "O&",
1323 CtlObj_Convert, &inControl))
1324 return NULL;
1325 _rv = GetControlEventTarget(inControl);
1326 _res = Py_BuildValue("O&",
1327 EventTargetRef_New, _rv);
1328 return _res;
1329}
1330
1331static PyObject *CarbonEvents_GetMenuEventTarget(PyObject *_self, PyObject *_args)
1332{
1333 PyObject *_res = NULL;
1334 EventTargetRef _rv;
1335 MenuHandle inMenu;
1336 if (!PyArg_ParseTuple(_args, "O&",
1337 MenuObj_Convert, &inMenu))
1338 return NULL;
1339 _rv = GetMenuEventTarget(inMenu);
1340 _res = Py_BuildValue("O&",
1341 EventTargetRef_New, _rv);
1342 return _res;
1343}
1344
1345static PyObject *CarbonEvents_GetApplicationEventTarget(PyObject *_self, PyObject *_args)
1346{
1347 PyObject *_res = NULL;
1348 EventTargetRef _rv;
1349 if (!PyArg_ParseTuple(_args, ""))
1350 return NULL;
1351 _rv = GetApplicationEventTarget();
1352 _res = Py_BuildValue("O&",
1353 EventTargetRef_New, _rv);
1354 return _res;
1355}
1356
1357static PyObject *CarbonEvents_GetUserFocusEventTarget(PyObject *_self, PyObject *_args)
1358{
1359 PyObject *_res = NULL;
1360 EventTargetRef _rv;
1361 if (!PyArg_ParseTuple(_args, ""))
1362 return NULL;
1363 _rv = GetUserFocusEventTarget();
1364 _res = Py_BuildValue("O&",
1365 EventTargetRef_New, _rv);
1366 return _res;
1367}
1368
1369static PyObject *CarbonEvents_QuitApplicationEventLoop(PyObject *_self, PyObject *_args)
1370{
1371 PyObject *_res = NULL;
1372 if (!PyArg_ParseTuple(_args, ""))
1373 return NULL;
1374 QuitApplicationEventLoop();
1375 Py_INCREF(Py_None);
1376 _res = Py_None;
1377 return _res;
1378}
1379
1380static PyObject *CarbonEvents_SetUserFocusWindow(PyObject *_self, PyObject *_args)
1381{
1382 PyObject *_res = NULL;
1383 OSStatus _err;
1384 WindowPtr inWindow;
1385 if (!PyArg_ParseTuple(_args, "O&",
1386 WinObj_Convert, &inWindow))
1387 return NULL;
1388 _err = SetUserFocusWindow(inWindow);
1389 if (_err != noErr) return PyMac_Error(_err);
1390 Py_INCREF(Py_None);
1391 _res = Py_None;
1392 return _res;
1393}
1394
1395static PyObject *CarbonEvents_GetUserFocusWindow(PyObject *_self, PyObject *_args)
1396{
1397 PyObject *_res = NULL;
1398 WindowPtr _rv;
1399 if (!PyArg_ParseTuple(_args, ""))
1400 return NULL;
1401 _rv = GetUserFocusWindow();
1402 _res = Py_BuildValue("O&",
1403 WinObj_New, _rv);
1404 return _res;
1405}
1406
1407static PyObject *CarbonEvents_SetWindowDefaultButton(PyObject *_self, PyObject *_args)
1408{
1409 PyObject *_res = NULL;
1410 OSStatus _err;
1411 WindowPtr inWindow;
1412 ControlHandle inControl;
1413 if (!PyArg_ParseTuple(_args, "O&O&",
1414 WinObj_Convert, &inWindow,
1415 CtlObj_Convert, &inControl))
1416 return NULL;
1417 _err = SetWindowDefaultButton(inWindow,
1418 inControl);
1419 if (_err != noErr) return PyMac_Error(_err);
1420 Py_INCREF(Py_None);
1421 _res = Py_None;
1422 return _res;
1423}
1424
1425static PyObject *CarbonEvents_SetWindowCancelButton(PyObject *_self, PyObject *_args)
1426{
1427 PyObject *_res = NULL;
1428 OSStatus _err;
1429 WindowPtr inWindow;
1430 ControlHandle inControl;
1431 if (!PyArg_ParseTuple(_args, "O&O&",
1432 WinObj_Convert, &inWindow,
1433 CtlObj_Convert, &inControl))
1434 return NULL;
1435 _err = SetWindowCancelButton(inWindow,
1436 inControl);
1437 if (_err != noErr) return PyMac_Error(_err);
1438 Py_INCREF(Py_None);
1439 _res = Py_None;
1440 return _res;
1441}
1442
1443static PyObject *CarbonEvents_GetWindowDefaultButton(PyObject *_self, PyObject *_args)
1444{
1445 PyObject *_res = NULL;
1446 OSStatus _err;
1447 WindowPtr inWindow;
1448 ControlHandle outControl;
1449 if (!PyArg_ParseTuple(_args, "O&",
1450 WinObj_Convert, &inWindow))
1451 return NULL;
1452 _err = GetWindowDefaultButton(inWindow,
1453 &outControl);
1454 if (_err != noErr) return PyMac_Error(_err);
1455 _res = Py_BuildValue("O&",
1456 CtlObj_New, outControl);
1457 return _res;
1458}
1459
1460static PyObject *CarbonEvents_GetWindowCancelButton(PyObject *_self, PyObject *_args)
1461{
1462 PyObject *_res = NULL;
1463 OSStatus _err;
1464 WindowPtr inWindow;
1465 ControlHandle outControl;
1466 if (!PyArg_ParseTuple(_args, "O&",
1467 WinObj_Convert, &inWindow))
1468 return NULL;
1469 _err = GetWindowCancelButton(inWindow,
1470 &outControl);
1471 if (_err != noErr) return PyMac_Error(_err);
1472 _res = Py_BuildValue("O&",
1473 CtlObj_New, outControl);
1474 return _res;
1475}
1476
1477static PyObject *CarbonEvents_RunApplicationEventLoop(PyObject *_self, PyObject *_args)
1478{
1479 PyObject *_res = NULL;
1480
1481#if USE_MAC_MP_MULTITHREADING
1482 if (MPCreateCriticalRegion(&reentrantLock) != noErr) {
Just van Rossumc3baa0e2001-12-11 21:52:02 +00001483 printf("lock failure\n");
Jack Jansen9c2b5142001-11-05 16:21:45 +00001484 return NULL;
1485 }
1486 _save = PyEval_SaveThread();
1487#endif /* USE_MAC_MP_MULTITHREADING */
1488
1489 RunApplicationEventLoop();
1490
1491#if USE_MAC_MP_MULTITHREADING
1492 PyEval_RestoreThread(_save);
1493
1494 MPDeleteCriticalRegion(reentrantLock);
1495#endif /* USE_MAC_MP_MULTITHREADING */
1496
1497 Py_INCREF(Py_None);
1498
1499 return Py_None;
1500
1501}
1502
1503static PyMethodDef CarbonEvents_methods[] = {
1504 {"GetCurrentEventLoop", (PyCFunction)CarbonEvents_GetCurrentEventLoop, 1,
1505 "() -> (EventLoopRef _rv)"},
1506 {"GetMainEventLoop", (PyCFunction)CarbonEvents_GetMainEventLoop, 1,
1507 "() -> (EventLoopRef _rv)"},
1508 {"RunCurrentEventLoop", (PyCFunction)CarbonEvents_RunCurrentEventLoop, 1,
1509 "(double inTimeout) -> None"},
1510 {"ReceiveNextEvent", (PyCFunction)CarbonEvents_ReceiveNextEvent, 1,
Just van Rossumc3baa0e2001-12-11 21:52:02 +00001511 "(UInt32 inNumTypes, EventTypeSpec inList, double inTimeout, Boolean inPullEvent) -> (EventRef outEvent)"},
Jack Jansen9c2b5142001-11-05 16:21:45 +00001512 {"GetCurrentEventQueue", (PyCFunction)CarbonEvents_GetCurrentEventQueue, 1,
1513 "() -> (EventQueueRef _rv)"},
1514 {"GetMainEventQueue", (PyCFunction)CarbonEvents_GetMainEventQueue, 1,
1515 "() -> (EventQueueRef _rv)"},
1516 {"GetCurrentEventTime", (PyCFunction)CarbonEvents_GetCurrentEventTime, 1,
1517 "() -> (double _rv)"},
1518 {"GetLastUserEventTime", (PyCFunction)CarbonEvents_GetLastUserEventTime, 1,
1519 "() -> (double _rv)"},
1520 {"GetWindowEventTarget", (PyCFunction)CarbonEvents_GetWindowEventTarget, 1,
1521 "(WindowPtr inWindow) -> (EventTargetRef _rv)"},
1522 {"GetControlEventTarget", (PyCFunction)CarbonEvents_GetControlEventTarget, 1,
1523 "(ControlHandle inControl) -> (EventTargetRef _rv)"},
1524 {"GetMenuEventTarget", (PyCFunction)CarbonEvents_GetMenuEventTarget, 1,
1525 "(MenuHandle inMenu) -> (EventTargetRef _rv)"},
1526 {"GetApplicationEventTarget", (PyCFunction)CarbonEvents_GetApplicationEventTarget, 1,
1527 "() -> (EventTargetRef _rv)"},
1528 {"GetUserFocusEventTarget", (PyCFunction)CarbonEvents_GetUserFocusEventTarget, 1,
1529 "() -> (EventTargetRef _rv)"},
1530 {"QuitApplicationEventLoop", (PyCFunction)CarbonEvents_QuitApplicationEventLoop, 1,
1531 "() -> None"},
1532 {"SetUserFocusWindow", (PyCFunction)CarbonEvents_SetUserFocusWindow, 1,
1533 "(WindowPtr inWindow) -> None"},
1534 {"GetUserFocusWindow", (PyCFunction)CarbonEvents_GetUserFocusWindow, 1,
1535 "() -> (WindowPtr _rv)"},
1536 {"SetWindowDefaultButton", (PyCFunction)CarbonEvents_SetWindowDefaultButton, 1,
1537 "(WindowPtr inWindow, ControlHandle inControl) -> None"},
1538 {"SetWindowCancelButton", (PyCFunction)CarbonEvents_SetWindowCancelButton, 1,
1539 "(WindowPtr inWindow, ControlHandle inControl) -> None"},
1540 {"GetWindowDefaultButton", (PyCFunction)CarbonEvents_GetWindowDefaultButton, 1,
1541 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
1542 {"GetWindowCancelButton", (PyCFunction)CarbonEvents_GetWindowCancelButton, 1,
1543 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
1544 {"RunApplicationEventLoop", (PyCFunction)CarbonEvents_RunApplicationEventLoop, 1,
1545 "() -> ()"},
1546 {NULL, NULL, 0}
1547};
1548
1549
1550
1551
Just van Rossumc3baa0e2001-12-11 21:52:02 +00001552void init_CarbonEvt(void)
Jack Jansen9c2b5142001-11-05 16:21:45 +00001553{
1554 PyObject *m;
1555 PyObject *d;
1556
1557
1558
Just van Rossumc3baa0e2001-12-11 21:52:02 +00001559 gEventHandlerUPP = NewEventHandlerUPP(CarbonEvents_HandleEvent);
Jack Jansen9c2b5142001-11-05 16:21:45 +00001560
Just van Rossumc3baa0e2001-12-11 21:52:02 +00001561
1562 m = Py_InitModule("_CarbonEvt", CarbonEvents_methods);
Jack Jansen9c2b5142001-11-05 16:21:45 +00001563 d = PyModule_GetDict(m);
1564 CarbonEvents_Error = PyMac_GetOSErrException();
1565 if (CarbonEvents_Error == NULL ||
1566 PyDict_SetItemString(d, "Error", CarbonEvents_Error) != 0)
1567 return;
1568 EventRef_Type.ob_type = &PyType_Type;
1569 Py_INCREF(&EventRef_Type);
1570 if (PyDict_SetItemString(d, "EventRefType", (PyObject *)&EventRef_Type) != 0)
1571 Py_FatalError("can't initialize EventRefType");
1572 EventQueueRef_Type.ob_type = &PyType_Type;
1573 Py_INCREF(&EventQueueRef_Type);
1574 if (PyDict_SetItemString(d, "EventQueueRefType", (PyObject *)&EventQueueRef_Type) != 0)
1575 Py_FatalError("can't initialize EventQueueRefType");
1576 EventLoopRef_Type.ob_type = &PyType_Type;
1577 Py_INCREF(&EventLoopRef_Type);
1578 if (PyDict_SetItemString(d, "EventLoopRefType", (PyObject *)&EventLoopRef_Type) != 0)
1579 Py_FatalError("can't initialize EventLoopRefType");
1580 EventLoopTimerRef_Type.ob_type = &PyType_Type;
1581 Py_INCREF(&EventLoopTimerRef_Type);
1582 if (PyDict_SetItemString(d, "EventLoopTimerRefType", (PyObject *)&EventLoopTimerRef_Type) != 0)
1583 Py_FatalError("can't initialize EventLoopTimerRefType");
1584 EventHandlerRef_Type.ob_type = &PyType_Type;
1585 Py_INCREF(&EventHandlerRef_Type);
1586 if (PyDict_SetItemString(d, "EventHandlerRefType", (PyObject *)&EventHandlerRef_Type) != 0)
1587 Py_FatalError("can't initialize EventHandlerRefType");
1588 EventHandlerCallRef_Type.ob_type = &PyType_Type;
1589 Py_INCREF(&EventHandlerCallRef_Type);
1590 if (PyDict_SetItemString(d, "EventHandlerCallRefType", (PyObject *)&EventHandlerCallRef_Type) != 0)
1591 Py_FatalError("can't initialize EventHandlerCallRefType");
1592 EventTargetRef_Type.ob_type = &PyType_Type;
1593 Py_INCREF(&EventTargetRef_Type);
1594 if (PyDict_SetItemString(d, "EventTargetRefType", (PyObject *)&EventTargetRef_Type) != 0)
1595 Py_FatalError("can't initialize EventTargetRefType");
1596 EventHotKeyRef_Type.ob_type = &PyType_Type;
1597 Py_INCREF(&EventHotKeyRef_Type);
1598 if (PyDict_SetItemString(d, "EventHotKeyRefType", (PyObject *)&EventHotKeyRef_Type) != 0)
1599 Py_FatalError("can't initialize EventHotKeyRefType");
1600}
1601
Just van Rossumc3baa0e2001-12-11 21:52:02 +00001602/* ===================== End module _CarbonEvt ====================== */
Jack Jansen9c2b5142001-11-05 16:21:45 +00001603