Update for release.
[python/dscho.git] / Mac / Modules / carbonevt / _CarbonEvtmodule.c
blob6d1aa0f2efaabdead4a9424712e3764382926a3a
2 /* ======================= Module _CarbonEvt ======================== */
4 #include "Python.h"
8 #ifdef WITHOUT_FRAMEWORKS
9 #include <CarbonEvents.h>
10 #else
11 #include <Carbon/Carbon.h>
12 #endif
14 #include "macglue.h"
16 /* Macro to test whether a weak-loaded CFM function exists */
17 #define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
18 PyErr_SetString(PyExc_NotImplementedError, \
19 "Not available in this shared library/OS version"); \
20 return; \
21 }} while(0)
24 #define USE_MAC_MP_MULTITHREADING 0
26 #if USE_MAC_MP_MULTITHREADING
27 static PyThreadState *_save;
28 static MPCriticalRegionID reentrantLock;
29 #endif /* USE_MAC_MP_MULTITHREADING */
31 extern int CFStringRef_New(CFStringRef *);
33 extern int CFStringRef_Convert(PyObject *, CFStringRef *);
34 extern int CFBundleRef_Convert(PyObject *, CFBundleRef *);
36 int EventTargetRef_Convert(PyObject *, EventTargetRef *);
37 PyObject *EventHandlerCallRef_New(EventHandlerCallRef itself);
38 PyObject *EventRef_New(EventRef itself);
40 /********** EventTypeSpec *******/
41 static PyObject*
42 EventTypeSpec_New(EventTypeSpec *in)
44 return Py_BuildValue("ll", in->eventClass, in->eventKind);
47 static int
48 EventTypeSpec_Convert(PyObject *v, EventTypeSpec *out)
50 if (PyArg_Parse(v, "(O&l)",
51 PyMac_GetOSType, &(out->eventClass),
52 &(out->eventKind)))
53 return 1;
54 return NULL;
57 /********** end EventTypeSpec *******/
59 /********** HIPoint *******/
61 #if 0 /* XXX doesn't compile */
62 static PyObject*
63 HIPoint_New(HIPoint *in)
65 return Py_BuildValue("ff", in->x, in->y);
68 static int
69 HIPoint_Convert(PyObject *v, HIPoint *out)
71 if (PyArg_ParseTuple(v, "ff", &(out->x), &(out->y)))
72 return 1;
73 return NULL;
75 #endif
77 /********** end HIPoint *******/
79 /********** EventHotKeyID *******/
81 static PyObject*
82 EventHotKeyID_New(EventHotKeyID *in)
84 return Py_BuildValue("ll", in->signature, in->id);
87 static int
88 EventHotKeyID_Convert(PyObject *v, EventHotKeyID *out)
90 if (PyArg_ParseTuple(v, "ll", &out->signature, &out->id))
91 return 1;
92 return NULL;
95 /********** end EventHotKeyID *******/
97 /******** myEventHandler ***********/
99 static EventHandlerUPP myEventHandlerUPP;
101 static pascal OSStatus
102 myEventHandler(EventHandlerCallRef handlerRef, EventRef event, void *outPyObject) {
103 PyObject *retValue;
104 int status;
106 #if USE_MAC_MP_MULTITHREADING
107 MPEnterCriticalRegion(reentrantLock, kDurationForever);
108 PyEval_RestoreThread(_save);
109 #endif /* USE_MAC_MP_MULTITHREADING */
111 retValue = PyObject_CallFunction((PyObject *)outPyObject, "O&O&",
112 EventHandlerCallRef_New, handlerRef,
113 EventRef_New, event);
114 if (retValue == NULL) {
115 PySys_WriteStderr("Error in event handler callback:\n");
116 PyErr_Print(); /* this also clears the error */
117 status = noErr; /* complain? how? */
118 } else {
119 if (retValue == Py_None)
120 status = noErr;
121 else if (PyInt_Check(retValue)) {
122 status = PyInt_AsLong(retValue);
123 } else
124 status = noErr; /* wrong object type, complain? */
125 Py_DECREF(retValue);
128 #if USE_MAC_MP_MULTITHREADING
129 _save = PyEval_SaveThread();
130 MPExitCriticalRegion(reentrantLock);
131 #endif /* USE_MAC_MP_MULTITHREADING */
133 return status;
136 /******** end myEventHandler ***********/
139 static PyObject *CarbonEvents_Error;
141 /* ---------------------- Object type EventRef ---------------------- */
143 PyTypeObject EventRef_Type;
145 #define EventRef_Check(x) ((x)->ob_type == &EventRef_Type || PyObject_TypeCheck((x), &EventRef_Type))
147 typedef struct EventRefObject {
148 PyObject_HEAD
149 EventRef ob_itself;
150 } EventRefObject;
152 PyObject *EventRef_New(EventRef itself)
154 EventRefObject *it;
155 it = PyObject_NEW(EventRefObject, &EventRef_Type);
156 if (it == NULL) return NULL;
157 it->ob_itself = itself;
158 return (PyObject *)it;
160 int EventRef_Convert(PyObject *v, EventRef *p_itself)
162 if (!EventRef_Check(v))
164 PyErr_SetString(PyExc_TypeError, "EventRef required");
165 return 0;
167 *p_itself = ((EventRefObject *)v)->ob_itself;
168 return 1;
171 static void EventRef_dealloc(EventRefObject *self)
173 /* Cleanup of self->ob_itself goes here */
174 self->ob_type->tp_free((PyObject *)self);
177 static PyObject *EventRef_RetainEvent(EventRefObject *_self, PyObject *_args)
179 PyObject *_res = NULL;
180 EventRef _rv;
181 if (!PyArg_ParseTuple(_args, ""))
182 return NULL;
183 _rv = RetainEvent(_self->ob_itself);
184 _res = Py_BuildValue("O&",
185 EventRef_New, _rv);
186 return _res;
189 static PyObject *EventRef_GetEventRetainCount(EventRefObject *_self, PyObject *_args)
191 PyObject *_res = NULL;
192 UInt32 _rv;
193 if (!PyArg_ParseTuple(_args, ""))
194 return NULL;
195 _rv = GetEventRetainCount(_self->ob_itself);
196 _res = Py_BuildValue("l",
197 _rv);
198 return _res;
201 static PyObject *EventRef_ReleaseEvent(EventRefObject *_self, PyObject *_args)
203 PyObject *_res = NULL;
204 if (!PyArg_ParseTuple(_args, ""))
205 return NULL;
206 ReleaseEvent(_self->ob_itself);
207 Py_INCREF(Py_None);
208 _res = Py_None;
209 return _res;
212 static PyObject *EventRef_SetEventParameter(EventRefObject *_self, PyObject *_args)
214 PyObject *_res = NULL;
215 OSStatus _err;
216 OSType inName;
217 OSType inType;
218 char *inDataPtr__in__;
219 long inDataPtr__len__;
220 int inDataPtr__in_len__;
221 if (!PyArg_ParseTuple(_args, "O&O&s#",
222 PyMac_GetOSType, &inName,
223 PyMac_GetOSType, &inType,
224 &inDataPtr__in__, &inDataPtr__in_len__))
225 return NULL;
226 inDataPtr__len__ = inDataPtr__in_len__;
227 _err = SetEventParameter(_self->ob_itself,
228 inName,
229 inType,
230 inDataPtr__len__, inDataPtr__in__);
231 if (_err != noErr) return PyMac_Error(_err);
232 Py_INCREF(Py_None);
233 _res = Py_None;
234 return _res;
237 static PyObject *EventRef_GetEventClass(EventRefObject *_self, PyObject *_args)
239 PyObject *_res = NULL;
240 UInt32 _rv;
241 if (!PyArg_ParseTuple(_args, ""))
242 return NULL;
243 _rv = GetEventClass(_self->ob_itself);
244 _res = Py_BuildValue("l",
245 _rv);
246 return _res;
249 static PyObject *EventRef_GetEventKind(EventRefObject *_self, PyObject *_args)
251 PyObject *_res = NULL;
252 UInt32 _rv;
253 if (!PyArg_ParseTuple(_args, ""))
254 return NULL;
255 _rv = GetEventKind(_self->ob_itself);
256 _res = Py_BuildValue("l",
257 _rv);
258 return _res;
261 static PyObject *EventRef_GetEventTime(EventRefObject *_self, PyObject *_args)
263 PyObject *_res = NULL;
264 double _rv;
265 if (!PyArg_ParseTuple(_args, ""))
266 return NULL;
267 _rv = GetEventTime(_self->ob_itself);
268 _res = Py_BuildValue("d",
269 _rv);
270 return _res;
273 static PyObject *EventRef_SetEventTime(EventRefObject *_self, PyObject *_args)
275 PyObject *_res = NULL;
276 OSStatus _err;
277 double inTime;
278 if (!PyArg_ParseTuple(_args, "d",
279 &inTime))
280 return NULL;
281 _err = SetEventTime(_self->ob_itself,
282 inTime);
283 if (_err != noErr) return PyMac_Error(_err);
284 Py_INCREF(Py_None);
285 _res = Py_None;
286 return _res;
289 static PyObject *EventRef_IsUserCancelEventRef(EventRefObject *_self, PyObject *_args)
291 PyObject *_res = NULL;
292 Boolean _rv;
293 if (!PyArg_ParseTuple(_args, ""))
294 return NULL;
295 _rv = IsUserCancelEventRef(_self->ob_itself);
296 _res = Py_BuildValue("b",
297 _rv);
298 return _res;
301 static PyObject *EventRef_ConvertEventRefToEventRecord(EventRefObject *_self, PyObject *_args)
303 PyObject *_res = NULL;
304 Boolean _rv;
305 EventRecord outEvent;
306 if (!PyArg_ParseTuple(_args, ""))
307 return NULL;
308 _rv = ConvertEventRefToEventRecord(_self->ob_itself,
309 &outEvent);
310 _res = Py_BuildValue("bO&",
311 _rv,
312 PyMac_BuildEventRecord, &outEvent);
313 return _res;
316 static PyObject *EventRef_IsEventInMask(EventRefObject *_self, PyObject *_args)
318 PyObject *_res = NULL;
319 Boolean _rv;
320 UInt16 inMask;
321 if (!PyArg_ParseTuple(_args, "H",
322 &inMask))
323 return NULL;
324 _rv = IsEventInMask(_self->ob_itself,
325 inMask);
326 _res = Py_BuildValue("b",
327 _rv);
328 return _res;
331 static PyObject *EventRef_SendEventToEventTarget(EventRefObject *_self, PyObject *_args)
333 PyObject *_res = NULL;
334 OSStatus _err;
335 EventTargetRef inTarget;
336 if (!PyArg_ParseTuple(_args, "O&",
337 EventTargetRef_Convert, &inTarget))
338 return NULL;
339 _err = SendEventToEventTarget(_self->ob_itself,
340 inTarget);
341 if (_err != noErr) return PyMac_Error(_err);
342 Py_INCREF(Py_None);
343 _res = Py_None;
344 return _res;
347 static PyObject *EventRef_GetEventParameter(EventRefObject *_self, PyObject *_args)
349 PyObject *_res = NULL;
351 UInt32 bufferSize;
352 EventParamName inName;
353 EventParamType inType;
354 OSErr _err;
355 void * buffer;
357 if (!PyArg_ParseTuple(_args, "O&O&", PyMac_GetOSType, &inName, PyMac_GetOSType, &inType))
358 return NULL;
360 /* Figure out the size by passing a null buffer to GetEventParameter */
361 _err = GetEventParameter(_self->ob_itself, inName, inType, NULL, 0, &bufferSize, NULL);
363 if (_err != noErr)
364 return PyMac_Error(_err);
365 buffer = PyMem_NEW(char, bufferSize);
366 if (buffer == NULL)
367 return PyErr_NoMemory();
369 _err = GetEventParameter(_self->ob_itself, inName, inType, NULL, bufferSize, NULL, buffer);
371 if (_err != noErr) {
372 PyMem_DEL(buffer);
373 return PyMac_Error(_err);
375 _res = Py_BuildValue("s#", buffer, bufferSize);
376 PyMem_DEL(buffer);
377 return _res;
381 static PyMethodDef EventRef_methods[] = {
382 {"RetainEvent", (PyCFunction)EventRef_RetainEvent, 1,
383 PyDoc_STR("() -> (EventRef _rv)")},
384 {"GetEventRetainCount", (PyCFunction)EventRef_GetEventRetainCount, 1,
385 PyDoc_STR("() -> (UInt32 _rv)")},
386 {"ReleaseEvent", (PyCFunction)EventRef_ReleaseEvent, 1,
387 PyDoc_STR("() -> None")},
388 {"SetEventParameter", (PyCFunction)EventRef_SetEventParameter, 1,
389 PyDoc_STR("(OSType inName, OSType inType, Buffer inDataPtr) -> None")},
390 {"GetEventClass", (PyCFunction)EventRef_GetEventClass, 1,
391 PyDoc_STR("() -> (UInt32 _rv)")},
392 {"GetEventKind", (PyCFunction)EventRef_GetEventKind, 1,
393 PyDoc_STR("() -> (UInt32 _rv)")},
394 {"GetEventTime", (PyCFunction)EventRef_GetEventTime, 1,
395 PyDoc_STR("() -> (double _rv)")},
396 {"SetEventTime", (PyCFunction)EventRef_SetEventTime, 1,
397 PyDoc_STR("(double inTime) -> None")},
398 {"IsUserCancelEventRef", (PyCFunction)EventRef_IsUserCancelEventRef, 1,
399 PyDoc_STR("() -> (Boolean _rv)")},
400 {"ConvertEventRefToEventRecord", (PyCFunction)EventRef_ConvertEventRefToEventRecord, 1,
401 PyDoc_STR("() -> (Boolean _rv, EventRecord outEvent)")},
402 {"IsEventInMask", (PyCFunction)EventRef_IsEventInMask, 1,
403 PyDoc_STR("(UInt16 inMask) -> (Boolean _rv)")},
404 {"SendEventToEventTarget", (PyCFunction)EventRef_SendEventToEventTarget, 1,
405 PyDoc_STR("(EventTargetRef inTarget) -> None")},
406 {"GetEventParameter", (PyCFunction)EventRef_GetEventParameter, 1,
407 PyDoc_STR("(EventParamName eventName, EventParamType eventType) -> (String eventParamData)")},
408 {NULL, NULL, 0}
411 #define EventRef_getsetlist NULL
414 #define EventRef_compare NULL
416 #define EventRef_repr NULL
418 #define EventRef_hash NULL
419 #define EventRef_tp_init 0
421 #define EventRef_tp_alloc PyType_GenericAlloc
423 static PyObject *EventRef_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
425 PyObject *self;
426 EventRef itself;
427 char *kw[] = {"itself", 0};
429 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&", kw, EventRef_Convert, &itself)) return NULL;
430 if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;
431 ((EventRefObject *)self)->ob_itself = itself;
432 return self;
435 #define EventRef_tp_free PyObject_Del
438 PyTypeObject EventRef_Type = {
439 PyObject_HEAD_INIT(NULL)
440 0, /*ob_size*/
441 "_CarbonEvt.EventRef", /*tp_name*/
442 sizeof(EventRefObject), /*tp_basicsize*/
443 0, /*tp_itemsize*/
444 /* methods */
445 (destructor) EventRef_dealloc, /*tp_dealloc*/
446 0, /*tp_print*/
447 (getattrfunc)0, /*tp_getattr*/
448 (setattrfunc)0, /*tp_setattr*/
449 (cmpfunc) EventRef_compare, /*tp_compare*/
450 (reprfunc) EventRef_repr, /*tp_repr*/
451 (PyNumberMethods *)0, /* tp_as_number */
452 (PySequenceMethods *)0, /* tp_as_sequence */
453 (PyMappingMethods *)0, /* tp_as_mapping */
454 (hashfunc) EventRef_hash, /*tp_hash*/
455 0, /*tp_call*/
456 0, /*tp_str*/
457 PyObject_GenericGetAttr, /*tp_getattro*/
458 PyObject_GenericSetAttr, /*tp_setattro */
459 0, /*tp_as_buffer*/
460 Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
461 0, /*tp_doc*/
462 0, /*tp_traverse*/
463 0, /*tp_clear*/
464 0, /*tp_richcompare*/
465 0, /*tp_weaklistoffset*/
466 0, /*tp_iter*/
467 0, /*tp_iternext*/
468 EventRef_methods, /* tp_methods */
469 0, /*tp_members*/
470 EventRef_getsetlist, /*tp_getset*/
471 0, /*tp_base*/
472 0, /*tp_dict*/
473 0, /*tp_descr_get*/
474 0, /*tp_descr_set*/
475 0, /*tp_dictoffset*/
476 EventRef_tp_init, /* tp_init */
477 EventRef_tp_alloc, /* tp_alloc */
478 EventRef_tp_new, /* tp_new */
479 EventRef_tp_free, /* tp_free */
482 /* -------------------- End object type EventRef -------------------- */
485 /* ------------------- Object type EventQueueRef -------------------- */
487 PyTypeObject EventQueueRef_Type;
489 #define EventQueueRef_Check(x) ((x)->ob_type == &EventQueueRef_Type || PyObject_TypeCheck((x), &EventQueueRef_Type))
491 typedef struct EventQueueRefObject {
492 PyObject_HEAD
493 EventQueueRef ob_itself;
494 } EventQueueRefObject;
496 PyObject *EventQueueRef_New(EventQueueRef itself)
498 EventQueueRefObject *it;
499 it = PyObject_NEW(EventQueueRefObject, &EventQueueRef_Type);
500 if (it == NULL) return NULL;
501 it->ob_itself = itself;
502 return (PyObject *)it;
504 int EventQueueRef_Convert(PyObject *v, EventQueueRef *p_itself)
506 if (!EventQueueRef_Check(v))
508 PyErr_SetString(PyExc_TypeError, "EventQueueRef required");
509 return 0;
511 *p_itself = ((EventQueueRefObject *)v)->ob_itself;
512 return 1;
515 static void EventQueueRef_dealloc(EventQueueRefObject *self)
517 /* Cleanup of self->ob_itself goes here */
518 self->ob_type->tp_free((PyObject *)self);
521 static PyObject *EventQueueRef_PostEventToQueue(EventQueueRefObject *_self, PyObject *_args)
523 PyObject *_res = NULL;
524 OSStatus _err;
525 EventRef inEvent;
526 SInt16 inPriority;
527 if (!PyArg_ParseTuple(_args, "O&h",
528 EventRef_Convert, &inEvent,
529 &inPriority))
530 return NULL;
531 _err = PostEventToQueue(_self->ob_itself,
532 inEvent,
533 inPriority);
534 if (_err != noErr) return PyMac_Error(_err);
535 Py_INCREF(Py_None);
536 _res = Py_None;
537 return _res;
540 static PyObject *EventQueueRef_FlushEventsMatchingListFromQueue(EventQueueRefObject *_self, PyObject *_args)
542 PyObject *_res = NULL;
543 OSStatus _err;
544 UInt32 inNumTypes;
545 EventTypeSpec inList;
546 if (!PyArg_ParseTuple(_args, "lO&",
547 &inNumTypes,
548 EventTypeSpec_Convert, &inList))
549 return NULL;
550 _err = FlushEventsMatchingListFromQueue(_self->ob_itself,
551 inNumTypes,
552 &inList);
553 if (_err != noErr) return PyMac_Error(_err);
554 Py_INCREF(Py_None);
555 _res = Py_None;
556 return _res;
559 static PyObject *EventQueueRef_FlushEventQueue(EventQueueRefObject *_self, PyObject *_args)
561 PyObject *_res = NULL;
562 OSStatus _err;
563 if (!PyArg_ParseTuple(_args, ""))
564 return NULL;
565 _err = FlushEventQueue(_self->ob_itself);
566 if (_err != noErr) return PyMac_Error(_err);
567 Py_INCREF(Py_None);
568 _res = Py_None;
569 return _res;
572 static PyObject *EventQueueRef_GetNumEventsInQueue(EventQueueRefObject *_self, PyObject *_args)
574 PyObject *_res = NULL;
575 UInt32 _rv;
576 if (!PyArg_ParseTuple(_args, ""))
577 return NULL;
578 _rv = GetNumEventsInQueue(_self->ob_itself);
579 _res = Py_BuildValue("l",
580 _rv);
581 return _res;
584 static PyObject *EventQueueRef_RemoveEventFromQueue(EventQueueRefObject *_self, PyObject *_args)
586 PyObject *_res = NULL;
587 OSStatus _err;
588 EventRef inEvent;
589 if (!PyArg_ParseTuple(_args, "O&",
590 EventRef_Convert, &inEvent))
591 return NULL;
592 _err = RemoveEventFromQueue(_self->ob_itself,
593 inEvent);
594 if (_err != noErr) return PyMac_Error(_err);
595 Py_INCREF(Py_None);
596 _res = Py_None;
597 return _res;
600 static PyObject *EventQueueRef_IsEventInQueue(EventQueueRefObject *_self, PyObject *_args)
602 PyObject *_res = NULL;
603 Boolean _rv;
604 EventRef inEvent;
605 if (!PyArg_ParseTuple(_args, "O&",
606 EventRef_Convert, &inEvent))
607 return NULL;
608 _rv = IsEventInQueue(_self->ob_itself,
609 inEvent);
610 _res = Py_BuildValue("b",
611 _rv);
612 return _res;
615 static PyMethodDef EventQueueRef_methods[] = {
616 {"PostEventToQueue", (PyCFunction)EventQueueRef_PostEventToQueue, 1,
617 PyDoc_STR("(EventRef inEvent, SInt16 inPriority) -> None")},
618 {"FlushEventsMatchingListFromQueue", (PyCFunction)EventQueueRef_FlushEventsMatchingListFromQueue, 1,
619 PyDoc_STR("(UInt32 inNumTypes, EventTypeSpec inList) -> None")},
620 {"FlushEventQueue", (PyCFunction)EventQueueRef_FlushEventQueue, 1,
621 PyDoc_STR("() -> None")},
622 {"GetNumEventsInQueue", (PyCFunction)EventQueueRef_GetNumEventsInQueue, 1,
623 PyDoc_STR("() -> (UInt32 _rv)")},
624 {"RemoveEventFromQueue", (PyCFunction)EventQueueRef_RemoveEventFromQueue, 1,
625 PyDoc_STR("(EventRef inEvent) -> None")},
626 {"IsEventInQueue", (PyCFunction)EventQueueRef_IsEventInQueue, 1,
627 PyDoc_STR("(EventRef inEvent) -> (Boolean _rv)")},
628 {NULL, NULL, 0}
631 #define EventQueueRef_getsetlist NULL
634 #define EventQueueRef_compare NULL
636 #define EventQueueRef_repr NULL
638 #define EventQueueRef_hash NULL
639 #define EventQueueRef_tp_init 0
641 #define EventQueueRef_tp_alloc PyType_GenericAlloc
643 static PyObject *EventQueueRef_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
645 PyObject *self;
646 EventQueueRef itself;
647 char *kw[] = {"itself", 0};
649 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&", kw, EventQueueRef_Convert, &itself)) return NULL;
650 if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;
651 ((EventQueueRefObject *)self)->ob_itself = itself;
652 return self;
655 #define EventQueueRef_tp_free PyObject_Del
658 PyTypeObject EventQueueRef_Type = {
659 PyObject_HEAD_INIT(NULL)
660 0, /*ob_size*/
661 "_CarbonEvt.EventQueueRef", /*tp_name*/
662 sizeof(EventQueueRefObject), /*tp_basicsize*/
663 0, /*tp_itemsize*/
664 /* methods */
665 (destructor) EventQueueRef_dealloc, /*tp_dealloc*/
666 0, /*tp_print*/
667 (getattrfunc)0, /*tp_getattr*/
668 (setattrfunc)0, /*tp_setattr*/
669 (cmpfunc) EventQueueRef_compare, /*tp_compare*/
670 (reprfunc) EventQueueRef_repr, /*tp_repr*/
671 (PyNumberMethods *)0, /* tp_as_number */
672 (PySequenceMethods *)0, /* tp_as_sequence */
673 (PyMappingMethods *)0, /* tp_as_mapping */
674 (hashfunc) EventQueueRef_hash, /*tp_hash*/
675 0, /*tp_call*/
676 0, /*tp_str*/
677 PyObject_GenericGetAttr, /*tp_getattro*/
678 PyObject_GenericSetAttr, /*tp_setattro */
679 0, /*tp_as_buffer*/
680 Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
681 0, /*tp_doc*/
682 0, /*tp_traverse*/
683 0, /*tp_clear*/
684 0, /*tp_richcompare*/
685 0, /*tp_weaklistoffset*/
686 0, /*tp_iter*/
687 0, /*tp_iternext*/
688 EventQueueRef_methods, /* tp_methods */
689 0, /*tp_members*/
690 EventQueueRef_getsetlist, /*tp_getset*/
691 0, /*tp_base*/
692 0, /*tp_dict*/
693 0, /*tp_descr_get*/
694 0, /*tp_descr_set*/
695 0, /*tp_dictoffset*/
696 EventQueueRef_tp_init, /* tp_init */
697 EventQueueRef_tp_alloc, /* tp_alloc */
698 EventQueueRef_tp_new, /* tp_new */
699 EventQueueRef_tp_free, /* tp_free */
702 /* ----------------- End object type EventQueueRef ------------------ */
705 /* -------------------- Object type EventLoopRef -------------------- */
707 PyTypeObject EventLoopRef_Type;
709 #define EventLoopRef_Check(x) ((x)->ob_type == &EventLoopRef_Type || PyObject_TypeCheck((x), &EventLoopRef_Type))
711 typedef struct EventLoopRefObject {
712 PyObject_HEAD
713 EventLoopRef ob_itself;
714 } EventLoopRefObject;
716 PyObject *EventLoopRef_New(EventLoopRef itself)
718 EventLoopRefObject *it;
719 it = PyObject_NEW(EventLoopRefObject, &EventLoopRef_Type);
720 if (it == NULL) return NULL;
721 it->ob_itself = itself;
722 return (PyObject *)it;
724 int EventLoopRef_Convert(PyObject *v, EventLoopRef *p_itself)
726 if (!EventLoopRef_Check(v))
728 PyErr_SetString(PyExc_TypeError, "EventLoopRef required");
729 return 0;
731 *p_itself = ((EventLoopRefObject *)v)->ob_itself;
732 return 1;
735 static void EventLoopRef_dealloc(EventLoopRefObject *self)
737 /* Cleanup of self->ob_itself goes here */
738 self->ob_type->tp_free((PyObject *)self);
741 static PyObject *EventLoopRef_QuitEventLoop(EventLoopRefObject *_self, PyObject *_args)
743 PyObject *_res = NULL;
744 OSStatus _err;
745 if (!PyArg_ParseTuple(_args, ""))
746 return NULL;
747 _err = QuitEventLoop(_self->ob_itself);
748 if (_err != noErr) return PyMac_Error(_err);
749 Py_INCREF(Py_None);
750 _res = Py_None;
751 return _res;
754 static PyMethodDef EventLoopRef_methods[] = {
755 {"QuitEventLoop", (PyCFunction)EventLoopRef_QuitEventLoop, 1,
756 PyDoc_STR("() -> None")},
757 {NULL, NULL, 0}
760 #define EventLoopRef_getsetlist NULL
763 #define EventLoopRef_compare NULL
765 #define EventLoopRef_repr NULL
767 #define EventLoopRef_hash NULL
768 #define EventLoopRef_tp_init 0
770 #define EventLoopRef_tp_alloc PyType_GenericAlloc
772 static PyObject *EventLoopRef_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
774 PyObject *self;
775 EventLoopRef itself;
776 char *kw[] = {"itself", 0};
778 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&", kw, EventLoopRef_Convert, &itself)) return NULL;
779 if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;
780 ((EventLoopRefObject *)self)->ob_itself = itself;
781 return self;
784 #define EventLoopRef_tp_free PyObject_Del
787 PyTypeObject EventLoopRef_Type = {
788 PyObject_HEAD_INIT(NULL)
789 0, /*ob_size*/
790 "_CarbonEvt.EventLoopRef", /*tp_name*/
791 sizeof(EventLoopRefObject), /*tp_basicsize*/
792 0, /*tp_itemsize*/
793 /* methods */
794 (destructor) EventLoopRef_dealloc, /*tp_dealloc*/
795 0, /*tp_print*/
796 (getattrfunc)0, /*tp_getattr*/
797 (setattrfunc)0, /*tp_setattr*/
798 (cmpfunc) EventLoopRef_compare, /*tp_compare*/
799 (reprfunc) EventLoopRef_repr, /*tp_repr*/
800 (PyNumberMethods *)0, /* tp_as_number */
801 (PySequenceMethods *)0, /* tp_as_sequence */
802 (PyMappingMethods *)0, /* tp_as_mapping */
803 (hashfunc) EventLoopRef_hash, /*tp_hash*/
804 0, /*tp_call*/
805 0, /*tp_str*/
806 PyObject_GenericGetAttr, /*tp_getattro*/
807 PyObject_GenericSetAttr, /*tp_setattro */
808 0, /*tp_as_buffer*/
809 Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
810 0, /*tp_doc*/
811 0, /*tp_traverse*/
812 0, /*tp_clear*/
813 0, /*tp_richcompare*/
814 0, /*tp_weaklistoffset*/
815 0, /*tp_iter*/
816 0, /*tp_iternext*/
817 EventLoopRef_methods, /* tp_methods */
818 0, /*tp_members*/
819 EventLoopRef_getsetlist, /*tp_getset*/
820 0, /*tp_base*/
821 0, /*tp_dict*/
822 0, /*tp_descr_get*/
823 0, /*tp_descr_set*/
824 0, /*tp_dictoffset*/
825 EventLoopRef_tp_init, /* tp_init */
826 EventLoopRef_tp_alloc, /* tp_alloc */
827 EventLoopRef_tp_new, /* tp_new */
828 EventLoopRef_tp_free, /* tp_free */
831 /* ------------------ End object type EventLoopRef ------------------ */
834 /* ----------------- Object type EventLoopTimerRef ------------------ */
836 PyTypeObject EventLoopTimerRef_Type;
838 #define EventLoopTimerRef_Check(x) ((x)->ob_type == &EventLoopTimerRef_Type || PyObject_TypeCheck((x), &EventLoopTimerRef_Type))
840 typedef struct EventLoopTimerRefObject {
841 PyObject_HEAD
842 EventLoopTimerRef ob_itself;
843 } EventLoopTimerRefObject;
845 PyObject *EventLoopTimerRef_New(EventLoopTimerRef itself)
847 EventLoopTimerRefObject *it;
848 it = PyObject_NEW(EventLoopTimerRefObject, &EventLoopTimerRef_Type);
849 if (it == NULL) return NULL;
850 it->ob_itself = itself;
851 return (PyObject *)it;
853 int EventLoopTimerRef_Convert(PyObject *v, EventLoopTimerRef *p_itself)
855 if (!EventLoopTimerRef_Check(v))
857 PyErr_SetString(PyExc_TypeError, "EventLoopTimerRef required");
858 return 0;
860 *p_itself = ((EventLoopTimerRefObject *)v)->ob_itself;
861 return 1;
864 static void EventLoopTimerRef_dealloc(EventLoopTimerRefObject *self)
866 /* Cleanup of self->ob_itself goes here */
867 self->ob_type->tp_free((PyObject *)self);
870 static PyObject *EventLoopTimerRef_RemoveEventLoopTimer(EventLoopTimerRefObject *_self, PyObject *_args)
872 PyObject *_res = NULL;
873 OSStatus _err;
874 if (!PyArg_ParseTuple(_args, ""))
875 return NULL;
876 _err = RemoveEventLoopTimer(_self->ob_itself);
877 if (_err != noErr) return PyMac_Error(_err);
878 Py_INCREF(Py_None);
879 _res = Py_None;
880 return _res;
883 static PyObject *EventLoopTimerRef_SetEventLoopTimerNextFireTime(EventLoopTimerRefObject *_self, PyObject *_args)
885 PyObject *_res = NULL;
886 OSStatus _err;
887 double inNextFire;
888 if (!PyArg_ParseTuple(_args, "d",
889 &inNextFire))
890 return NULL;
891 _err = SetEventLoopTimerNextFireTime(_self->ob_itself,
892 inNextFire);
893 if (_err != noErr) return PyMac_Error(_err);
894 Py_INCREF(Py_None);
895 _res = Py_None;
896 return _res;
899 static PyMethodDef EventLoopTimerRef_methods[] = {
900 {"RemoveEventLoopTimer", (PyCFunction)EventLoopTimerRef_RemoveEventLoopTimer, 1,
901 PyDoc_STR("() -> None")},
902 {"SetEventLoopTimerNextFireTime", (PyCFunction)EventLoopTimerRef_SetEventLoopTimerNextFireTime, 1,
903 PyDoc_STR("(double inNextFire) -> None")},
904 {NULL, NULL, 0}
907 #define EventLoopTimerRef_getsetlist NULL
910 #define EventLoopTimerRef_compare NULL
912 #define EventLoopTimerRef_repr NULL
914 #define EventLoopTimerRef_hash NULL
915 #define EventLoopTimerRef_tp_init 0
917 #define EventLoopTimerRef_tp_alloc PyType_GenericAlloc
919 static PyObject *EventLoopTimerRef_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
921 PyObject *self;
922 EventLoopTimerRef itself;
923 char *kw[] = {"itself", 0};
925 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&", kw, EventLoopTimerRef_Convert, &itself)) return NULL;
926 if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;
927 ((EventLoopTimerRefObject *)self)->ob_itself = itself;
928 return self;
931 #define EventLoopTimerRef_tp_free PyObject_Del
934 PyTypeObject EventLoopTimerRef_Type = {
935 PyObject_HEAD_INIT(NULL)
936 0, /*ob_size*/
937 "_CarbonEvt.EventLoopTimerRef", /*tp_name*/
938 sizeof(EventLoopTimerRefObject), /*tp_basicsize*/
939 0, /*tp_itemsize*/
940 /* methods */
941 (destructor) EventLoopTimerRef_dealloc, /*tp_dealloc*/
942 0, /*tp_print*/
943 (getattrfunc)0, /*tp_getattr*/
944 (setattrfunc)0, /*tp_setattr*/
945 (cmpfunc) EventLoopTimerRef_compare, /*tp_compare*/
946 (reprfunc) EventLoopTimerRef_repr, /*tp_repr*/
947 (PyNumberMethods *)0, /* tp_as_number */
948 (PySequenceMethods *)0, /* tp_as_sequence */
949 (PyMappingMethods *)0, /* tp_as_mapping */
950 (hashfunc) EventLoopTimerRef_hash, /*tp_hash*/
951 0, /*tp_call*/
952 0, /*tp_str*/
953 PyObject_GenericGetAttr, /*tp_getattro*/
954 PyObject_GenericSetAttr, /*tp_setattro */
955 0, /*tp_as_buffer*/
956 Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
957 0, /*tp_doc*/
958 0, /*tp_traverse*/
959 0, /*tp_clear*/
960 0, /*tp_richcompare*/
961 0, /*tp_weaklistoffset*/
962 0, /*tp_iter*/
963 0, /*tp_iternext*/
964 EventLoopTimerRef_methods, /* tp_methods */
965 0, /*tp_members*/
966 EventLoopTimerRef_getsetlist, /*tp_getset*/
967 0, /*tp_base*/
968 0, /*tp_dict*/
969 0, /*tp_descr_get*/
970 0, /*tp_descr_set*/
971 0, /*tp_dictoffset*/
972 EventLoopTimerRef_tp_init, /* tp_init */
973 EventLoopTimerRef_tp_alloc, /* tp_alloc */
974 EventLoopTimerRef_tp_new, /* tp_new */
975 EventLoopTimerRef_tp_free, /* tp_free */
978 /* --------------- End object type EventLoopTimerRef ---------------- */
981 /* ------------------ Object type EventHandlerRef ------------------- */
983 PyTypeObject EventHandlerRef_Type;
985 #define EventHandlerRef_Check(x) ((x)->ob_type == &EventHandlerRef_Type || PyObject_TypeCheck((x), &EventHandlerRef_Type))
987 typedef struct EventHandlerRefObject {
988 PyObject_HEAD
989 EventHandlerRef ob_itself;
990 PyObject *ob_callback;
991 } EventHandlerRefObject;
993 PyObject *EventHandlerRef_New(EventHandlerRef itself)
995 EventHandlerRefObject *it;
996 it = PyObject_NEW(EventHandlerRefObject, &EventHandlerRef_Type);
997 if (it == NULL) return NULL;
998 it->ob_itself = itself;
999 it->ob_callback = NULL;
1000 return (PyObject *)it;
1002 int EventHandlerRef_Convert(PyObject *v, EventHandlerRef *p_itself)
1004 if (!EventHandlerRef_Check(v))
1006 PyErr_SetString(PyExc_TypeError, "EventHandlerRef required");
1007 return 0;
1009 *p_itself = ((EventHandlerRefObject *)v)->ob_itself;
1010 return 1;
1013 static void EventHandlerRef_dealloc(EventHandlerRefObject *self)
1015 if (self->ob_itself != NULL) {
1016 RemoveEventHandler(self->ob_itself);
1017 Py_DECREF(self->ob_callback);
1019 self->ob_type->tp_free((PyObject *)self);
1022 static PyObject *EventHandlerRef_AddEventTypesToHandler(EventHandlerRefObject *_self, PyObject *_args)
1024 PyObject *_res = NULL;
1025 OSStatus _err;
1026 UInt32 inNumTypes;
1027 EventTypeSpec inList;
1028 if (_self->ob_itself == NULL) {
1029 PyErr_SetString(CarbonEvents_Error, "Handler has been removed");
1030 return NULL;
1032 if (!PyArg_ParseTuple(_args, "lO&",
1033 &inNumTypes,
1034 EventTypeSpec_Convert, &inList))
1035 return NULL;
1036 _err = AddEventTypesToHandler(_self->ob_itself,
1037 inNumTypes,
1038 &inList);
1039 if (_err != noErr) return PyMac_Error(_err);
1040 Py_INCREF(Py_None);
1041 _res = Py_None;
1042 return _res;
1045 static PyObject *EventHandlerRef_RemoveEventTypesFromHandler(EventHandlerRefObject *_self, PyObject *_args)
1047 PyObject *_res = NULL;
1048 OSStatus _err;
1049 UInt32 inNumTypes;
1050 EventTypeSpec inList;
1051 if (_self->ob_itself == NULL) {
1052 PyErr_SetString(CarbonEvents_Error, "Handler has been removed");
1053 return NULL;
1055 if (!PyArg_ParseTuple(_args, "lO&",
1056 &inNumTypes,
1057 EventTypeSpec_Convert, &inList))
1058 return NULL;
1059 _err = RemoveEventTypesFromHandler(_self->ob_itself,
1060 inNumTypes,
1061 &inList);
1062 if (_err != noErr) return PyMac_Error(_err);
1063 Py_INCREF(Py_None);
1064 _res = Py_None;
1065 return _res;
1068 static PyObject *EventHandlerRef_RemoveEventHandler(EventHandlerRefObject *_self, PyObject *_args)
1070 PyObject *_res = NULL;
1072 OSStatus _err;
1073 if (_self->ob_itself == NULL) {
1074 PyErr_SetString(CarbonEvents_Error, "Handler has been removed");
1075 return NULL;
1077 if (!PyArg_ParseTuple(_args, ""))
1078 return NULL;
1079 _err = RemoveEventHandler(_self->ob_itself);
1080 if (_err != noErr) return PyMac_Error(_err);
1081 _self->ob_itself = NULL;
1082 Py_DECREF(_self->ob_callback);
1083 _self->ob_callback = NULL;
1084 Py_INCREF(Py_None);
1085 _res = Py_None;
1086 return _res;
1089 static PyMethodDef EventHandlerRef_methods[] = {
1090 {"AddEventTypesToHandler", (PyCFunction)EventHandlerRef_AddEventTypesToHandler, 1,
1091 PyDoc_STR("(UInt32 inNumTypes, EventTypeSpec inList) -> None")},
1092 {"RemoveEventTypesFromHandler", (PyCFunction)EventHandlerRef_RemoveEventTypesFromHandler, 1,
1093 PyDoc_STR("(UInt32 inNumTypes, EventTypeSpec inList) -> None")},
1094 {"RemoveEventHandler", (PyCFunction)EventHandlerRef_RemoveEventHandler, 1,
1095 PyDoc_STR("() -> None")},
1096 {NULL, NULL, 0}
1099 #define EventHandlerRef_getsetlist NULL
1102 #define EventHandlerRef_compare NULL
1104 #define EventHandlerRef_repr NULL
1106 #define EventHandlerRef_hash NULL
1107 #define EventHandlerRef_tp_init 0
1109 #define EventHandlerRef_tp_alloc PyType_GenericAlloc
1111 static PyObject *EventHandlerRef_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
1113 PyObject *self;
1114 EventHandlerRef itself;
1115 char *kw[] = {"itself", 0};
1117 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&", kw, EventHandlerRef_Convert, &itself)) return NULL;
1118 if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;
1119 ((EventHandlerRefObject *)self)->ob_itself = itself;
1120 return self;
1123 #define EventHandlerRef_tp_free PyObject_Del
1126 PyTypeObject EventHandlerRef_Type = {
1127 PyObject_HEAD_INIT(NULL)
1128 0, /*ob_size*/
1129 "_CarbonEvt.EventHandlerRef", /*tp_name*/
1130 sizeof(EventHandlerRefObject), /*tp_basicsize*/
1131 0, /*tp_itemsize*/
1132 /* methods */
1133 (destructor) EventHandlerRef_dealloc, /*tp_dealloc*/
1134 0, /*tp_print*/
1135 (getattrfunc)0, /*tp_getattr*/
1136 (setattrfunc)0, /*tp_setattr*/
1137 (cmpfunc) EventHandlerRef_compare, /*tp_compare*/
1138 (reprfunc) EventHandlerRef_repr, /*tp_repr*/
1139 (PyNumberMethods *)0, /* tp_as_number */
1140 (PySequenceMethods *)0, /* tp_as_sequence */
1141 (PyMappingMethods *)0, /* tp_as_mapping */
1142 (hashfunc) EventHandlerRef_hash, /*tp_hash*/
1143 0, /*tp_call*/
1144 0, /*tp_str*/
1145 PyObject_GenericGetAttr, /*tp_getattro*/
1146 PyObject_GenericSetAttr, /*tp_setattro */
1147 0, /*tp_as_buffer*/
1148 Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
1149 0, /*tp_doc*/
1150 0, /*tp_traverse*/
1151 0, /*tp_clear*/
1152 0, /*tp_richcompare*/
1153 0, /*tp_weaklistoffset*/
1154 0, /*tp_iter*/
1155 0, /*tp_iternext*/
1156 EventHandlerRef_methods, /* tp_methods */
1157 0, /*tp_members*/
1158 EventHandlerRef_getsetlist, /*tp_getset*/
1159 0, /*tp_base*/
1160 0, /*tp_dict*/
1161 0, /*tp_descr_get*/
1162 0, /*tp_descr_set*/
1163 0, /*tp_dictoffset*/
1164 EventHandlerRef_tp_init, /* tp_init */
1165 EventHandlerRef_tp_alloc, /* tp_alloc */
1166 EventHandlerRef_tp_new, /* tp_new */
1167 EventHandlerRef_tp_free, /* tp_free */
1170 /* ---------------- End object type EventHandlerRef ----------------- */
1173 /* ---------------- Object type EventHandlerCallRef ----------------- */
1175 PyTypeObject EventHandlerCallRef_Type;
1177 #define EventHandlerCallRef_Check(x) ((x)->ob_type == &EventHandlerCallRef_Type || PyObject_TypeCheck((x), &EventHandlerCallRef_Type))
1179 typedef struct EventHandlerCallRefObject {
1180 PyObject_HEAD
1181 EventHandlerCallRef ob_itself;
1182 } EventHandlerCallRefObject;
1184 PyObject *EventHandlerCallRef_New(EventHandlerCallRef itself)
1186 EventHandlerCallRefObject *it;
1187 it = PyObject_NEW(EventHandlerCallRefObject, &EventHandlerCallRef_Type);
1188 if (it == NULL) return NULL;
1189 it->ob_itself = itself;
1190 return (PyObject *)it;
1192 int EventHandlerCallRef_Convert(PyObject *v, EventHandlerCallRef *p_itself)
1194 if (!EventHandlerCallRef_Check(v))
1196 PyErr_SetString(PyExc_TypeError, "EventHandlerCallRef required");
1197 return 0;
1199 *p_itself = ((EventHandlerCallRefObject *)v)->ob_itself;
1200 return 1;
1203 static void EventHandlerCallRef_dealloc(EventHandlerCallRefObject *self)
1205 /* Cleanup of self->ob_itself goes here */
1206 self->ob_type->tp_free((PyObject *)self);
1209 static PyObject *EventHandlerCallRef_CallNextEventHandler(EventHandlerCallRefObject *_self, PyObject *_args)
1211 PyObject *_res = NULL;
1212 OSStatus _err;
1213 EventRef inEvent;
1214 if (!PyArg_ParseTuple(_args, "O&",
1215 EventRef_Convert, &inEvent))
1216 return NULL;
1217 _err = CallNextEventHandler(_self->ob_itself,
1218 inEvent);
1219 if (_err != noErr) return PyMac_Error(_err);
1220 Py_INCREF(Py_None);
1221 _res = Py_None;
1222 return _res;
1225 static PyMethodDef EventHandlerCallRef_methods[] = {
1226 {"CallNextEventHandler", (PyCFunction)EventHandlerCallRef_CallNextEventHandler, 1,
1227 PyDoc_STR("(EventRef inEvent) -> None")},
1228 {NULL, NULL, 0}
1231 #define EventHandlerCallRef_getsetlist NULL
1234 #define EventHandlerCallRef_compare NULL
1236 #define EventHandlerCallRef_repr NULL
1238 #define EventHandlerCallRef_hash NULL
1239 #define EventHandlerCallRef_tp_init 0
1241 #define EventHandlerCallRef_tp_alloc PyType_GenericAlloc
1243 static PyObject *EventHandlerCallRef_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
1245 PyObject *self;
1246 EventHandlerCallRef itself;
1247 char *kw[] = {"itself", 0};
1249 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&", kw, EventHandlerCallRef_Convert, &itself)) return NULL;
1250 if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;
1251 ((EventHandlerCallRefObject *)self)->ob_itself = itself;
1252 return self;
1255 #define EventHandlerCallRef_tp_free PyObject_Del
1258 PyTypeObject EventHandlerCallRef_Type = {
1259 PyObject_HEAD_INIT(NULL)
1260 0, /*ob_size*/
1261 "_CarbonEvt.EventHandlerCallRef", /*tp_name*/
1262 sizeof(EventHandlerCallRefObject), /*tp_basicsize*/
1263 0, /*tp_itemsize*/
1264 /* methods */
1265 (destructor) EventHandlerCallRef_dealloc, /*tp_dealloc*/
1266 0, /*tp_print*/
1267 (getattrfunc)0, /*tp_getattr*/
1268 (setattrfunc)0, /*tp_setattr*/
1269 (cmpfunc) EventHandlerCallRef_compare, /*tp_compare*/
1270 (reprfunc) EventHandlerCallRef_repr, /*tp_repr*/
1271 (PyNumberMethods *)0, /* tp_as_number */
1272 (PySequenceMethods *)0, /* tp_as_sequence */
1273 (PyMappingMethods *)0, /* tp_as_mapping */
1274 (hashfunc) EventHandlerCallRef_hash, /*tp_hash*/
1275 0, /*tp_call*/
1276 0, /*tp_str*/
1277 PyObject_GenericGetAttr, /*tp_getattro*/
1278 PyObject_GenericSetAttr, /*tp_setattro */
1279 0, /*tp_as_buffer*/
1280 Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
1281 0, /*tp_doc*/
1282 0, /*tp_traverse*/
1283 0, /*tp_clear*/
1284 0, /*tp_richcompare*/
1285 0, /*tp_weaklistoffset*/
1286 0, /*tp_iter*/
1287 0, /*tp_iternext*/
1288 EventHandlerCallRef_methods, /* tp_methods */
1289 0, /*tp_members*/
1290 EventHandlerCallRef_getsetlist, /*tp_getset*/
1291 0, /*tp_base*/
1292 0, /*tp_dict*/
1293 0, /*tp_descr_get*/
1294 0, /*tp_descr_set*/
1295 0, /*tp_dictoffset*/
1296 EventHandlerCallRef_tp_init, /* tp_init */
1297 EventHandlerCallRef_tp_alloc, /* tp_alloc */
1298 EventHandlerCallRef_tp_new, /* tp_new */
1299 EventHandlerCallRef_tp_free, /* tp_free */
1302 /* -------------- End object type EventHandlerCallRef --------------- */
1305 /* ------------------- Object type EventTargetRef ------------------- */
1307 PyTypeObject EventTargetRef_Type;
1309 #define EventTargetRef_Check(x) ((x)->ob_type == &EventTargetRef_Type || PyObject_TypeCheck((x), &EventTargetRef_Type))
1311 typedef struct EventTargetRefObject {
1312 PyObject_HEAD
1313 EventTargetRef ob_itself;
1314 } EventTargetRefObject;
1316 PyObject *EventTargetRef_New(EventTargetRef itself)
1318 EventTargetRefObject *it;
1319 it = PyObject_NEW(EventTargetRefObject, &EventTargetRef_Type);
1320 if (it == NULL) return NULL;
1321 it->ob_itself = itself;
1322 return (PyObject *)it;
1324 int EventTargetRef_Convert(PyObject *v, EventTargetRef *p_itself)
1326 if (!EventTargetRef_Check(v))
1328 PyErr_SetString(PyExc_TypeError, "EventTargetRef required");
1329 return 0;
1331 *p_itself = ((EventTargetRefObject *)v)->ob_itself;
1332 return 1;
1335 static void EventTargetRef_dealloc(EventTargetRefObject *self)
1337 /* Cleanup of self->ob_itself goes here */
1338 self->ob_type->tp_free((PyObject *)self);
1341 static PyObject *EventTargetRef_InstallStandardEventHandler(EventTargetRefObject *_self, PyObject *_args)
1343 PyObject *_res = NULL;
1344 OSStatus _err;
1345 if (!PyArg_ParseTuple(_args, ""))
1346 return NULL;
1347 _err = InstallStandardEventHandler(_self->ob_itself);
1348 if (_err != noErr) return PyMac_Error(_err);
1349 Py_INCREF(Py_None);
1350 _res = Py_None;
1351 return _res;
1354 static PyObject *EventTargetRef_InstallEventHandler(EventTargetRefObject *_self, PyObject *_args)
1356 PyObject *_res = NULL;
1358 EventTypeSpec inSpec;
1359 PyObject *callback;
1360 EventHandlerRef outRef;
1361 OSStatus _err;
1363 if (!PyArg_ParseTuple(_args, "O&O", EventTypeSpec_Convert, &inSpec, &callback))
1364 return NULL;
1366 _err = InstallEventHandler(_self->ob_itself, myEventHandlerUPP, 1, &inSpec, (void *)callback, &outRef);
1367 if (_err != noErr) return PyMac_Error(_err);
1369 _res = EventHandlerRef_New(outRef);
1370 if (_res != NULL) {
1371 ((EventHandlerRefObject*)_res)->ob_callback = callback;
1372 Py_INCREF(callback);
1374 return _res;
1377 static PyMethodDef EventTargetRef_methods[] = {
1378 {"InstallStandardEventHandler", (PyCFunction)EventTargetRef_InstallStandardEventHandler, 1,
1379 PyDoc_STR("() -> None")},
1380 {"InstallEventHandler", (PyCFunction)EventTargetRef_InstallEventHandler, 1,
1381 PyDoc_STR("(EventTypeSpec inSpec, Method callback) -> (EventHandlerRef outRef)")},
1382 {NULL, NULL, 0}
1385 #define EventTargetRef_getsetlist NULL
1388 #define EventTargetRef_compare NULL
1390 #define EventTargetRef_repr NULL
1392 #define EventTargetRef_hash NULL
1393 #define EventTargetRef_tp_init 0
1395 #define EventTargetRef_tp_alloc PyType_GenericAlloc
1397 static PyObject *EventTargetRef_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
1399 PyObject *self;
1400 EventTargetRef itself;
1401 char *kw[] = {"itself", 0};
1403 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&", kw, EventTargetRef_Convert, &itself)) return NULL;
1404 if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;
1405 ((EventTargetRefObject *)self)->ob_itself = itself;
1406 return self;
1409 #define EventTargetRef_tp_free PyObject_Del
1412 PyTypeObject EventTargetRef_Type = {
1413 PyObject_HEAD_INIT(NULL)
1414 0, /*ob_size*/
1415 "_CarbonEvt.EventTargetRef", /*tp_name*/
1416 sizeof(EventTargetRefObject), /*tp_basicsize*/
1417 0, /*tp_itemsize*/
1418 /* methods */
1419 (destructor) EventTargetRef_dealloc, /*tp_dealloc*/
1420 0, /*tp_print*/
1421 (getattrfunc)0, /*tp_getattr*/
1422 (setattrfunc)0, /*tp_setattr*/
1423 (cmpfunc) EventTargetRef_compare, /*tp_compare*/
1424 (reprfunc) EventTargetRef_repr, /*tp_repr*/
1425 (PyNumberMethods *)0, /* tp_as_number */
1426 (PySequenceMethods *)0, /* tp_as_sequence */
1427 (PyMappingMethods *)0, /* tp_as_mapping */
1428 (hashfunc) EventTargetRef_hash, /*tp_hash*/
1429 0, /*tp_call*/
1430 0, /*tp_str*/
1431 PyObject_GenericGetAttr, /*tp_getattro*/
1432 PyObject_GenericSetAttr, /*tp_setattro */
1433 0, /*tp_as_buffer*/
1434 Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
1435 0, /*tp_doc*/
1436 0, /*tp_traverse*/
1437 0, /*tp_clear*/
1438 0, /*tp_richcompare*/
1439 0, /*tp_weaklistoffset*/
1440 0, /*tp_iter*/
1441 0, /*tp_iternext*/
1442 EventTargetRef_methods, /* tp_methods */
1443 0, /*tp_members*/
1444 EventTargetRef_getsetlist, /*tp_getset*/
1445 0, /*tp_base*/
1446 0, /*tp_dict*/
1447 0, /*tp_descr_get*/
1448 0, /*tp_descr_set*/
1449 0, /*tp_dictoffset*/
1450 EventTargetRef_tp_init, /* tp_init */
1451 EventTargetRef_tp_alloc, /* tp_alloc */
1452 EventTargetRef_tp_new, /* tp_new */
1453 EventTargetRef_tp_free, /* tp_free */
1456 /* ----------------- End object type EventTargetRef ----------------- */
1459 /* ------------------- Object type EventHotKeyRef ------------------- */
1461 PyTypeObject EventHotKeyRef_Type;
1463 #define EventHotKeyRef_Check(x) ((x)->ob_type == &EventHotKeyRef_Type || PyObject_TypeCheck((x), &EventHotKeyRef_Type))
1465 typedef struct EventHotKeyRefObject {
1466 PyObject_HEAD
1467 EventHotKeyRef ob_itself;
1468 } EventHotKeyRefObject;
1470 PyObject *EventHotKeyRef_New(EventHotKeyRef itself)
1472 EventHotKeyRefObject *it;
1473 it = PyObject_NEW(EventHotKeyRefObject, &EventHotKeyRef_Type);
1474 if (it == NULL) return NULL;
1475 it->ob_itself = itself;
1476 return (PyObject *)it;
1478 int EventHotKeyRef_Convert(PyObject *v, EventHotKeyRef *p_itself)
1480 if (!EventHotKeyRef_Check(v))
1482 PyErr_SetString(PyExc_TypeError, "EventHotKeyRef required");
1483 return 0;
1485 *p_itself = ((EventHotKeyRefObject *)v)->ob_itself;
1486 return 1;
1489 static void EventHotKeyRef_dealloc(EventHotKeyRefObject *self)
1491 /* Cleanup of self->ob_itself goes here */
1492 self->ob_type->tp_free((PyObject *)self);
1495 static PyObject *EventHotKeyRef_UnregisterEventHotKey(EventHotKeyRefObject *_self, PyObject *_args)
1497 PyObject *_res = NULL;
1498 OSStatus _err;
1499 if (!PyArg_ParseTuple(_args, ""))
1500 return NULL;
1501 _err = UnregisterEventHotKey(_self->ob_itself);
1502 if (_err != noErr) return PyMac_Error(_err);
1503 Py_INCREF(Py_None);
1504 _res = Py_None;
1505 return _res;
1508 static PyMethodDef EventHotKeyRef_methods[] = {
1509 {"UnregisterEventHotKey", (PyCFunction)EventHotKeyRef_UnregisterEventHotKey, 1,
1510 PyDoc_STR("() -> None")},
1511 {NULL, NULL, 0}
1514 #define EventHotKeyRef_getsetlist NULL
1517 #define EventHotKeyRef_compare NULL
1519 #define EventHotKeyRef_repr NULL
1521 #define EventHotKeyRef_hash NULL
1522 #define EventHotKeyRef_tp_init 0
1524 #define EventHotKeyRef_tp_alloc PyType_GenericAlloc
1526 static PyObject *EventHotKeyRef_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
1528 PyObject *self;
1529 EventHotKeyRef itself;
1530 char *kw[] = {"itself", 0};
1532 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&", kw, EventHotKeyRef_Convert, &itself)) return NULL;
1533 if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;
1534 ((EventHotKeyRefObject *)self)->ob_itself = itself;
1535 return self;
1538 #define EventHotKeyRef_tp_free PyObject_Del
1541 PyTypeObject EventHotKeyRef_Type = {
1542 PyObject_HEAD_INIT(NULL)
1543 0, /*ob_size*/
1544 "_CarbonEvt.EventHotKeyRef", /*tp_name*/
1545 sizeof(EventHotKeyRefObject), /*tp_basicsize*/
1546 0, /*tp_itemsize*/
1547 /* methods */
1548 (destructor) EventHotKeyRef_dealloc, /*tp_dealloc*/
1549 0, /*tp_print*/
1550 (getattrfunc)0, /*tp_getattr*/
1551 (setattrfunc)0, /*tp_setattr*/
1552 (cmpfunc) EventHotKeyRef_compare, /*tp_compare*/
1553 (reprfunc) EventHotKeyRef_repr, /*tp_repr*/
1554 (PyNumberMethods *)0, /* tp_as_number */
1555 (PySequenceMethods *)0, /* tp_as_sequence */
1556 (PyMappingMethods *)0, /* tp_as_mapping */
1557 (hashfunc) EventHotKeyRef_hash, /*tp_hash*/
1558 0, /*tp_call*/
1559 0, /*tp_str*/
1560 PyObject_GenericGetAttr, /*tp_getattro*/
1561 PyObject_GenericSetAttr, /*tp_setattro */
1562 0, /*tp_as_buffer*/
1563 Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
1564 0, /*tp_doc*/
1565 0, /*tp_traverse*/
1566 0, /*tp_clear*/
1567 0, /*tp_richcompare*/
1568 0, /*tp_weaklistoffset*/
1569 0, /*tp_iter*/
1570 0, /*tp_iternext*/
1571 EventHotKeyRef_methods, /* tp_methods */
1572 0, /*tp_members*/
1573 EventHotKeyRef_getsetlist, /*tp_getset*/
1574 0, /*tp_base*/
1575 0, /*tp_dict*/
1576 0, /*tp_descr_get*/
1577 0, /*tp_descr_set*/
1578 0, /*tp_dictoffset*/
1579 EventHotKeyRef_tp_init, /* tp_init */
1580 EventHotKeyRef_tp_alloc, /* tp_alloc */
1581 EventHotKeyRef_tp_new, /* tp_new */
1582 EventHotKeyRef_tp_free, /* tp_free */
1585 /* ----------------- End object type EventHotKeyRef ----------------- */
1588 static PyObject *CarbonEvents_GetCurrentEventLoop(PyObject *_self, PyObject *_args)
1590 PyObject *_res = NULL;
1591 EventLoopRef _rv;
1592 if (!PyArg_ParseTuple(_args, ""))
1593 return NULL;
1594 _rv = GetCurrentEventLoop();
1595 _res = Py_BuildValue("O&",
1596 EventLoopRef_New, _rv);
1597 return _res;
1600 static PyObject *CarbonEvents_GetMainEventLoop(PyObject *_self, PyObject *_args)
1602 PyObject *_res = NULL;
1603 EventLoopRef _rv;
1604 if (!PyArg_ParseTuple(_args, ""))
1605 return NULL;
1606 _rv = GetMainEventLoop();
1607 _res = Py_BuildValue("O&",
1608 EventLoopRef_New, _rv);
1609 return _res;
1612 static PyObject *CarbonEvents_RunCurrentEventLoop(PyObject *_self, PyObject *_args)
1614 PyObject *_res = NULL;
1615 OSStatus _err;
1616 double inTimeout;
1617 if (!PyArg_ParseTuple(_args, "d",
1618 &inTimeout))
1619 return NULL;
1620 _err = RunCurrentEventLoop(inTimeout);
1621 if (_err != noErr) return PyMac_Error(_err);
1622 Py_INCREF(Py_None);
1623 _res = Py_None;
1624 return _res;
1627 static PyObject *CarbonEvents_ReceiveNextEvent(PyObject *_self, PyObject *_args)
1629 PyObject *_res = NULL;
1630 OSStatus _err;
1631 UInt32 inNumTypes;
1632 EventTypeSpec inList;
1633 double inTimeout;
1634 Boolean inPullEvent;
1635 EventRef outEvent;
1636 if (!PyArg_ParseTuple(_args, "lO&db",
1637 &inNumTypes,
1638 EventTypeSpec_Convert, &inList,
1639 &inTimeout,
1640 &inPullEvent))
1641 return NULL;
1642 _err = ReceiveNextEvent(inNumTypes,
1643 &inList,
1644 inTimeout,
1645 inPullEvent,
1646 &outEvent);
1647 if (_err != noErr) return PyMac_Error(_err);
1648 _res = Py_BuildValue("O&",
1649 EventRef_New, outEvent);
1650 return _res;
1653 static PyObject *CarbonEvents_GetCurrentEventQueue(PyObject *_self, PyObject *_args)
1655 PyObject *_res = NULL;
1656 EventQueueRef _rv;
1657 if (!PyArg_ParseTuple(_args, ""))
1658 return NULL;
1659 _rv = GetCurrentEventQueue();
1660 _res = Py_BuildValue("O&",
1661 EventQueueRef_New, _rv);
1662 return _res;
1665 static PyObject *CarbonEvents_GetMainEventQueue(PyObject *_self, PyObject *_args)
1667 PyObject *_res = NULL;
1668 EventQueueRef _rv;
1669 if (!PyArg_ParseTuple(_args, ""))
1670 return NULL;
1671 _rv = GetMainEventQueue();
1672 _res = Py_BuildValue("O&",
1673 EventQueueRef_New, _rv);
1674 return _res;
1677 static PyObject *CarbonEvents_GetCurrentEventTime(PyObject *_self, PyObject *_args)
1679 PyObject *_res = NULL;
1680 double _rv;
1681 if (!PyArg_ParseTuple(_args, ""))
1682 return NULL;
1683 _rv = GetCurrentEventTime();
1684 _res = Py_BuildValue("d",
1685 _rv);
1686 return _res;
1689 static PyObject *CarbonEvents_TrackMouseLocation(PyObject *_self, PyObject *_args)
1691 PyObject *_res = NULL;
1692 OSStatus _err;
1693 GrafPtr inPort;
1694 Point outPt;
1695 UInt16 outResult;
1696 if (!PyArg_ParseTuple(_args, "O&",
1697 GrafObj_Convert, &inPort))
1698 return NULL;
1699 _err = TrackMouseLocation(inPort,
1700 &outPt,
1701 &outResult);
1702 if (_err != noErr) return PyMac_Error(_err);
1703 _res = Py_BuildValue("O&H",
1704 PyMac_BuildPoint, outPt,
1705 outResult);
1706 return _res;
1709 static PyObject *CarbonEvents_TrackMouseLocationWithOptions(PyObject *_self, PyObject *_args)
1711 PyObject *_res = NULL;
1712 OSStatus _err;
1713 GrafPtr inPort;
1714 OptionBits inOptions;
1715 double inTimeout;
1716 Point outPt;
1717 UInt32 outModifiers;
1718 UInt16 outResult;
1719 if (!PyArg_ParseTuple(_args, "O&ld",
1720 GrafObj_Convert, &inPort,
1721 &inOptions,
1722 &inTimeout))
1723 return NULL;
1724 _err = TrackMouseLocationWithOptions(inPort,
1725 inOptions,
1726 inTimeout,
1727 &outPt,
1728 &outModifiers,
1729 &outResult);
1730 if (_err != noErr) return PyMac_Error(_err);
1731 _res = Py_BuildValue("O&lH",
1732 PyMac_BuildPoint, outPt,
1733 outModifiers,
1734 outResult);
1735 return _res;
1738 static PyObject *CarbonEvents_TrackMouseRegion(PyObject *_self, PyObject *_args)
1740 PyObject *_res = NULL;
1741 OSStatus _err;
1742 GrafPtr inPort;
1743 RgnHandle inRegion;
1744 Boolean ioWasInRgn;
1745 UInt16 outResult;
1746 if (!PyArg_ParseTuple(_args, "O&O&b",
1747 GrafObj_Convert, &inPort,
1748 ResObj_Convert, &inRegion,
1749 &ioWasInRgn))
1750 return NULL;
1751 _err = TrackMouseRegion(inPort,
1752 inRegion,
1753 &ioWasInRgn,
1754 &outResult);
1755 if (_err != noErr) return PyMac_Error(_err);
1756 _res = Py_BuildValue("bH",
1757 ioWasInRgn,
1758 outResult);
1759 return _res;
1762 static PyObject *CarbonEvents_GetLastUserEventTime(PyObject *_self, PyObject *_args)
1764 PyObject *_res = NULL;
1765 double _rv;
1766 if (!PyArg_ParseTuple(_args, ""))
1767 return NULL;
1768 _rv = GetLastUserEventTime();
1769 _res = Py_BuildValue("d",
1770 _rv);
1771 return _res;
1774 static PyObject *CarbonEvents_GetWindowEventTarget(PyObject *_self, PyObject *_args)
1776 PyObject *_res = NULL;
1777 EventTargetRef _rv;
1778 WindowPtr inWindow;
1779 if (!PyArg_ParseTuple(_args, "O&",
1780 WinObj_Convert, &inWindow))
1781 return NULL;
1782 _rv = GetWindowEventTarget(inWindow);
1783 _res = Py_BuildValue("O&",
1784 EventTargetRef_New, _rv);
1785 return _res;
1788 static PyObject *CarbonEvents_GetControlEventTarget(PyObject *_self, PyObject *_args)
1790 PyObject *_res = NULL;
1791 EventTargetRef _rv;
1792 ControlHandle inControl;
1793 if (!PyArg_ParseTuple(_args, "O&",
1794 CtlObj_Convert, &inControl))
1795 return NULL;
1796 _rv = GetControlEventTarget(inControl);
1797 _res = Py_BuildValue("O&",
1798 EventTargetRef_New, _rv);
1799 return _res;
1802 static PyObject *CarbonEvents_GetMenuEventTarget(PyObject *_self, PyObject *_args)
1804 PyObject *_res = NULL;
1805 EventTargetRef _rv;
1806 MenuHandle inMenu;
1807 if (!PyArg_ParseTuple(_args, "O&",
1808 MenuObj_Convert, &inMenu))
1809 return NULL;
1810 _rv = GetMenuEventTarget(inMenu);
1811 _res = Py_BuildValue("O&",
1812 EventTargetRef_New, _rv);
1813 return _res;
1816 static PyObject *CarbonEvents_GetApplicationEventTarget(PyObject *_self, PyObject *_args)
1818 PyObject *_res = NULL;
1819 EventTargetRef _rv;
1820 if (!PyArg_ParseTuple(_args, ""))
1821 return NULL;
1822 _rv = GetApplicationEventTarget();
1823 _res = Py_BuildValue("O&",
1824 EventTargetRef_New, _rv);
1825 return _res;
1828 static PyObject *CarbonEvents_GetUserFocusEventTarget(PyObject *_self, PyObject *_args)
1830 PyObject *_res = NULL;
1831 EventTargetRef _rv;
1832 if (!PyArg_ParseTuple(_args, ""))
1833 return NULL;
1834 _rv = GetUserFocusEventTarget();
1835 _res = Py_BuildValue("O&",
1836 EventTargetRef_New, _rv);
1837 return _res;
1840 static PyObject *CarbonEvents_GetEventDispatcherTarget(PyObject *_self, PyObject *_args)
1842 PyObject *_res = NULL;
1843 EventTargetRef _rv;
1844 if (!PyArg_ParseTuple(_args, ""))
1845 return NULL;
1846 _rv = GetEventDispatcherTarget();
1847 _res = Py_BuildValue("O&",
1848 EventTargetRef_New, _rv);
1849 return _res;
1852 static PyObject *CarbonEvents_QuitApplicationEventLoop(PyObject *_self, PyObject *_args)
1854 PyObject *_res = NULL;
1855 if (!PyArg_ParseTuple(_args, ""))
1856 return NULL;
1857 QuitApplicationEventLoop();
1858 Py_INCREF(Py_None);
1859 _res = Py_None;
1860 return _res;
1863 static PyObject *CarbonEvents_RunAppModalLoopForWindow(PyObject *_self, PyObject *_args)
1865 PyObject *_res = NULL;
1866 OSStatus _err;
1867 WindowPtr inWindow;
1868 if (!PyArg_ParseTuple(_args, "O&",
1869 WinObj_Convert, &inWindow))
1870 return NULL;
1871 _err = RunAppModalLoopForWindow(inWindow);
1872 if (_err != noErr) return PyMac_Error(_err);
1873 Py_INCREF(Py_None);
1874 _res = Py_None;
1875 return _res;
1878 static PyObject *CarbonEvents_QuitAppModalLoopForWindow(PyObject *_self, PyObject *_args)
1880 PyObject *_res = NULL;
1881 OSStatus _err;
1882 WindowPtr inWindow;
1883 if (!PyArg_ParseTuple(_args, "O&",
1884 WinObj_Convert, &inWindow))
1885 return NULL;
1886 _err = QuitAppModalLoopForWindow(inWindow);
1887 if (_err != noErr) return PyMac_Error(_err);
1888 Py_INCREF(Py_None);
1889 _res = Py_None;
1890 return _res;
1893 static PyObject *CarbonEvents_BeginAppModalStateForWindow(PyObject *_self, PyObject *_args)
1895 PyObject *_res = NULL;
1896 OSStatus _err;
1897 WindowPtr inWindow;
1898 if (!PyArg_ParseTuple(_args, "O&",
1899 WinObj_Convert, &inWindow))
1900 return NULL;
1901 _err = BeginAppModalStateForWindow(inWindow);
1902 if (_err != noErr) return PyMac_Error(_err);
1903 Py_INCREF(Py_None);
1904 _res = Py_None;
1905 return _res;
1908 static PyObject *CarbonEvents_EndAppModalStateForWindow(PyObject *_self, PyObject *_args)
1910 PyObject *_res = NULL;
1911 OSStatus _err;
1912 WindowPtr inWindow;
1913 if (!PyArg_ParseTuple(_args, "O&",
1914 WinObj_Convert, &inWindow))
1915 return NULL;
1916 _err = EndAppModalStateForWindow(inWindow);
1917 if (_err != noErr) return PyMac_Error(_err);
1918 Py_INCREF(Py_None);
1919 _res = Py_None;
1920 return _res;
1923 static PyObject *CarbonEvents_SetUserFocusWindow(PyObject *_self, PyObject *_args)
1925 PyObject *_res = NULL;
1926 OSStatus _err;
1927 WindowPtr inWindow;
1928 if (!PyArg_ParseTuple(_args, "O&",
1929 WinObj_Convert, &inWindow))
1930 return NULL;
1931 _err = SetUserFocusWindow(inWindow);
1932 if (_err != noErr) return PyMac_Error(_err);
1933 Py_INCREF(Py_None);
1934 _res = Py_None;
1935 return _res;
1938 static PyObject *CarbonEvents_GetUserFocusWindow(PyObject *_self, PyObject *_args)
1940 PyObject *_res = NULL;
1941 WindowPtr _rv;
1942 if (!PyArg_ParseTuple(_args, ""))
1943 return NULL;
1944 _rv = GetUserFocusWindow();
1945 _res = Py_BuildValue("O&",
1946 WinObj_New, _rv);
1947 return _res;
1950 static PyObject *CarbonEvents_SetWindowDefaultButton(PyObject *_self, PyObject *_args)
1952 PyObject *_res = NULL;
1953 OSStatus _err;
1954 WindowPtr inWindow;
1955 ControlHandle inControl;
1956 if (!PyArg_ParseTuple(_args, "O&O&",
1957 WinObj_Convert, &inWindow,
1958 CtlObj_Convert, &inControl))
1959 return NULL;
1960 _err = SetWindowDefaultButton(inWindow,
1961 inControl);
1962 if (_err != noErr) return PyMac_Error(_err);
1963 Py_INCREF(Py_None);
1964 _res = Py_None;
1965 return _res;
1968 static PyObject *CarbonEvents_SetWindowCancelButton(PyObject *_self, PyObject *_args)
1970 PyObject *_res = NULL;
1971 OSStatus _err;
1972 WindowPtr inWindow;
1973 ControlHandle inControl;
1974 if (!PyArg_ParseTuple(_args, "O&O&",
1975 WinObj_Convert, &inWindow,
1976 CtlObj_Convert, &inControl))
1977 return NULL;
1978 _err = SetWindowCancelButton(inWindow,
1979 inControl);
1980 if (_err != noErr) return PyMac_Error(_err);
1981 Py_INCREF(Py_None);
1982 _res = Py_None;
1983 return _res;
1986 static PyObject *CarbonEvents_GetWindowDefaultButton(PyObject *_self, PyObject *_args)
1988 PyObject *_res = NULL;
1989 OSStatus _err;
1990 WindowPtr inWindow;
1991 ControlHandle outControl;
1992 if (!PyArg_ParseTuple(_args, "O&",
1993 WinObj_Convert, &inWindow))
1994 return NULL;
1995 _err = GetWindowDefaultButton(inWindow,
1996 &outControl);
1997 if (_err != noErr) return PyMac_Error(_err);
1998 _res = Py_BuildValue("O&",
1999 CtlObj_New, outControl);
2000 return _res;
2003 static PyObject *CarbonEvents_GetWindowCancelButton(PyObject *_self, PyObject *_args)
2005 PyObject *_res = NULL;
2006 OSStatus _err;
2007 WindowPtr inWindow;
2008 ControlHandle outControl;
2009 if (!PyArg_ParseTuple(_args, "O&",
2010 WinObj_Convert, &inWindow))
2011 return NULL;
2012 _err = GetWindowCancelButton(inWindow,
2013 &outControl);
2014 if (_err != noErr) return PyMac_Error(_err);
2015 _res = Py_BuildValue("O&",
2016 CtlObj_New, outControl);
2017 return _res;
2020 static PyObject *CarbonEvents_RegisterEventHotKey(PyObject *_self, PyObject *_args)
2022 PyObject *_res = NULL;
2023 OSStatus _err;
2024 UInt32 inHotKeyCode;
2025 UInt32 inHotKeyModifiers;
2026 EventHotKeyID inHotKeyID;
2027 EventTargetRef inTarget;
2028 OptionBits inOptions;
2029 EventHotKeyRef outRef;
2030 if (!PyArg_ParseTuple(_args, "llO&O&l",
2031 &inHotKeyCode,
2032 &inHotKeyModifiers,
2033 EventHotKeyID_Convert, &inHotKeyID,
2034 EventTargetRef_Convert, &inTarget,
2035 &inOptions))
2036 return NULL;
2037 _err = RegisterEventHotKey(inHotKeyCode,
2038 inHotKeyModifiers,
2039 inHotKeyID,
2040 inTarget,
2041 inOptions,
2042 &outRef);
2043 if (_err != noErr) return PyMac_Error(_err);
2044 _res = Py_BuildValue("O&",
2045 EventHotKeyRef_New, outRef);
2046 return _res;
2049 static PyObject *CarbonEvents_RunApplicationEventLoop(PyObject *_self, PyObject *_args)
2051 PyObject *_res = NULL;
2053 #if USE_MAC_MP_MULTITHREADING
2054 if (MPCreateCriticalRegion(&reentrantLock) != noErr) {
2055 PySys_WriteStderr("lock failure\n");
2056 return NULL;
2058 _save = PyEval_SaveThread();
2059 #endif /* USE_MAC_MP_MULTITHREADING */
2061 RunApplicationEventLoop();
2063 #if USE_MAC_MP_MULTITHREADING
2064 PyEval_RestoreThread(_save);
2066 MPDeleteCriticalRegion(reentrantLock);
2067 #endif /* USE_MAC_MP_MULTITHREADING */
2069 Py_INCREF(Py_None);
2070 _res = Py_None;
2071 return _res;
2075 static PyMethodDef CarbonEvents_methods[] = {
2076 {"GetCurrentEventLoop", (PyCFunction)CarbonEvents_GetCurrentEventLoop, 1,
2077 PyDoc_STR("() -> (EventLoopRef _rv)")},
2078 {"GetMainEventLoop", (PyCFunction)CarbonEvents_GetMainEventLoop, 1,
2079 PyDoc_STR("() -> (EventLoopRef _rv)")},
2080 {"RunCurrentEventLoop", (PyCFunction)CarbonEvents_RunCurrentEventLoop, 1,
2081 PyDoc_STR("(double inTimeout) -> None")},
2082 {"ReceiveNextEvent", (PyCFunction)CarbonEvents_ReceiveNextEvent, 1,
2083 PyDoc_STR("(UInt32 inNumTypes, EventTypeSpec inList, double inTimeout, Boolean inPullEvent) -> (EventRef outEvent)")},
2084 {"GetCurrentEventQueue", (PyCFunction)CarbonEvents_GetCurrentEventQueue, 1,
2085 PyDoc_STR("() -> (EventQueueRef _rv)")},
2086 {"GetMainEventQueue", (PyCFunction)CarbonEvents_GetMainEventQueue, 1,
2087 PyDoc_STR("() -> (EventQueueRef _rv)")},
2088 {"GetCurrentEventTime", (PyCFunction)CarbonEvents_GetCurrentEventTime, 1,
2089 PyDoc_STR("() -> (double _rv)")},
2090 {"TrackMouseLocation", (PyCFunction)CarbonEvents_TrackMouseLocation, 1,
2091 PyDoc_STR("(GrafPtr inPort) -> (Point outPt, UInt16 outResult)")},
2092 {"TrackMouseLocationWithOptions", (PyCFunction)CarbonEvents_TrackMouseLocationWithOptions, 1,
2093 PyDoc_STR("(GrafPtr inPort, OptionBits inOptions, double inTimeout) -> (Point outPt, UInt32 outModifiers, UInt16 outResult)")},
2094 {"TrackMouseRegion", (PyCFunction)CarbonEvents_TrackMouseRegion, 1,
2095 PyDoc_STR("(GrafPtr inPort, RgnHandle inRegion, Boolean ioWasInRgn) -> (Boolean ioWasInRgn, UInt16 outResult)")},
2096 {"GetLastUserEventTime", (PyCFunction)CarbonEvents_GetLastUserEventTime, 1,
2097 PyDoc_STR("() -> (double _rv)")},
2098 {"GetWindowEventTarget", (PyCFunction)CarbonEvents_GetWindowEventTarget, 1,
2099 PyDoc_STR("(WindowPtr inWindow) -> (EventTargetRef _rv)")},
2100 {"GetControlEventTarget", (PyCFunction)CarbonEvents_GetControlEventTarget, 1,
2101 PyDoc_STR("(ControlHandle inControl) -> (EventTargetRef _rv)")},
2102 {"GetMenuEventTarget", (PyCFunction)CarbonEvents_GetMenuEventTarget, 1,
2103 PyDoc_STR("(MenuHandle inMenu) -> (EventTargetRef _rv)")},
2104 {"GetApplicationEventTarget", (PyCFunction)CarbonEvents_GetApplicationEventTarget, 1,
2105 PyDoc_STR("() -> (EventTargetRef _rv)")},
2106 {"GetUserFocusEventTarget", (PyCFunction)CarbonEvents_GetUserFocusEventTarget, 1,
2107 PyDoc_STR("() -> (EventTargetRef _rv)")},
2108 {"GetEventDispatcherTarget", (PyCFunction)CarbonEvents_GetEventDispatcherTarget, 1,
2109 PyDoc_STR("() -> (EventTargetRef _rv)")},
2110 {"QuitApplicationEventLoop", (PyCFunction)CarbonEvents_QuitApplicationEventLoop, 1,
2111 PyDoc_STR("() -> None")},
2112 {"RunAppModalLoopForWindow", (PyCFunction)CarbonEvents_RunAppModalLoopForWindow, 1,
2113 PyDoc_STR("(WindowPtr inWindow) -> None")},
2114 {"QuitAppModalLoopForWindow", (PyCFunction)CarbonEvents_QuitAppModalLoopForWindow, 1,
2115 PyDoc_STR("(WindowPtr inWindow) -> None")},
2116 {"BeginAppModalStateForWindow", (PyCFunction)CarbonEvents_BeginAppModalStateForWindow, 1,
2117 PyDoc_STR("(WindowPtr inWindow) -> None")},
2118 {"EndAppModalStateForWindow", (PyCFunction)CarbonEvents_EndAppModalStateForWindow, 1,
2119 PyDoc_STR("(WindowPtr inWindow) -> None")},
2120 {"SetUserFocusWindow", (PyCFunction)CarbonEvents_SetUserFocusWindow, 1,
2121 PyDoc_STR("(WindowPtr inWindow) -> None")},
2122 {"GetUserFocusWindow", (PyCFunction)CarbonEvents_GetUserFocusWindow, 1,
2123 PyDoc_STR("() -> (WindowPtr _rv)")},
2124 {"SetWindowDefaultButton", (PyCFunction)CarbonEvents_SetWindowDefaultButton, 1,
2125 PyDoc_STR("(WindowPtr inWindow, ControlHandle inControl) -> None")},
2126 {"SetWindowCancelButton", (PyCFunction)CarbonEvents_SetWindowCancelButton, 1,
2127 PyDoc_STR("(WindowPtr inWindow, ControlHandle inControl) -> None")},
2128 {"GetWindowDefaultButton", (PyCFunction)CarbonEvents_GetWindowDefaultButton, 1,
2129 PyDoc_STR("(WindowPtr inWindow) -> (ControlHandle outControl)")},
2130 {"GetWindowCancelButton", (PyCFunction)CarbonEvents_GetWindowCancelButton, 1,
2131 PyDoc_STR("(WindowPtr inWindow) -> (ControlHandle outControl)")},
2132 {"RegisterEventHotKey", (PyCFunction)CarbonEvents_RegisterEventHotKey, 1,
2133 PyDoc_STR("(UInt32 inHotKeyCode, UInt32 inHotKeyModifiers, EventHotKeyID inHotKeyID, EventTargetRef inTarget, OptionBits inOptions) -> (EventHotKeyRef outRef)")},
2134 {"RunApplicationEventLoop", (PyCFunction)CarbonEvents_RunApplicationEventLoop, 1,
2135 PyDoc_STR("() -> ()")},
2136 {NULL, NULL, 0}
2142 void init_CarbonEvt(void)
2144 PyObject *m;
2145 PyObject *d;
2149 PyMac_PRECHECK(NewEventHandlerUPP); /* This can fail if CarbonLib is too old */
2150 myEventHandlerUPP = NewEventHandlerUPP(myEventHandler);
2153 m = Py_InitModule("_CarbonEvt", CarbonEvents_methods);
2154 d = PyModule_GetDict(m);
2155 CarbonEvents_Error = PyMac_GetOSErrException();
2156 if (CarbonEvents_Error == NULL ||
2157 PyDict_SetItemString(d, "Error", CarbonEvents_Error) != 0)
2158 return;
2159 EventRef_Type.ob_type = &PyType_Type;
2160 if (PyType_Ready(&EventRef_Type) < 0) return;
2161 Py_INCREF(&EventRef_Type);
2162 PyModule_AddObject(m, "EventRef", (PyObject *)&EventRef_Type);
2163 /* Backward-compatible name */
2164 Py_INCREF(&EventRef_Type);
2165 PyModule_AddObject(m, "EventRefType", (PyObject *)&EventRef_Type);
2166 EventQueueRef_Type.ob_type = &PyType_Type;
2167 if (PyType_Ready(&EventQueueRef_Type) < 0) return;
2168 Py_INCREF(&EventQueueRef_Type);
2169 PyModule_AddObject(m, "EventQueueRef", (PyObject *)&EventQueueRef_Type);
2170 /* Backward-compatible name */
2171 Py_INCREF(&EventQueueRef_Type);
2172 PyModule_AddObject(m, "EventQueueRefType", (PyObject *)&EventQueueRef_Type);
2173 EventLoopRef_Type.ob_type = &PyType_Type;
2174 if (PyType_Ready(&EventLoopRef_Type) < 0) return;
2175 Py_INCREF(&EventLoopRef_Type);
2176 PyModule_AddObject(m, "EventLoopRef", (PyObject *)&EventLoopRef_Type);
2177 /* Backward-compatible name */
2178 Py_INCREF(&EventLoopRef_Type);
2179 PyModule_AddObject(m, "EventLoopRefType", (PyObject *)&EventLoopRef_Type);
2180 EventLoopTimerRef_Type.ob_type = &PyType_Type;
2181 if (PyType_Ready(&EventLoopTimerRef_Type) < 0) return;
2182 Py_INCREF(&EventLoopTimerRef_Type);
2183 PyModule_AddObject(m, "EventLoopTimerRef", (PyObject *)&EventLoopTimerRef_Type);
2184 /* Backward-compatible name */
2185 Py_INCREF(&EventLoopTimerRef_Type);
2186 PyModule_AddObject(m, "EventLoopTimerRefType", (PyObject *)&EventLoopTimerRef_Type);
2187 EventHandlerRef_Type.ob_type = &PyType_Type;
2188 if (PyType_Ready(&EventHandlerRef_Type) < 0) return;
2189 Py_INCREF(&EventHandlerRef_Type);
2190 PyModule_AddObject(m, "EventHandlerRef", (PyObject *)&EventHandlerRef_Type);
2191 /* Backward-compatible name */
2192 Py_INCREF(&EventHandlerRef_Type);
2193 PyModule_AddObject(m, "EventHandlerRefType", (PyObject *)&EventHandlerRef_Type);
2194 EventHandlerCallRef_Type.ob_type = &PyType_Type;
2195 if (PyType_Ready(&EventHandlerCallRef_Type) < 0) return;
2196 Py_INCREF(&EventHandlerCallRef_Type);
2197 PyModule_AddObject(m, "EventHandlerCallRef", (PyObject *)&EventHandlerCallRef_Type);
2198 /* Backward-compatible name */
2199 Py_INCREF(&EventHandlerCallRef_Type);
2200 PyModule_AddObject(m, "EventHandlerCallRefType", (PyObject *)&EventHandlerCallRef_Type);
2201 EventTargetRef_Type.ob_type = &PyType_Type;
2202 if (PyType_Ready(&EventTargetRef_Type) < 0) return;
2203 Py_INCREF(&EventTargetRef_Type);
2204 PyModule_AddObject(m, "EventTargetRef", (PyObject *)&EventTargetRef_Type);
2205 /* Backward-compatible name */
2206 Py_INCREF(&EventTargetRef_Type);
2207 PyModule_AddObject(m, "EventTargetRefType", (PyObject *)&EventTargetRef_Type);
2208 EventHotKeyRef_Type.ob_type = &PyType_Type;
2209 if (PyType_Ready(&EventHotKeyRef_Type) < 0) return;
2210 Py_INCREF(&EventHotKeyRef_Type);
2211 PyModule_AddObject(m, "EventHotKeyRef", (PyObject *)&EventHotKeyRef_Type);
2212 /* Backward-compatible name */
2213 Py_INCREF(&EventHotKeyRef_Type);
2214 PyModule_AddObject(m, "EventHotKeyRefType", (PyObject *)&EventHotKeyRef_Type);
2217 /* ===================== End module _CarbonEvt ====================== */