diff options
Diffstat (limited to 'Mac/Modules')
35 files changed, 10223 insertions, 0 deletions
diff --git a/Mac/Modules/ae/AEmodule.c b/Mac/Modules/ae/AEmodule.c new file mode 100644 index 0000000..544c4e2 --- /dev/null +++ b/Mac/Modules/ae/AEmodule.c @@ -0,0 +1,1257 @@ + +/* =========================== Module AE ============================ */ + +#include "Python.h" + + + +#define SystemSevenOrLater 1 + +#include "macglue.h" +#include <Memory.h> +#include <Dialogs.h> +#include <Menus.h> +#include <Controls.h> + +extern PyObject *ResObj_New(Handle); +extern int ResObj_Convert(PyObject *, Handle *); + +extern PyObject *WinObj_New(WindowPtr); +extern int WinObj_Convert(PyObject *, WindowPtr *); + +extern PyObject *DlgObj_New(DialogPtr); +extern int DlgObj_Convert(PyObject *, DialogPtr *); +extern PyTypeObject Dialog_Type; +#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type) + +extern PyObject *MenuObj_New(MenuHandle); +extern int MenuObj_Convert(PyObject *, MenuHandle *); + +extern PyObject *CtlObj_New(ControlHandle); +extern int CtlObj_Convert(PyObject *, ControlHandle *); + +#include <AppleEvents.h> + +#ifdef THINK_C +#define AEFilterProcPtr EventFilterProcPtr +#define AEEventHandlerProcPtr EventHandlerProcPtr +#endif + +static pascal OSErr GenericEventHandler(); /* Forward */ + +static pascal Boolean AEIdleProc(EventRecord *theEvent, long *sleepTime, RgnHandle *mouseRgn) +{ + (void) PyMac_Idle(); + return 0; +} + +static PyObject *AE_Error; + +/* ----------------------- Object type AEDesc ----------------------- */ + +staticforward PyTypeObject AEDesc_Type; + +#define AEDesc_Check(x) ((x)->ob_type == &AEDesc_Type) + +typedef struct AEDescObject { + PyObject_HEAD + AEDesc ob_itself; +} AEDescObject; + +static PyObject *AEDesc_New(itself) + const AEDesc *itself; +{ + AEDescObject *it; + it = PyObject_NEW(AEDescObject, &AEDesc_Type); + if (it == NULL) return NULL; + it->ob_itself = *itself; + return (PyObject *)it; +} +static AEDesc_Convert(v, p_itself) + PyObject *v; + AEDesc *p_itself; +{ + if (!AEDesc_Check(v)) + { + PyErr_SetString(PyExc_TypeError, "AEDesc required"); + return 0; + } + *p_itself = ((AEDescObject *)v)->ob_itself; + return 1; +} + +static void AEDesc_dealloc(self) + AEDescObject *self; +{ + AEDisposeDesc(&self->ob_itself); + PyMem_DEL(self); +} + +static PyObject *AEDesc_AECoerceDesc(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + DescType toType; + AEDesc result; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetOSType, &toType)) + return NULL; + _err = AECoerceDesc(&_self->ob_itself, + toType, + &result); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&", + AEDesc_New, &result); + return _res; +} + +static PyObject *AEDesc_AEDuplicateDesc(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AEDesc result; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _err = AEDuplicateDesc(&_self->ob_itself, + &result); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&", + AEDesc_New, &result); + return _res; +} + +static PyObject *AEDesc_AECountItems(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + long theCount; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _err = AECountItems(&_self->ob_itself, + &theCount); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("l", + theCount); + return _res; +} + +static PyObject *AEDesc_AEPutPtr(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + long index; + DescType typeCode; + char *dataPtr__in__; + long dataPtr__len__; + if (!PyArg_ParseTuple(_args, "lO&s#", + &index, + PyMac_GetOSType, &typeCode, + &dataPtr__in__, &dataPtr__len__)) + return NULL; + _err = AEPutPtr(&_self->ob_itself, + index, + typeCode, + dataPtr__in__, dataPtr__len__); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + dataPtr__error__: ; + return _res; +} + +static PyObject *AEDesc_AEPutDesc(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + long index; + AEDesc theAEDesc; + if (!PyArg_ParseTuple(_args, "lO&", + &index, + AEDesc_Convert, &theAEDesc)) + return NULL; + _err = AEPutDesc(&_self->ob_itself, + index, + &theAEDesc); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *AEDesc_AEGetNthPtr(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + long index; + DescType desiredType; + AEKeyword theAEKeyword; + DescType typeCode; + char *dataPtr__out__; + long dataPtr__len__; + if (!PyArg_ParseTuple(_args, "lO&l", + &index, + PyMac_GetOSType, &desiredType, + &dataPtr__len__)) + return NULL; + if ((dataPtr__out__ = malloc(dataPtr__len__)) == NULL) + { + PyErr_NoMemory(); + goto dataPtr__error__; + } + _err = AEGetNthPtr(&_self->ob_itself, + index, + desiredType, + &theAEKeyword, + &typeCode, + dataPtr__out__, dataPtr__len__, &dataPtr__len__); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&O&s#", + PyMac_BuildOSType, theAEKeyword, + PyMac_BuildOSType, typeCode, + dataPtr__out__, dataPtr__len__); + free(dataPtr__out__); + dataPtr__error__: ; + return _res; +} + +static PyObject *AEDesc_AEGetNthDesc(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + long index; + DescType desiredType; + AEKeyword theAEKeyword; + AEDesc result; + if (!PyArg_ParseTuple(_args, "lO&", + &index, + PyMac_GetOSType, &desiredType)) + return NULL; + _err = AEGetNthDesc(&_self->ob_itself, + index, + desiredType, + &theAEKeyword, + &result); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&O&", + PyMac_BuildOSType, theAEKeyword, + AEDesc_New, &result); + return _res; +} + +static PyObject *AEDesc_AESizeOfNthItem(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + long index; + DescType typeCode; + Size dataSize; + if (!PyArg_ParseTuple(_args, "l", + &index)) + return NULL; + _err = AESizeOfNthItem(&_self->ob_itself, + index, + &typeCode, + &dataSize); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&l", + PyMac_BuildOSType, typeCode, + dataSize); + return _res; +} + +static PyObject *AEDesc_AEDeleteItem(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + long index; + if (!PyArg_ParseTuple(_args, "l", + &index)) + return NULL; + _err = AEDeleteItem(&_self->ob_itself, + index); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *AEDesc_AEPutKeyPtr(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AEKeyword theAEKeyword; + DescType typeCode; + char *dataPtr__in__; + long dataPtr__len__; + if (!PyArg_ParseTuple(_args, "O&O&s#", + PyMac_GetOSType, &theAEKeyword, + PyMac_GetOSType, &typeCode, + &dataPtr__in__, &dataPtr__len__)) + return NULL; + _err = AEPutKeyPtr(&_self->ob_itself, + theAEKeyword, + typeCode, + dataPtr__in__, dataPtr__len__); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + dataPtr__error__: ; + return _res; +} + +static PyObject *AEDesc_AEPutKeyDesc(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AEKeyword theAEKeyword; + AEDesc theAEDesc; + if (!PyArg_ParseTuple(_args, "O&O&", + PyMac_GetOSType, &theAEKeyword, + AEDesc_Convert, &theAEDesc)) + return NULL; + _err = AEPutKeyDesc(&_self->ob_itself, + theAEKeyword, + &theAEDesc); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *AEDesc_AEGetKeyPtr(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AEKeyword theAEKeyword; + DescType desiredType; + DescType typeCode; + char *dataPtr__out__; + long dataPtr__len__; + if (!PyArg_ParseTuple(_args, "O&O&l", + PyMac_GetOSType, &theAEKeyword, + PyMac_GetOSType, &desiredType, + &dataPtr__len__)) + return NULL; + if ((dataPtr__out__ = malloc(dataPtr__len__)) == NULL) + { + PyErr_NoMemory(); + goto dataPtr__error__; + } + _err = AEGetKeyPtr(&_self->ob_itself, + theAEKeyword, + desiredType, + &typeCode, + dataPtr__out__, dataPtr__len__, &dataPtr__len__); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&s#", + PyMac_BuildOSType, typeCode, + dataPtr__out__, dataPtr__len__); + free(dataPtr__out__); + dataPtr__error__: ; + return _res; +} + +static PyObject *AEDesc_AEGetKeyDesc(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AEKeyword theAEKeyword; + DescType desiredType; + AEDesc result; + if (!PyArg_ParseTuple(_args, "O&O&", + PyMac_GetOSType, &theAEKeyword, + PyMac_GetOSType, &desiredType)) + return NULL; + _err = AEGetKeyDesc(&_self->ob_itself, + theAEKeyword, + desiredType, + &result); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&", + AEDesc_New, &result); + return _res; +} + +static PyObject *AEDesc_AESizeOfKeyDesc(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AEKeyword theAEKeyword; + DescType typeCode; + Size dataSize; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetOSType, &theAEKeyword)) + return NULL; + _err = AESizeOfKeyDesc(&_self->ob_itself, + theAEKeyword, + &typeCode, + &dataSize); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&l", + PyMac_BuildOSType, typeCode, + dataSize); + return _res; +} + +static PyObject *AEDesc_AEDeleteKeyDesc(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AEKeyword theAEKeyword; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetOSType, &theAEKeyword)) + return NULL; + _err = AEDeleteKeyDesc(&_self->ob_itself, + theAEKeyword); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *AEDesc_AEPutParamPtr(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AEKeyword theAEKeyword; + DescType typeCode; + char *dataPtr__in__; + long dataPtr__len__; + if (!PyArg_ParseTuple(_args, "O&O&s#", + PyMac_GetOSType, &theAEKeyword, + PyMac_GetOSType, &typeCode, + &dataPtr__in__, &dataPtr__len__)) + return NULL; + _err = AEPutParamPtr(&_self->ob_itself, + theAEKeyword, + typeCode, + dataPtr__in__, dataPtr__len__); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + dataPtr__error__: ; + return _res; +} + +static PyObject *AEDesc_AEPutParamDesc(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AEKeyword theAEKeyword; + AEDesc theAEDesc; + if (!PyArg_ParseTuple(_args, "O&O&", + PyMac_GetOSType, &theAEKeyword, + AEDesc_Convert, &theAEDesc)) + return NULL; + _err = AEPutParamDesc(&_self->ob_itself, + theAEKeyword, + &theAEDesc); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *AEDesc_AEGetParamPtr(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AEKeyword theAEKeyword; + DescType desiredType; + DescType typeCode; + char *dataPtr__out__; + long dataPtr__len__; + if (!PyArg_ParseTuple(_args, "O&O&l", + PyMac_GetOSType, &theAEKeyword, + PyMac_GetOSType, &desiredType, + &dataPtr__len__)) + return NULL; + if ((dataPtr__out__ = malloc(dataPtr__len__)) == NULL) + { + PyErr_NoMemory(); + goto dataPtr__error__; + } + _err = AEGetParamPtr(&_self->ob_itself, + theAEKeyword, + desiredType, + &typeCode, + dataPtr__out__, dataPtr__len__, &dataPtr__len__); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&s#", + PyMac_BuildOSType, typeCode, + dataPtr__out__, dataPtr__len__); + free(dataPtr__out__); + dataPtr__error__: ; + return _res; +} + +static PyObject *AEDesc_AEGetParamDesc(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AEKeyword theAEKeyword; + DescType desiredType; + AEDesc result; + if (!PyArg_ParseTuple(_args, "O&O&", + PyMac_GetOSType, &theAEKeyword, + PyMac_GetOSType, &desiredType)) + return NULL; + _err = AEGetParamDesc(&_self->ob_itself, + theAEKeyword, + desiredType, + &result); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&", + AEDesc_New, &result); + return _res; +} + +static PyObject *AEDesc_AESizeOfParam(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AEKeyword theAEKeyword; + DescType typeCode; + Size dataSize; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetOSType, &theAEKeyword)) + return NULL; + _err = AESizeOfParam(&_self->ob_itself, + theAEKeyword, + &typeCode, + &dataSize); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&l", + PyMac_BuildOSType, typeCode, + dataSize); + return _res; +} + +static PyObject *AEDesc_AEDeleteParam(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AEKeyword theAEKeyword; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetOSType, &theAEKeyword)) + return NULL; + _err = AEDeleteParam(&_self->ob_itself, + theAEKeyword); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *AEDesc_AEGetAttributePtr(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AEKeyword theAEKeyword; + DescType desiredType; + DescType typeCode; + char *dataPtr__out__; + long dataPtr__len__; + if (!PyArg_ParseTuple(_args, "O&O&l", + PyMac_GetOSType, &theAEKeyword, + PyMac_GetOSType, &desiredType, + &dataPtr__len__)) + return NULL; + if ((dataPtr__out__ = malloc(dataPtr__len__)) == NULL) + { + PyErr_NoMemory(); + goto dataPtr__error__; + } + _err = AEGetAttributePtr(&_self->ob_itself, + theAEKeyword, + desiredType, + &typeCode, + dataPtr__out__, dataPtr__len__, &dataPtr__len__); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&s#", + PyMac_BuildOSType, typeCode, + dataPtr__out__, dataPtr__len__); + free(dataPtr__out__); + dataPtr__error__: ; + return _res; +} + +static PyObject *AEDesc_AEGetAttributeDesc(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AEKeyword theAEKeyword; + DescType desiredType; + AEDesc result; + if (!PyArg_ParseTuple(_args, "O&O&", + PyMac_GetOSType, &theAEKeyword, + PyMac_GetOSType, &desiredType)) + return NULL; + _err = AEGetAttributeDesc(&_self->ob_itself, + theAEKeyword, + desiredType, + &result); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&", + AEDesc_New, &result); + return _res; +} + +static PyObject *AEDesc_AESizeOfAttribute(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AEKeyword theAEKeyword; + DescType typeCode; + Size dataSize; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetOSType, &theAEKeyword)) + return NULL; + _err = AESizeOfAttribute(&_self->ob_itself, + theAEKeyword, + &typeCode, + &dataSize); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&l", + PyMac_BuildOSType, typeCode, + dataSize); + return _res; +} + +static PyObject *AEDesc_AEPutAttributePtr(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AEKeyword theAEKeyword; + DescType typeCode; + char *dataPtr__in__; + long dataPtr__len__; + if (!PyArg_ParseTuple(_args, "O&O&s#", + PyMac_GetOSType, &theAEKeyword, + PyMac_GetOSType, &typeCode, + &dataPtr__in__, &dataPtr__len__)) + return NULL; + _err = AEPutAttributePtr(&_self->ob_itself, + theAEKeyword, + typeCode, + dataPtr__in__, dataPtr__len__); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + dataPtr__error__: ; + return _res; +} + +static PyObject *AEDesc_AEPutAttributeDesc(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AEKeyword theAEKeyword; + AEDesc theAEDesc; + if (!PyArg_ParseTuple(_args, "O&O&", + PyMac_GetOSType, &theAEKeyword, + AEDesc_Convert, &theAEDesc)) + return NULL; + _err = AEPutAttributeDesc(&_self->ob_itself, + theAEKeyword, + &theAEDesc); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *AEDesc_AESend(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AppleEvent reply; + AESendMode sendMode; + AESendPriority sendPriority; + long timeOutInTicks; + if (!PyArg_ParseTuple(_args, "lhl", + &sendMode, + &sendPriority, + &timeOutInTicks)) + return NULL; + _err = AESend(&_self->ob_itself, + &reply, + sendMode, + sendPriority, + timeOutInTicks, + AEIdleProc, + (AEFilterProcPtr)0); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&", + AEDesc_New, &reply); + return _res; +} + +static PyObject *AEDesc_AEResetTimer(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _err = AEResetTimer(&_self->ob_itself); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *AEDesc_AESuspendTheCurrentEvent(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _err = AESuspendTheCurrentEvent(&_self->ob_itself); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *AEDesc_AEResumeTheCurrentEvent(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AppleEvent reply; + AEEventHandlerProcPtr dispatcher__proc__ = GenericEventHandler; + PyObject *dispatcher; + if (!PyArg_ParseTuple(_args, "O&O", + AEDesc_Convert, &reply, + &dispatcher)) + return NULL; + _err = AEResumeTheCurrentEvent(&_self->ob_itself, + &reply, + dispatcher__proc__, (long)dispatcher); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *AEDesc_AESetTheCurrentEvent(_self, _args) + AEDescObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _err = AESetTheCurrentEvent(&_self->ob_itself); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyMethodDef AEDesc_methods[] = { + {"AECoerceDesc", (PyCFunction)AEDesc_AECoerceDesc, 1, + "(DescType toType) -> (AEDesc result)"}, + {"AEDuplicateDesc", (PyCFunction)AEDesc_AEDuplicateDesc, 1, + "() -> (AEDesc result)"}, + {"AECountItems", (PyCFunction)AEDesc_AECountItems, 1, + "() -> (long theCount)"}, + {"AEPutPtr", (PyCFunction)AEDesc_AEPutPtr, 1, + "(long index, DescType typeCode, Buffer dataPtr) -> None"}, + {"AEPutDesc", (PyCFunction)AEDesc_AEPutDesc, 1, + "(long index, AEDesc theAEDesc) -> None"}, + {"AEGetNthPtr", (PyCFunction)AEDesc_AEGetNthPtr, 1, + "(long index, DescType desiredType, Buffer dataPtr) -> (AEKeyword theAEKeyword, DescType typeCode, Buffer dataPtr)"}, + {"AEGetNthDesc", (PyCFunction)AEDesc_AEGetNthDesc, 1, + "(long index, DescType desiredType) -> (AEKeyword theAEKeyword, AEDesc result)"}, + {"AESizeOfNthItem", (PyCFunction)AEDesc_AESizeOfNthItem, 1, + "(long index) -> (DescType typeCode, Size dataSize)"}, + {"AEDeleteItem", (PyCFunction)AEDesc_AEDeleteItem, 1, + "(long index) -> None"}, + {"AEPutKeyPtr", (PyCFunction)AEDesc_AEPutKeyPtr, 1, + "(AEKeyword theAEKeyword, DescType typeCode, Buffer dataPtr) -> None"}, + {"AEPutKeyDesc", (PyCFunction)AEDesc_AEPutKeyDesc, 1, + "(AEKeyword theAEKeyword, AEDesc theAEDesc) -> None"}, + {"AEGetKeyPtr", (PyCFunction)AEDesc_AEGetKeyPtr, 1, + "(AEKeyword theAEKeyword, DescType desiredType, Buffer dataPtr) -> (DescType typeCode, Buffer dataPtr)"}, + {"AEGetKeyDesc", (PyCFunction)AEDesc_AEGetKeyDesc, 1, + "(AEKeyword theAEKeyword, DescType desiredType) -> (AEDesc result)"}, + {"AESizeOfKeyDesc", (PyCFunction)AEDesc_AESizeOfKeyDesc, 1, + "(AEKeyword theAEKeyword) -> (DescType typeCode, Size dataSize)"}, + {"AEDeleteKeyDesc", (PyCFunction)AEDesc_AEDeleteKeyDesc, 1, + "(AEKeyword theAEKeyword) -> None"}, + {"AEPutParamPtr", (PyCFunction)AEDesc_AEPutParamPtr, 1, + "(AEKeyword theAEKeyword, DescType typeCode, Buffer dataPtr) -> None"}, + {"AEPutParamDesc", (PyCFunction)AEDesc_AEPutParamDesc, 1, + "(AEKeyword theAEKeyword, AEDesc theAEDesc) -> None"}, + {"AEGetParamPtr", (PyCFunction)AEDesc_AEGetParamPtr, 1, + "(AEKeyword theAEKeyword, DescType desiredType, Buffer dataPtr) -> (DescType typeCode, Buffer dataPtr)"}, + {"AEGetParamDesc", (PyCFunction)AEDesc_AEGetParamDesc, 1, + "(AEKeyword theAEKeyword, DescType desiredType) -> (AEDesc result)"}, + {"AESizeOfParam", (PyCFunction)AEDesc_AESizeOfParam, 1, + "(AEKeyword theAEKeyword) -> (DescType typeCode, Size dataSize)"}, + {"AEDeleteParam", (PyCFunction)AEDesc_AEDeleteParam, 1, + "(AEKeyword theAEKeyword) -> None"}, + {"AEGetAttributePtr", (PyCFunction)AEDesc_AEGetAttributePtr, 1, + "(AEKeyword theAEKeyword, DescType desiredType, Buffer dataPtr) -> (DescType typeCode, Buffer dataPtr)"}, + {"AEGetAttributeDesc", (PyCFunction)AEDesc_AEGetAttributeDesc, 1, + "(AEKeyword theAEKeyword, DescType desiredType) -> (AEDesc result)"}, + {"AESizeOfAttribute", (PyCFunction)AEDesc_AESizeOfAttribute, 1, + "(AEKeyword theAEKeyword) -> (DescType typeCode, Size dataSize)"}, + {"AEPutAttributePtr", (PyCFunction)AEDesc_AEPutAttributePtr, 1, + "(AEKeyword theAEKeyword, DescType typeCode, Buffer dataPtr) -> None"}, + {"AEPutAttributeDesc", (PyCFunction)AEDesc_AEPutAttributeDesc, 1, + "(AEKeyword theAEKeyword, AEDesc theAEDesc) -> None"}, + {"AESend", (PyCFunction)AEDesc_AESend, 1, + "(AESendMode sendMode, AESendPriority sendPriority, long timeOutInTicks) -> (AppleEvent reply)"}, + {"AEResetTimer", (PyCFunction)AEDesc_AEResetTimer, 1, + "() -> None"}, + {"AESuspendTheCurrentEvent", (PyCFunction)AEDesc_AESuspendTheCurrentEvent, 1, + "() -> None"}, + {"AEResumeTheCurrentEvent", (PyCFunction)AEDesc_AEResumeTheCurrentEvent, 1, + "(AppleEvent reply, EventHandler dispatcher) -> None"}, + {"AESetTheCurrentEvent", (PyCFunction)AEDesc_AESetTheCurrentEvent, 1, + "() -> None"}, + {NULL, NULL, 0} +}; + +static PyMethodChain AEDesc_chain = { AEDesc_methods, NULL }; + +static PyObject *AEDesc_getattr(self, name) + AEDescObject *self; + char *name; +{ + + if (strcmp(name, "type") == 0) + return PyMac_BuildOSType(self->ob_itself.descriptorType); + if (strcmp(name, "data") == 0) { + PyObject *res; + char state; + state = HGetState(self->ob_itself.dataHandle); + HLock(self->ob_itself.dataHandle); + res = PyString_FromStringAndSize( + *self->ob_itself.dataHandle, + GetHandleSize(self->ob_itself.dataHandle)); + HUnlock(self->ob_itself.dataHandle); + HSetState(self->ob_itself.dataHandle, state); + return res; + } + if (strcmp(name, "__members__") == 0) + return Py_BuildValue("[ss]", "data", "type"); + + return Py_FindMethodInChain(&AEDesc_chain, (PyObject *)self, name); +} + +#define AEDesc_setattr NULL + +static PyTypeObject AEDesc_Type = { + PyObject_HEAD_INIT(&PyType_Type) + 0, /*ob_size*/ + "AEDesc", /*tp_name*/ + sizeof(AEDescObject), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + /* methods */ + (destructor) AEDesc_dealloc, /*tp_dealloc*/ + 0, /*tp_print*/ + (getattrfunc) AEDesc_getattr, /*tp_getattr*/ + (setattrfunc) AEDesc_setattr, /*tp_setattr*/ +}; + +/* --------------------- End object type AEDesc --------------------- */ + + +static PyObject *AE_AECreateDesc(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + DescType typeCode; + char *dataPtr__in__; + long dataPtr__len__; + AEDesc result; + if (!PyArg_ParseTuple(_args, "O&s#", + PyMac_GetOSType, &typeCode, + &dataPtr__in__, &dataPtr__len__)) + return NULL; + _err = AECreateDesc(typeCode, + dataPtr__in__, dataPtr__len__, + &result); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&", + AEDesc_New, &result); + dataPtr__error__: ; + return _res; +} + +static PyObject *AE_AECoercePtr(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + DescType typeCode; + char *dataPtr__in__; + long dataPtr__len__; + DescType toType; + AEDesc result; + if (!PyArg_ParseTuple(_args, "O&s#O&", + PyMac_GetOSType, &typeCode, + &dataPtr__in__, &dataPtr__len__, + PyMac_GetOSType, &toType)) + return NULL; + _err = AECoercePtr(typeCode, + dataPtr__in__, dataPtr__len__, + toType, + &result); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&", + AEDesc_New, &result); + dataPtr__error__: ; + return _res; +} + +static PyObject *AE_AECreateList(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + char *factoringPtr__in__; + long factoringPtr__len__; + Boolean isRecord; + AEDescList resultList; + if (!PyArg_ParseTuple(_args, "s#b", + &factoringPtr__in__, &factoringPtr__len__, + &isRecord)) + return NULL; + _err = AECreateList(factoringPtr__in__, factoringPtr__len__, + isRecord, + &resultList); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&", + AEDesc_New, &resultList); + factoringPtr__error__: ; + return _res; +} + +static PyObject *AE_AECreateAppleEvent(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AEEventClass theAEEventClass; + AEEventID theAEEventID; + AEAddressDesc target; + short returnID; + long transactionID; + AppleEvent result; + if (!PyArg_ParseTuple(_args, "O&O&O&hl", + PyMac_GetOSType, &theAEEventClass, + PyMac_GetOSType, &theAEEventID, + AEDesc_Convert, &target, + &returnID, + &transactionID)) + return NULL; + _err = AECreateAppleEvent(theAEEventClass, + theAEEventID, + &target, + returnID, + transactionID, + &result); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&", + AEDesc_New, &result); + return _res; +} + +static PyObject *AE_AEProcessAppleEvent(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + EventRecord theEventRecord; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetEventRecord, &theEventRecord)) + return NULL; + _err = AEProcessAppleEvent(&theEventRecord); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *AE_AEGetTheCurrentEvent(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AppleEvent theAppleEvent; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _err = AEGetTheCurrentEvent(&theAppleEvent); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&", + AEDesc_New, &theAppleEvent); + return _res; +} + +static PyObject *AE_AEGetInteractionAllowed(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AEInteractAllowed level; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _err = AEGetInteractionAllowed(&level); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("b", + level); + return _res; +} + +static PyObject *AE_AESetInteractionAllowed(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AEInteractAllowed level; + if (!PyArg_ParseTuple(_args, "b", + &level)) + return NULL; + _err = AESetInteractionAllowed(level); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *AE_AEInteractWithUser(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + long timeOutInTicks; + if (!PyArg_ParseTuple(_args, "l", + &timeOutInTicks)) + return NULL; + _err = AEInteractWithUser(timeOutInTicks, + (NMRecPtr)0, + AEIdleProc); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *AE_AEInstallEventHandler(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AEEventClass theAEEventClass; + AEEventID theAEEventID; + AEEventHandlerProcPtr handler__proc__ = GenericEventHandler; + PyObject *handler; + if (!PyArg_ParseTuple(_args, "O&O&O", + PyMac_GetOSType, &theAEEventClass, + PyMac_GetOSType, &theAEEventID, + &handler)) + return NULL; + _err = AEInstallEventHandler(theAEEventClass, + theAEEventID, + handler__proc__, (long)handler, + 0); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *AE_AERemoveEventHandler(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AEEventClass theAEEventClass; + AEEventID theAEEventID; + if (!PyArg_ParseTuple(_args, "O&O&", + PyMac_GetOSType, &theAEEventClass, + PyMac_GetOSType, &theAEEventID)) + return NULL; + _err = AERemoveEventHandler(theAEEventClass, + theAEEventID, + GenericEventHandler, + 0); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *AE_AEManagerInfo(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + AEKeyword keyWord; + long result; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetOSType, &keyWord)) + return NULL; + _err = AEManagerInfo(keyWord, + &result); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("l", + result); + return _res; +} + +static PyMethodDef AE_methods[] = { + {"AECreateDesc", (PyCFunction)AE_AECreateDesc, 1, + "(DescType typeCode, Buffer dataPtr) -> (AEDesc result)"}, + {"AECoercePtr", (PyCFunction)AE_AECoercePtr, 1, + "(DescType typeCode, Buffer dataPtr, DescType toType) -> (AEDesc result)"}, + {"AECreateList", (PyCFunction)AE_AECreateList, 1, + "(Buffer factoringPtr, Boolean isRecord) -> (AEDescList resultList)"}, + {"AECreateAppleEvent", (PyCFunction)AE_AECreateAppleEvent, 1, + "(AEEventClass theAEEventClass, AEEventID theAEEventID, AEAddressDesc target, short returnID, long transactionID) -> (AppleEvent result)"}, + {"AEProcessAppleEvent", (PyCFunction)AE_AEProcessAppleEvent, 1, + "(EventRecord theEventRecord) -> None"}, + {"AEGetTheCurrentEvent", (PyCFunction)AE_AEGetTheCurrentEvent, 1, + "() -> (AppleEvent theAppleEvent)"}, + {"AEGetInteractionAllowed", (PyCFunction)AE_AEGetInteractionAllowed, 1, + "() -> (AEInteractAllowed level)"}, + {"AESetInteractionAllowed", (PyCFunction)AE_AESetInteractionAllowed, 1, + "(AEInteractAllowed level) -> None"}, + {"AEInteractWithUser", (PyCFunction)AE_AEInteractWithUser, 1, + "(long timeOutInTicks) -> None"}, + {"AEInstallEventHandler", (PyCFunction)AE_AEInstallEventHandler, 1, + "(AEEventClass theAEEventClass, AEEventID theAEEventID, EventHandler handler) -> None"}, + {"AERemoveEventHandler", (PyCFunction)AE_AERemoveEventHandler, 1, + "(AEEventClass theAEEventClass, AEEventID theAEEventID) -> None"}, + {"AEManagerInfo", (PyCFunction)AE_AEManagerInfo, 1, + "(AEKeyword keyWord) -> (long result)"}, + {NULL, NULL, 0} +}; + + + +static pascal OSErr +GenericEventHandler(const AppleEvent *request, AppleEvent *reply, long refcon) +{ + PyObject *handler = (PyObject *)refcon; + AEDescObject *requestObject, *replyObject; + PyObject *args, *res; + if ((requestObject = (AEDescObject *)AEDesc_New(request)) == NULL) { + return -1; + } + if ((replyObject = (AEDescObject *)AEDesc_New(reply)) == NULL) { + Py_DECREF(requestObject); + return -1; + } + if ((args = Py_BuildValue("OO", requestObject, replyObject)) == NULL) { + Py_DECREF(requestObject); + Py_DECREF(replyObject); + return -1; + } + res = PyEval_CallObject(handler, args); + requestObject->ob_itself.descriptorType = 'null'; + requestObject->ob_itself.dataHandle = NULL; + replyObject->ob_itself.descriptorType = 'null'; + replyObject->ob_itself.dataHandle = NULL; + Py_DECREF(args); + if (res == NULL) + return -1; + Py_DECREF(res); + return noErr; +} + + +void initAE() +{ + PyObject *m; + PyObject *d; + + + + + m = Py_InitModule("AE", AE_methods); + d = PyModule_GetDict(m); + AE_Error = PyMac_GetOSErrException(); + if (AE_Error == NULL || + PyDict_SetItemString(d, "Error", AE_Error) != 0) + Py_FatalError("can't initialize AE.Error"); +} + +/* ========================= End module AE ========================== */ + diff --git a/Mac/Modules/ae/aegen.py b/Mac/Modules/ae/aegen.py new file mode 100644 index 0000000..ea9b3b6 --- /dev/null +++ b/Mac/Modules/ae/aegen.py @@ -0,0 +1,314 @@ +# Generated from 'D:Development:THINK C:Mac #includes:Apple #includes:AppleEvents.h' + +f = AEFunction(OSErr, 'AECreateDesc', + (DescType, 'typeCode', InMode), + (InBuffer, 'dataPtr', InMode), + (AEDesc, 'result', OutMode), +) +functions.append(f) + +f = AEFunction(OSErr, 'AECoercePtr', + (DescType, 'typeCode', InMode), + (InBuffer, 'dataPtr', InMode), + (DescType, 'toType', InMode), + (AEDesc, 'result', OutMode), +) +functions.append(f) + +f = AEMethod(OSErr, 'AECoerceDesc', + (AEDesc_ptr, 'theAEDesc', InMode), + (DescType, 'toType', InMode), + (AEDesc, 'result', OutMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AEDuplicateDesc', + (AEDesc_ptr, 'theAEDesc', InMode), + (AEDesc, 'result', OutMode), +) +aedescmethods.append(f) + +f = AEFunction(OSErr, 'AECreateList', + (InBuffer, 'factoringPtr', InMode), + (Boolean, 'isRecord', InMode), + (AEDescList, 'resultList', OutMode), +) +functions.append(f) + +f = AEMethod(OSErr, 'AECountItems', + (AEDescList_ptr, 'theAEDescList', InMode), + (long, 'theCount', OutMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AEPutPtr', + (AEDescList_ptr, 'theAEDescList', InMode), + (long, 'index', InMode), + (DescType, 'typeCode', InMode), + (InBuffer, 'dataPtr', InMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AEPutDesc', + (AEDescList_ptr, 'theAEDescList', InMode), + (long, 'index', InMode), + (AEDesc_ptr, 'theAEDesc', InMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AEGetNthPtr', + (AEDescList_ptr, 'theAEDescList', InMode), + (long, 'index', InMode), + (DescType, 'desiredType', InMode), + (AEKeyword, 'theAEKeyword', OutMode), + (DescType, 'typeCode', OutMode), + (VarVarOutBuffer, 'dataPtr', InOutMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AEGetNthDesc', + (AEDescList_ptr, 'theAEDescList', InMode), + (long, 'index', InMode), + (DescType, 'desiredType', InMode), + (AEKeyword, 'theAEKeyword', OutMode), + (AEDesc, 'result', OutMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AESizeOfNthItem', + (AEDescList_ptr, 'theAEDescList', InMode), + (long, 'index', InMode), + (DescType, 'typeCode', OutMode), + (Size, 'dataSize', OutMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AEDeleteItem', + (AEDescList_ptr, 'theAEDescList', InMode), + (long, 'index', InMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AEPutKeyPtr', + (AERecord_ptr, 'theAERecord', InMode), + (AEKeyword, 'theAEKeyword', InMode), + (DescType, 'typeCode', InMode), + (InBuffer, 'dataPtr', InMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AEPutKeyDesc', + (AERecord_ptr, 'theAERecord', InMode), + (AEKeyword, 'theAEKeyword', InMode), + (AEDesc_ptr, 'theAEDesc', InMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AEGetKeyPtr', + (AERecord_ptr, 'theAERecord', InMode), + (AEKeyword, 'theAEKeyword', InMode), + (DescType, 'desiredType', InMode), + (DescType, 'typeCode', OutMode), + (VarVarOutBuffer, 'dataPtr', InOutMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AEGetKeyDesc', + (AERecord_ptr, 'theAERecord', InMode), + (AEKeyword, 'theAEKeyword', InMode), + (DescType, 'desiredType', InMode), + (AEDesc, 'result', OutMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AESizeOfKeyDesc', + (AERecord_ptr, 'theAERecord', InMode), + (AEKeyword, 'theAEKeyword', InMode), + (DescType, 'typeCode', OutMode), + (Size, 'dataSize', OutMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AEDeleteKeyDesc', + (AERecord_ptr, 'theAERecord', InMode), + (AEKeyword, 'theAEKeyword', InMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AEPutParamPtr', + (AppleEvent_ptr, 'theAppleEvent', InMode), + (AEKeyword, 'theAEKeyword', InMode), + (DescType, 'typeCode', InMode), + (InBuffer, 'dataPtr', InMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AEPutParamDesc', + (AppleEvent_ptr, 'theAppleEvent', InMode), + (AEKeyword, 'theAEKeyword', InMode), + (AEDesc_ptr, 'theAEDesc', InMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AEGetParamPtr', + (AppleEvent_ptr, 'theAppleEvent', InMode), + (AEKeyword, 'theAEKeyword', InMode), + (DescType, 'desiredType', InMode), + (DescType, 'typeCode', OutMode), + (VarVarOutBuffer, 'dataPtr', InOutMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AEGetParamDesc', + (AppleEvent_ptr, 'theAppleEvent', InMode), + (AEKeyword, 'theAEKeyword', InMode), + (DescType, 'desiredType', InMode), + (AEDesc, 'result', OutMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AESizeOfParam', + (AppleEvent_ptr, 'theAppleEvent', InMode), + (AEKeyword, 'theAEKeyword', InMode), + (DescType, 'typeCode', OutMode), + (Size, 'dataSize', OutMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AEDeleteParam', + (AppleEvent_ptr, 'theAppleEvent', InMode), + (AEKeyword, 'theAEKeyword', InMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AEGetAttributePtr', + (AppleEvent_ptr, 'theAppleEvent', InMode), + (AEKeyword, 'theAEKeyword', InMode), + (DescType, 'desiredType', InMode), + (DescType, 'typeCode', OutMode), + (VarVarOutBuffer, 'dataPtr', InOutMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AEGetAttributeDesc', + (AppleEvent_ptr, 'theAppleEvent', InMode), + (AEKeyword, 'theAEKeyword', InMode), + (DescType, 'desiredType', InMode), + (AEDesc, 'result', OutMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AESizeOfAttribute', + (AppleEvent_ptr, 'theAppleEvent', InMode), + (AEKeyword, 'theAEKeyword', InMode), + (DescType, 'typeCode', OutMode), + (Size, 'dataSize', OutMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AEPutAttributePtr', + (AppleEvent_ptr, 'theAppleEvent', InMode), + (AEKeyword, 'theAEKeyword', InMode), + (DescType, 'typeCode', InMode), + (InBuffer, 'dataPtr', InMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AEPutAttributeDesc', + (AppleEvent_ptr, 'theAppleEvent', InMode), + (AEKeyword, 'theAEKeyword', InMode), + (AEDesc_ptr, 'theAEDesc', InMode), +) +aedescmethods.append(f) + +f = AEFunction(OSErr, 'AECreateAppleEvent', + (AEEventClass, 'theAEEventClass', InMode), + (AEEventID, 'theAEEventID', InMode), + (AEAddressDesc_ptr, 'target', InMode), + (short, 'returnID', InMode), + (long, 'transactionID', InMode), + (AppleEvent, 'result', OutMode), +) +functions.append(f) + +f = AEMethod(OSErr, 'AESend', + (AppleEvent_ptr, 'theAppleEvent', InMode), + (AppleEvent, 'reply', OutMode), + (AESendMode, 'sendMode', InMode), + (AESendPriority, 'sendPriority', InMode), + (long, 'timeOutInTicks', InMode), + (IdleProcPtr, 'idleProc', InMode), + (EventFilterProcPtr, 'filterProc', InMode), +) +aedescmethods.append(f) + +f = AEFunction(OSErr, 'AEProcessAppleEvent', + (EventRecord_ptr, 'theEventRecord', InMode), +) +functions.append(f) + +f = AEMethod(OSErr, 'AEResetTimer', + (AppleEvent_ptr, 'reply', InMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AESuspendTheCurrentEvent', + (AppleEvent_ptr, 'theAppleEvent', InMode), +) +aedescmethods.append(f) + +f = AEMethod(OSErr, 'AEResumeTheCurrentEvent', + (AppleEvent_ptr, 'theAppleEvent', InMode), + (AppleEvent_ptr, 'reply', InMode), + (EventHandler, 'dispatcher', InMode), +) +aedescmethods.append(f) + +f = AEFunction(OSErr, 'AEGetTheCurrentEvent', + (AppleEvent, 'theAppleEvent', OutMode), +) +functions.append(f) + +f = AEMethod(OSErr, 'AESetTheCurrentEvent', + (AppleEvent_ptr, 'theAppleEvent', InMode), +) +aedescmethods.append(f) + +f = AEFunction(OSErr, 'AEGetInteractionAllowed', + (AEInteractAllowed, 'level', OutMode), +) +functions.append(f) + +f = AEFunction(OSErr, 'AESetInteractionAllowed', + (AEInteractAllowed, 'level', InMode), +) +functions.append(f) + +f = AEFunction(OSErr, 'AEInteractWithUser', + (long, 'timeOutInTicks', InMode), + (NMRecPtr, 'nmReqPtr', InMode), + (IdleProcPtr, 'idleProc', InMode), +) +functions.append(f) + +f = AEFunction(OSErr, 'AEInstallEventHandler', + (AEEventClass, 'theAEEventClass', InMode), + (AEEventID, 'theAEEventID', InMode), + (EventHandler, 'handler', InMode), + (AlwaysFalse, 'isSysHandler', InMode), +) +functions.append(f) + +f = AEFunction(OSErr, 'AERemoveEventHandler', + (AEEventClass, 'theAEEventClass', InMode), + (AEEventID, 'theAEEventID', InMode), + (EventHandlerProcPtr, 'handler', InMode), + (AlwaysFalse, 'isSysHandler', InMode), +) +functions.append(f) + +f = AEFunction(OSErr, 'AEManagerInfo', + (AEKeyword, 'keyWord', InMode), + (long, 'result', OutMode), +) +functions.append(f) diff --git a/Mac/Modules/ae/aescan.py b/Mac/Modules/ae/aescan.py new file mode 100644 index 0000000..75003ec --- /dev/null +++ b/Mac/Modules/ae/aescan.py @@ -0,0 +1,71 @@ +# Scan AppleEvents.h header file, generate aegen.py and AppleEvents.py files. +# Then run aesupport to generate AEmodule.c. +0# (Should learn how to tell the compiler to compile it as well.) + +import sys +import os +import string +import regex +import regsub +import MacOS + +from scantools import Scanner + +def main(): + input = "AppleEvents.h" + output = "aegen.py" + defsoutput = "AppleEvents.py" + scanner = AppleEventsScanner(input, output, defsoutput) + scanner.scan() + scanner.close() + print "=== Done Scanning and Generating, now doing 'import aesupport' ===" + import aesupport + print "=== Done 'import aesupport'. It's up to you to compile AEmodule.c ===" + +class AppleEventsScanner(Scanner): + + def destination(self, type, name, arglist): + classname = "AEFunction" + listname = "functions" + if arglist: + t, n, m = arglist[0] + if t[-4:] == "_ptr" and m == "InMode" and \ + t[:-4] in ("AEDesc", "AEAddressDesc", "AEDescList", + "AERecord", "AppleEvent"): + classname = "AEMethod" + listname = "aedescmethods" + return classname, listname + + def makeblacklistnames(self): + return [ + "AEDisposeDesc", + "AEGetEventHandler", + ] + + def makeblacklisttypes(self): + return [ + "ProcPtr", + "AEArrayType", + ] + + def makerepairinstructions(self): + return [ + ([("Boolean", "isSysHandler", "InMode")], + [("AlwaysFalse", "*", "*")]), + + ([("void_ptr", "*", "InMode"), ("Size", "*", "InMode")], + [("InBuffer", "*", "*")]), + + ([("EventHandlerProcPtr", "*", "InMode"), ("long", "*", "InMode")], + [("EventHandler", "*", "*")]), + + ([("EventHandlerProcPtr", "*", "OutMode"), ("long", "*", "OutMode")], + [("EventHandler", "*", "*")]), + + ([("void", "*", "OutMode"), ("Size", "*", "InMode"), + ("Size", "*", "OutMode")], + [("VarVarOutBuffer", "*", "InOutMode")]), + ] + +if __name__ == "__main__": + main() diff --git a/Mac/Modules/ae/aesupport.py b/Mac/Modules/ae/aesupport.py new file mode 100644 index 0000000..49f072b --- /dev/null +++ b/Mac/Modules/ae/aesupport.py @@ -0,0 +1,168 @@ +# This script will generate the AppleEvents interface for Python. +# It uses the "bgen" package to generate C code. +# It execs the file aegen.py which contain the function definitions +# (aegen.py was generated by aescan.py, scanning the <AppleEvents.h> header file). + + +from macsupport import * + + +AEArrayType = Type("AEArrayType", "c") +AESendMode = Type("AESendMode", "l") +AESendPriority = Type("AESendPriority", "h") +AEInteractAllowed = Type("AEInteractAllowed", "b") + + +AEEventClass = OSTypeType('AEEventClass') +AEEventID = OSTypeType('AEEventID') +AEKeyword = OSTypeType('AEKeyword') +DescType = OSTypeType('DescType') + + +AEDesc = OpaqueType('AEDesc') +AEDesc_ptr = OpaqueType('AEDesc') + +AEAddressDesc = OpaqueType('AEAddressDesc', 'AEDesc') +AEAddressDesc_ptr = OpaqueType('AEAddressDesc', 'AEDesc') + +AEDescList = OpaqueType('AEDescList', 'AEDesc') +AEDescList_ptr = OpaqueType('AEDescList', 'AEDesc') + +AERecord = OpaqueType('AERecord', 'AEDesc') +AERecord_ptr = OpaqueType('AERecord', 'AEDesc') + +AppleEvent = OpaqueType('AppleEvent', 'AEDesc') +AppleEvent_ptr = OpaqueType('AppleEvent', 'AEDesc') + + +class EHType(Type): + def __init__(self, name = 'EventHandler', format = ''): + Type.__init__(self, name, format) + def declare(self, name): + Output("AEEventHandlerProcPtr %s__proc__ = GenericEventHandler;", name) + Output("PyObject *%s;", name) + def getargsFormat(self): + return "O" + def getargsArgs(self, name): + return "&%s" % name + def passInput(self, name): + return "%s__proc__, (long)%s" % (name, name) + def passOutput(self, name): + return "&%s__proc__, (long *)&%s" % (name, name) + def mkvalueFormat(self): + return "O" + def mkvalueArgs(self, name): + return name + +class EHNoRefConType(EHType): + def passInput(self, name): + return "GenericEventHandler" + +EventHandler = EHType() +EventHandlerNoRefCon = EHNoRefConType() + + +IdleProcPtr = FakeType("AEIdleProc") +EventFilterProcPtr = FakeType("(AEFilterProcPtr)0") +NMRecPtr = FakeType("(NMRecPtr)0") +EventHandlerProcPtr = FakeType("GenericEventHandler") +AlwaysFalse = FakeType("0") + + +AEFunction = OSErrFunctionGenerator +AEMethod = OSErrMethodGenerator + + +includestuff = includestuff + """ +#include <AppleEvents.h> + +#ifdef THINK_C +#define AEFilterProcPtr EventFilterProcPtr +#define AEEventHandlerProcPtr EventHandlerProcPtr +#endif + +static pascal OSErr GenericEventHandler(); /* Forward */ + +static pascal Boolean AEIdleProc(EventRecord *theEvent, long *sleepTime, RgnHandle *mouseRgn) +{ + return !PyMac_Idle(); +} +""" + +finalstuff = finalstuff + """ +static pascal OSErr +GenericEventHandler(const AppleEvent *request, AppleEvent *reply, long refcon) +{ + PyObject *handler = (PyObject *)refcon; + AEDescObject *requestObject, *replyObject; + PyObject *args, *res; + if ((requestObject = (AEDescObject *)AEDesc_New(request)) == NULL) { + return -1; + } + if ((replyObject = (AEDescObject *)AEDesc_New(reply)) == NULL) { + Py_DECREF(requestObject); + return -1; + } + if ((args = Py_BuildValue("OO", requestObject, replyObject)) == NULL) { + Py_DECREF(requestObject); + Py_DECREF(replyObject); + return -1; + } + res = PyEval_CallObject(handler, args); + requestObject->ob_itself.descriptorType = 'null'; + requestObject->ob_itself.dataHandle = NULL; + replyObject->ob_itself.descriptorType = 'null'; + replyObject->ob_itself.dataHandle = NULL; + Py_DECREF(args); + if (res == NULL) + return -1; + Py_DECREF(res); + return noErr; +} +""" + +module = MacModule('AE', 'AE', includestuff, finalstuff, initstuff) + +class AEDescDefiniton(ObjectDefinition): + + def __init__(self, name, prefix = None, itselftype = None): + ObjectDefinition.__init__(self, name, prefix or name, itselftype or name) + self.argref = "*" + + def outputFreeIt(self, name): + Output("AEDisposeDesc(&%s);", name) + + def outputGetattrHook(self): + Output(""" +if (strcmp(name, "type") == 0) + return PyMac_BuildOSType(self->ob_itself.descriptorType); +if (strcmp(name, "data") == 0) { + PyObject *res; + char state; + state = HGetState(self->ob_itself.dataHandle); + HLock(self->ob_itself.dataHandle); + res = PyString_FromStringAndSize( + *self->ob_itself.dataHandle, + GetHandleSize(self->ob_itself.dataHandle)); + HUnlock(self->ob_itself.dataHandle); + HSetState(self->ob_itself.dataHandle, state); + return res; +} +if (strcmp(name, "__members__") == 0) + return Py_BuildValue("[ss]", "data", "type"); +""") + + +aedescobject = AEDescDefiniton('AEDesc') +module.addobject(aedescobject) + +functions = [] +aedescmethods = [] + +execfile('aegen.py') + +for f in functions: module.add(f) +for f in aedescmethods: aedescobject.add(f) + +SetOutputFileName('AEmodule.c') +module.generate() diff --git a/Mac/Modules/ctl/Ctlmodule.c b/Mac/Modules/ctl/Ctlmodule.c new file mode 100644 index 0000000..fb1459a --- /dev/null +++ b/Mac/Modules/ctl/Ctlmodule.c @@ -0,0 +1,691 @@ + +/* =========================== Module Ctl =========================== */ + +#include "Python.h" + + + +#define SystemSevenOrLater 1 + +#include "macglue.h" +#include <Memory.h> +#include <Dialogs.h> +#include <Menus.h> +#include <Controls.h> + +extern PyObject *ResObj_New(Handle); +extern int ResObj_Convert(PyObject *, Handle *); + +extern PyObject *WinObj_New(WindowPtr); +extern int WinObj_Convert(PyObject *, WindowPtr *); + +extern PyObject *DlgObj_New(DialogPtr); +extern int DlgObj_Convert(PyObject *, DialogPtr *); +extern PyTypeObject Dialog_Type; +#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type) + +extern PyObject *MenuObj_New(MenuHandle); +extern int MenuObj_Convert(PyObject *, MenuHandle *); + +extern PyObject *CtlObj_New(ControlHandle); +extern int CtlObj_Convert(PyObject *, ControlHandle *); + +extern PyObject *WinObj_WhichWindow(WindowPtr); + +#include <Controls.h> + +#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */ + +extern PyObject *CtlObj_WhichControl(ControlHandle); /* Forward */ + +#ifdef THINK_C +#define ControlActionUPP ProcPtr +#endif + +static PyObject *Ctl_Error; + +/* ---------------------- Object type Control ----------------------- */ + +PyTypeObject Control_Type; + +#define CtlObj_Check(x) ((x)->ob_type == &Control_Type) + +typedef struct ControlObject { + PyObject_HEAD + ControlHandle ob_itself; +} ControlObject; + +PyObject *CtlObj_New(itself) + const ControlHandle itself; +{ + ControlObject *it; + if (itself == NULL) return PyMac_Error(resNotFound); + it = PyObject_NEW(ControlObject, &Control_Type); + if (it == NULL) return NULL; + it->ob_itself = itself; + SetCRefCon(itself, (long)it); + return (PyObject *)it; +} +CtlObj_Convert(v, p_itself) + PyObject *v; + ControlHandle *p_itself; +{ + if (!CtlObj_Check(v)) + { + PyErr_SetString(PyExc_TypeError, "Control required"); + return 0; + } + *p_itself = ((ControlObject *)v)->ob_itself; + return 1; +} + +static void CtlObj_dealloc(self) + ControlObject *self; +{ + /* Cleanup of self->ob_itself goes here */ + PyMem_DEL(self); +} + +static PyObject *CtlObj_SetCTitle(_self, _args) + ControlObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Str255 title; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetStr255, title)) + return NULL; + SetCTitle(_self->ob_itself, + title); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *CtlObj_GetCTitle(_self, _args) + ControlObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Str255 title; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetStr255, title)) + return NULL; + GetCTitle(_self->ob_itself, + title); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *CtlObj_DisposeControl(_self, _args) + ControlObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + DisposeControl(_self->ob_itself); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *CtlObj_HideControl(_self, _args) + ControlObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + HideControl(_self->ob_itself); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *CtlObj_ShowControl(_self, _args) + ControlObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + ShowControl(_self->ob_itself); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *CtlObj_Draw1Control(_self, _args) + ControlObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + Draw1Control(_self->ob_itself); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *CtlObj_HiliteControl(_self, _args) + ControlObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short hiliteState; + if (!PyArg_ParseTuple(_args, "h", + &hiliteState)) + return NULL; + HiliteControl(_self->ob_itself, + hiliteState); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *CtlObj_MoveControl(_self, _args) + ControlObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short h; + short v; + if (!PyArg_ParseTuple(_args, "hh", + &h, + &v)) + return NULL; + MoveControl(_self->ob_itself, + h, + v); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *CtlObj_SizeControl(_self, _args) + ControlObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short w; + short h; + if (!PyArg_ParseTuple(_args, "hh", + &w, + &h)) + return NULL; + SizeControl(_self->ob_itself, + w, + h); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *CtlObj_SetCtlValue(_self, _args) + ControlObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short theValue; + if (!PyArg_ParseTuple(_args, "h", + &theValue)) + return NULL; + SetCtlValue(_self->ob_itself, + theValue); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *CtlObj_GetCtlValue(_self, _args) + ControlObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = GetCtlValue(_self->ob_itself); + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *CtlObj_SetCtlMin(_self, _args) + ControlObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short minValue; + if (!PyArg_ParseTuple(_args, "h", + &minValue)) + return NULL; + SetCtlMin(_self->ob_itself, + minValue); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *CtlObj_GetCtlMin(_self, _args) + ControlObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = GetCtlMin(_self->ob_itself); + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *CtlObj_SetCtlMax(_self, _args) + ControlObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short maxValue; + if (!PyArg_ParseTuple(_args, "h", + &maxValue)) + return NULL; + SetCtlMax(_self->ob_itself, + maxValue); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *CtlObj_GetCtlMax(_self, _args) + ControlObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = GetCtlMax(_self->ob_itself); + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *CtlObj_SetCRefCon(_self, _args) + ControlObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + long data; + if (!PyArg_ParseTuple(_args, "l", + &data)) + return NULL; + SetCRefCon(_self->ob_itself, + data); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *CtlObj_GetCRefCon(_self, _args) + ControlObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + long _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = GetCRefCon(_self->ob_itself); + _res = Py_BuildValue("l", + _rv); + return _res; +} + +static PyObject *CtlObj_DragControl(_self, _args) + ControlObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Point startPt; + Rect limitRect; + Rect slopRect; + short axis; + if (!PyArg_ParseTuple(_args, "O&O&O&h", + PyMac_GetPoint, &startPt, + PyMac_GetRect, &limitRect, + PyMac_GetRect, &slopRect, + &axis)) + return NULL; + DragControl(_self->ob_itself, + startPt, + &limitRect, + &slopRect, + axis); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *CtlObj_TestControl(_self, _args) + ControlObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + Point thePt; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetPoint, &thePt)) + return NULL; + _rv = TestControl(_self->ob_itself, + thePt); + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *CtlObj_TrackControl(_self, _args) + ControlObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + Point thePoint; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetPoint, &thePoint)) + return NULL; + _rv = TrackControl(_self->ob_itself, + thePoint, + (ControlActionUPP)0); + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *CtlObj_GetCVariant(_self, _args) + ControlObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = GetCVariant(_self->ob_itself); + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyMethodDef CtlObj_methods[] = { + {"SetCTitle", (PyCFunction)CtlObj_SetCTitle, 1, + "(Str255 title) -> None"}, + {"GetCTitle", (PyCFunction)CtlObj_GetCTitle, 1, + "(Str255 title) -> None"}, + {"DisposeControl", (PyCFunction)CtlObj_DisposeControl, 1, + "() -> None"}, + {"HideControl", (PyCFunction)CtlObj_HideControl, 1, + "() -> None"}, + {"ShowControl", (PyCFunction)CtlObj_ShowControl, 1, + "() -> None"}, + {"Draw1Control", (PyCFunction)CtlObj_Draw1Control, 1, + "() -> None"}, + {"HiliteControl", (PyCFunction)CtlObj_HiliteControl, 1, + "(short hiliteState) -> None"}, + {"MoveControl", (PyCFunction)CtlObj_MoveControl, 1, + "(short h, short v) -> None"}, + {"SizeControl", (PyCFunction)CtlObj_SizeControl, 1, + "(short w, short h) -> None"}, + {"SetCtlValue", (PyCFunction)CtlObj_SetCtlValue, 1, + "(short theValue) -> None"}, + {"GetCtlValue", (PyCFunction)CtlObj_GetCtlValue, 1, + "() -> (short _rv)"}, + {"SetCtlMin", (PyCFunction)CtlObj_SetCtlMin, 1, + "(short minValue) -> None"}, + {"GetCtlMin", (PyCFunction)CtlObj_GetCtlMin, 1, + "() -> (short _rv)"}, + {"SetCtlMax", (PyCFunction)CtlObj_SetCtlMax, 1, + "(short maxValue) -> None"}, + {"GetCtlMax", (PyCFunction)CtlObj_GetCtlMax, 1, + "() -> (short _rv)"}, + {"SetCRefCon", (PyCFunction)CtlObj_SetCRefCon, 1, + "(long data) -> None"}, + {"GetCRefCon", (PyCFunction)CtlObj_GetCRefCon, 1, + "() -> (long _rv)"}, + {"DragControl", (PyCFunction)CtlObj_DragControl, 1, + "(Point startPt, Rect limitRect, Rect slopRect, short axis) -> None"}, + {"TestControl", (PyCFunction)CtlObj_TestControl, 1, + "(Point thePt) -> (short _rv)"}, + {"TrackControl", (PyCFunction)CtlObj_TrackControl, 1, + "(Point thePoint) -> (short _rv)"}, + {"GetCVariant", (PyCFunction)CtlObj_GetCVariant, 1, + "() -> (short _rv)"}, + {NULL, NULL, 0} +}; + +PyMethodChain CtlObj_chain = { CtlObj_methods, NULL }; + +static PyObject *CtlObj_getattr(self, name) + ControlObject *self; + char *name; +{ + return Py_FindMethodInChain(&CtlObj_chain, (PyObject *)self, name); +} + +#define CtlObj_setattr NULL + +PyTypeObject Control_Type = { + PyObject_HEAD_INIT(&PyType_Type) + 0, /*ob_size*/ + "Control", /*tp_name*/ + sizeof(ControlObject), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + /* methods */ + (destructor) CtlObj_dealloc, /*tp_dealloc*/ + 0, /*tp_print*/ + (getattrfunc) CtlObj_getattr, /*tp_getattr*/ + (setattrfunc) CtlObj_setattr, /*tp_setattr*/ +}; + +/* -------------------- End object type Control --------------------- */ + + +static PyObject *Ctl_NewControl(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + ControlHandle _rv; + WindowPtr theWindow; + Rect boundsRect; + Str255 title; + Boolean visible; + short value; + short min; + short max; + short procID; + long refCon; + if (!PyArg_ParseTuple(_args, "O&O&O&bhhhhl", + WinObj_Convert, &theWindow, + PyMac_GetRect, &boundsRect, + PyMac_GetStr255, title, + &visible, + &value, + &min, + &max, + &procID, + &refCon)) + return NULL; + _rv = NewControl(theWindow, + &boundsRect, + title, + visible, + value, + min, + max, + procID, + refCon); + _res = Py_BuildValue("O&", + CtlObj_New, _rv); + return _res; +} + +static PyObject *Ctl_GetNewControl(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + ControlHandle _rv; + short controlID; + WindowPtr owner; + if (!PyArg_ParseTuple(_args, "hO&", + &controlID, + WinObj_Convert, &owner)) + return NULL; + _rv = GetNewControl(controlID, + owner); + _res = Py_BuildValue("O&", + CtlObj_New, _rv); + return _res; +} + +static PyObject *Ctl_KillControls(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + WindowPtr theWindow; + if (!PyArg_ParseTuple(_args, "O&", + WinObj_Convert, &theWindow)) + return NULL; + KillControls(theWindow); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Ctl_DrawControls(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + WindowPtr theWindow; + if (!PyArg_ParseTuple(_args, "O&", + WinObj_Convert, &theWindow)) + return NULL; + DrawControls(theWindow); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Ctl_UpdtControl(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + WindowPtr theWindow; + if (!PyArg_ParseTuple(_args, "O&", + WinObj_Convert, &theWindow)) + return NULL; + UpdtControl(theWindow, + theWindow->visRgn); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Ctl_UpdateControls(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + WindowPtr theWindow; + if (!PyArg_ParseTuple(_args, "O&", + WinObj_Convert, &theWindow)) + return NULL; + UpdateControls(theWindow, + theWindow->visRgn); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Ctl_FindControl(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + Point thePoint; + WindowPtr theWindow; + ControlHandle theControl; + if (!PyArg_ParseTuple(_args, "O&O&", + PyMac_GetPoint, &thePoint, + WinObj_Convert, &theWindow)) + return NULL; + _rv = FindControl(thePoint, + theWindow, + &theControl); + _res = Py_BuildValue("hO&", + _rv, + CtlObj_WhichControl, theControl); + return _res; +} + +static PyMethodDef Ctl_methods[] = { + {"NewControl", (PyCFunction)Ctl_NewControl, 1, + "(WindowPtr theWindow, Rect boundsRect, Str255 title, Boolean visible, short value, short min, short max, short procID, long refCon) -> (ControlHandle _rv)"}, + {"GetNewControl", (PyCFunction)Ctl_GetNewControl, 1, + "(short controlID, WindowPtr owner) -> (ControlHandle _rv)"}, + {"KillControls", (PyCFunction)Ctl_KillControls, 1, + "(WindowPtr theWindow) -> None"}, + {"DrawControls", (PyCFunction)Ctl_DrawControls, 1, + "(WindowPtr theWindow) -> None"}, + {"UpdtControl", (PyCFunction)Ctl_UpdtControl, 1, + "(WindowPtr theWindow) -> None"}, + {"UpdateControls", (PyCFunction)Ctl_UpdateControls, 1, + "(WindowPtr theWindow) -> None"}, + {"FindControl", (PyCFunction)Ctl_FindControl, 1, + "(Point thePoint, WindowPtr theWindow) -> (short _rv, ControlHandle theControl)"}, + {NULL, NULL, 0} +}; + + + +PyObject * +CtlObj_WhichControl(ControlHandle c) +{ + PyObject *it; + + /* XXX What if we find a control belonging to some other package? */ + if (c == NULL) + it = NULL; + else + it = (PyObject *) GetCRefCon(c); + if (it == NULL || ((ControlObject *)it)->ob_itself != c) + it = Py_None; + Py_INCREF(it); + return it; +} + + +void initCtl() +{ + PyObject *m; + PyObject *d; + + + + + m = Py_InitModule("Ctl", Ctl_methods); + d = PyModule_GetDict(m); + Ctl_Error = PyMac_GetOSErrException(); + if (Ctl_Error == NULL || + PyDict_SetItemString(d, "Error", Ctl_Error) != 0) + Py_FatalError("can't initialize Ctl.Error"); +} + +/* ========================= End module Ctl ========================= */ + diff --git a/Mac/Modules/ctl/ctlgen.py b/Mac/Modules/ctl/ctlgen.py new file mode 100644 index 0000000..fcbf0f4 --- /dev/null +++ b/Mac/Modules/ctl/ctlgen.py @@ -0,0 +1,172 @@ +# Generated from 'D:Development:THINK C:Mac #includes:Apple #includes:Controls.h' + +f = Function(ControlHandle, 'NewControl', + (WindowPtr, 'theWindow', InMode), + (Rect_ptr, 'boundsRect', InMode), + (ConstStr255Param, 'title', InMode), + (Boolean, 'visible', InMode), + (short, 'value', InMode), + (short, 'min', InMode), + (short, 'max', InMode), + (short, 'procID', InMode), + (long, 'refCon', InMode), +) +functions.append(f) + +f = Method(void, 'SetCTitle', + (ControlHandle, 'theControl', InMode), + (ConstStr255Param, 'title', InMode), +) +methods.append(f) + +f = Method(void, 'GetCTitle', + (ControlHandle, 'theControl', InMode), + (Str255, 'title', InMode), +) +methods.append(f) + +f = Function(ControlHandle, 'GetNewControl', + (short, 'controlID', InMode), + (WindowPtr, 'owner', InMode), +) +functions.append(f) + +f = Method(void, 'DisposeControl', + (ControlHandle, 'theControl', InMode), +) +methods.append(f) + +f = Function(void, 'KillControls', + (WindowPtr, 'theWindow', InMode), +) +functions.append(f) + +f = Method(void, 'HideControl', + (ControlHandle, 'theControl', InMode), +) +methods.append(f) + +f = Method(void, 'ShowControl', + (ControlHandle, 'theControl', InMode), +) +methods.append(f) + +f = Function(void, 'DrawControls', + (WindowPtr, 'theWindow', InMode), +) +functions.append(f) + +f = Method(void, 'Draw1Control', + (ControlHandle, 'theControl', InMode), +) +methods.append(f) + +f = Method(void, 'HiliteControl', + (ControlHandle, 'theControl', InMode), + (short, 'hiliteState', InMode), +) +methods.append(f) + +f = Function(void, 'UpdtControl', + (WindowPtr, 'theWindow', InMode), + (RgnHandle, 'updateRgn', InMode), +) +functions.append(f) + +f = Function(void, 'UpdateControls', + (WindowPtr, 'theWindow', InMode), + (RgnHandle, 'updateRgn', InMode), +) +functions.append(f) + +f = Method(void, 'MoveControl', + (ControlHandle, 'theControl', InMode), + (short, 'h', InMode), + (short, 'v', InMode), +) +methods.append(f) + +f = Method(void, 'SizeControl', + (ControlHandle, 'theControl', InMode), + (short, 'w', InMode), + (short, 'h', InMode), +) +methods.append(f) + +f = Method(void, 'SetCtlValue', + (ControlHandle, 'theControl', InMode), + (short, 'theValue', InMode), +) +methods.append(f) + +f = Method(short, 'GetCtlValue', + (ControlHandle, 'theControl', InMode), +) +methods.append(f) + +f = Method(void, 'SetCtlMin', + (ControlHandle, 'theControl', InMode), + (short, 'minValue', InMode), +) +methods.append(f) + +f = Method(short, 'GetCtlMin', + (ControlHandle, 'theControl', InMode), +) +methods.append(f) + +f = Method(void, 'SetCtlMax', + (ControlHandle, 'theControl', InMode), + (short, 'maxValue', InMode), +) +methods.append(f) + +f = Method(short, 'GetCtlMax', + (ControlHandle, 'theControl', InMode), +) +methods.append(f) + +f = Method(void, 'SetCRefCon', + (ControlHandle, 'theControl', InMode), + (long, 'data', InMode), +) +methods.append(f) + +f = Method(long, 'GetCRefCon', + (ControlHandle, 'theControl', InMode), +) +methods.append(f) + +f = Method(void, 'DragControl', + (ControlHandle, 'theControl', InMode), + (Point, 'startPt', InMode), + (Rect_ptr, 'limitRect', InMode), + (Rect_ptr, 'slopRect', InMode), + (short, 'axis', InMode), +) +methods.append(f) + +f = Method(short, 'TestControl', + (ControlHandle, 'theControl', InMode), + (Point, 'thePt', InMode), +) +methods.append(f) + +f = Method(short, 'TrackControl', + (ControlHandle, 'theControl', InMode), + (Point, 'thePoint', InMode), + (FakeType('(ControlActionUPP)0'), 'actionProc', InMode), +) +methods.append(f) + +f = Function(short, 'FindControl', + (Point, 'thePoint', InMode), + (WindowPtr, 'theWindow', InMode), + (ExistingControlHandle, 'theControl', OutMode), +) +functions.append(f) + +f = Method(short, 'GetCVariant', + (ControlHandle, 'theControl', InMode), +) +methods.append(f) diff --git a/Mac/Modules/ctl/ctlscan.py b/Mac/Modules/ctl/ctlscan.py new file mode 100644 index 0000000..f104e8d --- /dev/null +++ b/Mac/Modules/ctl/ctlscan.py @@ -0,0 +1,60 @@ +# Scan <Controls.h>, generating ctlgen.py. + +from scantools import Scanner + +def main(): + input = "Controls.h" + output = "ctlgen.py" + defsoutput = "Controls.py" + scanner = MyScanner(input, output, defsoutput) + scanner.scan() + scanner.close() + print "=== Done scanning and generating, now doing 'import ctlsupport' ===" + import ctlsupport + print "=== Done. It's up to you to compile Ctlmodule.c ===" + +class MyScanner(Scanner): + + def destination(self, type, name, arglist): + classname = "Function" + listname = "functions" + if arglist: + t, n, m = arglist[0] + if t == "ControlHandle" and m == "InMode": + classname = "Method" + listname = "methods" + return classname, listname + + def makeblacklistnames(self): + return [ + 'DisposeControl' # Implied by deletion of control object + 'KillControls', # Implied by close of dialog + 'SetCtlAction', + ] + + def makeblacklisttypes(self): + return [ + 'ProcPtr', + 'CCTabHandle', + 'AuxCtlHandle', + ] + + def makerepairinstructions(self): + return [ + ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")], + [("InBuffer", "*", "*")]), + + ([("void", "*", "OutMode"), ("long", "*", "InMode"), + ("long", "*", "OutMode")], + [("VarVarOutBuffer", "*", "InOutMode")]), + + # For TrackControl + ([("ProcPtr", "actionProc", "InMode")], + [("FakeType('(ControlActionUPP)0')", "*", "*")]), + + ([("ControlHandle", "*", "OutMode")], + [("ExistingControlHandle", "*", "*")]), + ] + +if __name__ == "__main__": + main() diff --git a/Mac/Modules/ctl/ctlsupport.py b/Mac/Modules/ctl/ctlsupport.py new file mode 100644 index 0000000..97b1f33 --- /dev/null +++ b/Mac/Modules/ctl/ctlsupport.py @@ -0,0 +1,86 @@ +# This script generates a Python interface for an Apple Macintosh Manager. +# It uses the "bgen" package to generate C code. +# The function specifications are generated by scanning the mamager's header file, +# using the "scantools" package (customized for this particular manager). + +import string + +# Declarations that change for each manager +MACHEADERFILE = 'Controls.h' # The Apple header file +MODNAME = 'Ctl' # The name of the module +OBJECTNAME = 'Control' # The basic name of the objects used here + +# The following is *usually* unchanged but may still require tuning +MODPREFIX = MODNAME # The prefix for module-wide routines +OBJECTTYPE = OBJECTNAME + 'Handle' # The C type used to represent them +OBJECTPREFIX = MODPREFIX + 'Obj' # The prefix for object methods +INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner +OUTPUTFILE = MODNAME + "module.c" # The file generated by this program + +from macsupport import * + +# Create the type objects + +ControlHandle = OpaqueByValueType(OBJECTTYPE, OBJECTPREFIX) +ExistingControlHandle = OpaqueByValueType(OBJECTTYPE, "CtlObj_WhichControl", "BUG") + +RgnHandle = FakeType("theWindow->visRgn") # XXX + +includestuff = includestuff + """ +#include <%s>""" % MACHEADERFILE + """ + +#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */ + +extern PyObject *CtlObj_WhichControl(ControlHandle); /* Forward */ + +#ifdef THINK_C +#define ControlActionUPP ProcPtr +#endif +""" + +finalstuff = finalstuff + """ +PyObject * +CtlObj_WhichControl(ControlHandle c) +{ + PyObject *it; + + /* XXX What if we find a control belonging to some other package? */ + if (c == NULL) + it = NULL; + else + it = (PyObject *) GetCRefCon(c); + if (it == NULL || ((ControlObject *)it)->ob_itself != c) + it = Py_None; + Py_INCREF(it); + return it; +} +""" + +class MyObjectDefinition(GlobalObjectDefinition): + def outputCheckNewArg(self): + Output("if (itself == NULL) return PyMac_Error(resNotFound);") + def outputInitStructMembers(self): + GlobalObjectDefinition.outputInitStructMembers(self) + Output("SetCRefCon(itself, (long)it);") + +# Create the generator groups and link them +module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff) +object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE) +module.addobject(object) + +# Create the generator classes used to populate the lists +Function = OSErrFunctionGenerator +Method = OSErrMethodGenerator + +# Create and populate the lists +functions = [] +methods = [] +execfile(INPUTFILE) + +# add the populated lists to the generator groups +for f in functions: module.add(f) +for f in methods: object.add(f) + +# generate output (open the output file as late as possible) +SetOutputFileName(OUTPUTFILE) +module.generate() diff --git a/Mac/Modules/dlg/Dlgmodule.c b/Mac/Modules/dlg/Dlgmodule.c new file mode 100644 index 0000000..b03f24f --- /dev/null +++ b/Mac/Modules/dlg/Dlgmodule.c @@ -0,0 +1,905 @@ + +/* =========================== Module Dlg =========================== */ + +#include "Python.h" + + + +#define SystemSevenOrLater 1 + +#include "macglue.h" +#include <Memory.h> +#include <Dialogs.h> +#include <Menus.h> +#include <Controls.h> + +extern PyObject *ResObj_New(Handle); +extern int ResObj_Convert(PyObject *, Handle *); + +extern PyObject *WinObj_New(WindowPtr); +extern int WinObj_Convert(PyObject *, WindowPtr *); + +extern PyObject *DlgObj_New(DialogPtr); +extern int DlgObj_Convert(PyObject *, DialogPtr *); +extern PyTypeObject Dialog_Type; +#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type) + +extern PyObject *MenuObj_New(MenuHandle); +extern int MenuObj_Convert(PyObject *, MenuHandle *); + +extern PyObject *CtlObj_New(ControlHandle); +extern int CtlObj_Convert(PyObject *, ControlHandle *); + +extern PyObject *WinObj_WhichWindow(WindowPtr); + +#include <Dialogs.h> + +#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */ + +/* XXX Shouldn't this be a stack? */ +static PyObject *Dlg_FilterProc_callback = NULL; + +static PyObject *DlgObj_New(DialogPtr); /* Forward */ + +static pascal Boolean Dlg_UnivFilterProc(DialogPtr dialog, + EventRecord *event, + short *itemHit) +{ + Boolean rv; + PyObject *args, *res; + PyObject *callback = Dlg_FilterProc_callback; + if (callback == NULL) + return 0; /* Default behavior */ + Dlg_FilterProc_callback = NULL; /* We'll restore it when call successful */ + args = Py_BuildValue("O&s#", DlgObj_New, dialog, event, sizeof(EventRecord)); + if (args == NULL) + res = NULL; + else { + res = PyEval_CallObject(callback, args); + Py_DECREF(args); + } + if (res == NULL) { + fprintf(stderr, "Exception in Dialog Filter\n"); + PyErr_Print(); + *itemHit = -1; /* Fake return item */ + return 1; /* We handled it */ + } + else { + Dlg_FilterProc_callback = callback; + if (PyInt_Check(res)) { + *itemHit = PyInt_AsLong(res); + rv = 1; + } + else + rv = PyObject_IsTrue(res); + } + Py_DECREF(res); + return rv; +} + +static ModalFilterProcPtr +Dlg_PassFilterProc(PyObject *callback) +{ + PyObject *tmp = Dlg_FilterProc_callback; + Dlg_FilterProc_callback = NULL; + if (callback == Py_None) { + Py_XDECREF(tmp); + return NULL; + } + Py_INCREF(callback); + Dlg_FilterProc_callback = callback; + Py_XDECREF(tmp); + return &Dlg_UnivFilterProc; +} + +extern PyMethodChain WinObj_chain; + +static PyObject *Dlg_Error; + +/* ----------------------- Object type Dialog ----------------------- */ + +PyTypeObject Dialog_Type; + +#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type) + +typedef struct DialogObject { + PyObject_HEAD + DialogPtr ob_itself; +} DialogObject; + +PyObject *DlgObj_New(itself) + const DialogPtr itself; +{ + DialogObject *it; + if (itself == NULL) return Py_None; + it = PyObject_NEW(DialogObject, &Dialog_Type); + if (it == NULL) return NULL; + it->ob_itself = itself; + SetWRefCon(itself, (long)it); + return (PyObject *)it; +} +DlgObj_Convert(v, p_itself) + PyObject *v; + DialogPtr *p_itself; +{ + if (v == Py_None) { *p_itself = NULL; return 1; } + if (PyInt_Check(v)) { *p_itself = (DialogPtr)PyInt_AsLong(v); + return 1; } + if (!DlgObj_Check(v)) + { + PyErr_SetString(PyExc_TypeError, "Dialog required"); + return 0; + } + *p_itself = ((DialogObject *)v)->ob_itself; + return 1; +} + +static void DlgObj_dealloc(self) + DialogObject *self; +{ + DisposeDialog(self->ob_itself); + PyMem_DEL(self); +} + +static PyObject *DlgObj_DrawDialog(_self, _args) + DialogObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + DrawDialog(_self->ob_itself); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *DlgObj_UpdtDialog(_self, _args) + DialogObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + UpdtDialog(_self->ob_itself, + _self->ob_itself->visRgn); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *DlgObj_UpdateDialog(_self, _args) + DialogObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + UpdateDialog(_self->ob_itself, + _self->ob_itself->visRgn); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *DlgObj_GetDItem(_self, _args) + DialogObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short itemNo; + short itemType; + Handle item; + Rect box; + if (!PyArg_ParseTuple(_args, "h", + &itemNo)) + return NULL; + GetDItem(_self->ob_itself, + itemNo, + &itemType, + &item, + &box); + _res = Py_BuildValue("hO&O&", + itemType, + ResObj_New, item, + PyMac_BuildRect, &box); + return _res; +} + +static PyObject *DlgObj_SetDItem(_self, _args) + DialogObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short itemNo; + short itemType; + Handle item; + Rect box; + if (!PyArg_ParseTuple(_args, "hhO&O&", + &itemNo, + &itemType, + ResObj_Convert, &item, + PyMac_GetRect, &box)) + return NULL; + SetDItem(_self->ob_itself, + itemNo, + itemType, + item, + &box); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *DlgObj_HideDItem(_self, _args) + DialogObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short itemNo; + if (!PyArg_ParseTuple(_args, "h", + &itemNo)) + return NULL; + HideDItem(_self->ob_itself, + itemNo); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *DlgObj_ShowDItem(_self, _args) + DialogObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short itemNo; + if (!PyArg_ParseTuple(_args, "h", + &itemNo)) + return NULL; + ShowDItem(_self->ob_itself, + itemNo); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *DlgObj_SelIText(_self, _args) + DialogObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short itemNo; + short strtSel; + short endSel; + if (!PyArg_ParseTuple(_args, "hhh", + &itemNo, + &strtSel, + &endSel)) + return NULL; + SelIText(_self->ob_itself, + itemNo, + strtSel, + endSel); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *DlgObj_FindDItem(_self, _args) + DialogObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + Point thePt; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetPoint, &thePt)) + return NULL; + _rv = FindDItem(_self->ob_itself, + thePt); + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *DlgObj_DlgCut(_self, _args) + DialogObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + DlgCut(_self->ob_itself); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *DlgObj_DlgPaste(_self, _args) + DialogObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + DlgPaste(_self->ob_itself); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *DlgObj_DlgCopy(_self, _args) + DialogObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + DlgCopy(_self->ob_itself); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *DlgObj_DlgDelete(_self, _args) + DialogObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + DlgDelete(_self->ob_itself); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *DlgObj_AppendDITL(_self, _args) + DialogObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Handle theHandle; + DITLMethod method; + if (!PyArg_ParseTuple(_args, "O&h", + ResObj_Convert, &theHandle, + &method)) + return NULL; + AppendDITL(_self->ob_itself, + theHandle, + method); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *DlgObj_CountDITL(_self, _args) + DialogObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = CountDITL(_self->ob_itself); + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *DlgObj_ShortenDITL(_self, _args) + DialogObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short numberItems; + if (!PyArg_ParseTuple(_args, "h", + &numberItems)) + return NULL; + ShortenDITL(_self->ob_itself, + numberItems); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyMethodDef DlgObj_methods[] = { + {"DrawDialog", (PyCFunction)DlgObj_DrawDialog, 1, + "() -> None"}, + {"UpdtDialog", (PyCFunction)DlgObj_UpdtDialog, 1, + "() -> None"}, + {"UpdateDialog", (PyCFunction)DlgObj_UpdateDialog, 1, + "() -> None"}, + {"GetDItem", (PyCFunction)DlgObj_GetDItem, 1, + "(short itemNo) -> (short itemType, Handle item, Rect box)"}, + {"SetDItem", (PyCFunction)DlgObj_SetDItem, 1, + "(short itemNo, short itemType, Handle item, Rect box) -> None"}, + {"HideDItem", (PyCFunction)DlgObj_HideDItem, 1, + "(short itemNo) -> None"}, + {"ShowDItem", (PyCFunction)DlgObj_ShowDItem, 1, + "(short itemNo) -> None"}, + {"SelIText", (PyCFunction)DlgObj_SelIText, 1, + "(short itemNo, short strtSel, short endSel) -> None"}, + {"FindDItem", (PyCFunction)DlgObj_FindDItem, 1, + "(Point thePt) -> (short _rv)"}, + {"DlgCut", (PyCFunction)DlgObj_DlgCut, 1, + "() -> None"}, + {"DlgPaste", (PyCFunction)DlgObj_DlgPaste, 1, + "() -> None"}, + {"DlgCopy", (PyCFunction)DlgObj_DlgCopy, 1, + "() -> None"}, + {"DlgDelete", (PyCFunction)DlgObj_DlgDelete, 1, + "() -> None"}, + {"AppendDITL", (PyCFunction)DlgObj_AppendDITL, 1, + "(Handle theHandle, DITLMethod method) -> None"}, + {"CountDITL", (PyCFunction)DlgObj_CountDITL, 1, + "() -> (short _rv)"}, + {"ShortenDITL", (PyCFunction)DlgObj_ShortenDITL, 1, + "(short numberItems) -> None"}, + {NULL, NULL, 0} +}; + +PyMethodChain DlgObj_chain = { DlgObj_methods, &WinObj_chain }; + +static PyObject *DlgObj_getattr(self, name) + DialogObject *self; + char *name; +{ + return Py_FindMethodInChain(&DlgObj_chain, (PyObject *)self, name); +} + +#define DlgObj_setattr NULL + +PyTypeObject Dialog_Type = { + PyObject_HEAD_INIT(&PyType_Type) + 0, /*ob_size*/ + "Dialog", /*tp_name*/ + sizeof(DialogObject), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + /* methods */ + (destructor) DlgObj_dealloc, /*tp_dealloc*/ + 0, /*tp_print*/ + (getattrfunc) DlgObj_getattr, /*tp_getattr*/ + (setattrfunc) DlgObj_setattr, /*tp_setattr*/ +}; + +/* --------------------- End object type Dialog --------------------- */ + + +static PyObject *Dlg_NewDialog(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + DialogPtr _rv; + Rect boundsRect; + Str255 title; + Boolean visible; + short procID; + WindowPtr behind; + Boolean goAwayFlag; + long refCon; + Handle itmLstHndl; + if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&", + PyMac_GetRect, &boundsRect, + PyMac_GetStr255, title, + &visible, + &procID, + WinObj_Convert, &behind, + &goAwayFlag, + &refCon, + ResObj_Convert, &itmLstHndl)) + return NULL; + _rv = NewDialog((void *)0, + &boundsRect, + title, + visible, + procID, + behind, + goAwayFlag, + refCon, + itmLstHndl); + _res = Py_BuildValue("O&", + DlgObj_New, _rv); + return _res; +} + +static PyObject *Dlg_GetNewDialog(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + DialogPtr _rv; + short dialogID; + WindowPtr behind; + if (!PyArg_ParseTuple(_args, "hO&", + &dialogID, + WinObj_Convert, &behind)) + return NULL; + _rv = GetNewDialog(dialogID, + (void *)0, + behind); + _res = Py_BuildValue("O&", + DlgObj_New, _rv); + return _res; +} + +static PyObject *Dlg_CouldDialog(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short dialogID; + if (!PyArg_ParseTuple(_args, "h", + &dialogID)) + return NULL; + CouldDialog(dialogID); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Dlg_FreeDialog(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short dialogID; + if (!PyArg_ParseTuple(_args, "h", + &dialogID)) + return NULL; + FreeDialog(dialogID); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Dlg_ParamText(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Str255 param0; + Str255 param1; + Str255 param2; + Str255 param3; + if (!PyArg_ParseTuple(_args, "O&O&O&O&", + PyMac_GetStr255, param0, + PyMac_GetStr255, param1, + PyMac_GetStr255, param2, + PyMac_GetStr255, param3)) + return NULL; + ParamText(param0, + param1, + param2, + param3); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Dlg_ModalDialog(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + PyObject* filterProc; + short itemHit; + if (!PyArg_ParseTuple(_args, "O", + &filterProc)) + return NULL; + ModalDialog(Dlg_PassFilterProc(filterProc), + &itemHit); + _res = Py_BuildValue("h", + itemHit); + return _res; +} + +static PyObject *Dlg_IsDialogEvent(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Boolean _rv; + EventRecord theEvent; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetEventRecord, &theEvent)) + return NULL; + _rv = IsDialogEvent(&theEvent); + _res = Py_BuildValue("b", + _rv); + return _res; +} + +static PyObject *Dlg_DialogSelect(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Boolean _rv; + EventRecord theEvent; + DialogPtr theDialog; + short itemHit; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetEventRecord, &theEvent)) + return NULL; + _rv = DialogSelect(&theEvent, + &theDialog, + &itemHit); + _res = Py_BuildValue("bO&h", + _rv, + WinObj_WhichWindow, theDialog, + itemHit); + return _res; +} + +static PyObject *Dlg_Alert(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + short alertID; + PyObject* filterProc; + if (!PyArg_ParseTuple(_args, "hO", + &alertID, + &filterProc)) + return NULL; + _rv = Alert(alertID, + Dlg_PassFilterProc(filterProc)); + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *Dlg_StopAlert(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + short alertID; + PyObject* filterProc; + if (!PyArg_ParseTuple(_args, "hO", + &alertID, + &filterProc)) + return NULL; + _rv = StopAlert(alertID, + Dlg_PassFilterProc(filterProc)); + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *Dlg_NoteAlert(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + short alertID; + PyObject* filterProc; + if (!PyArg_ParseTuple(_args, "hO", + &alertID, + &filterProc)) + return NULL; + _rv = NoteAlert(alertID, + Dlg_PassFilterProc(filterProc)); + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *Dlg_CautionAlert(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + short alertID; + PyObject* filterProc; + if (!PyArg_ParseTuple(_args, "hO", + &alertID, + &filterProc)) + return NULL; + _rv = CautionAlert(alertID, + Dlg_PassFilterProc(filterProc)); + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *Dlg_CouldAlert(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short alertID; + if (!PyArg_ParseTuple(_args, "h", + &alertID)) + return NULL; + CouldAlert(alertID); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Dlg_FreeAlert(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short alertID; + if (!PyArg_ParseTuple(_args, "h", + &alertID)) + return NULL; + FreeAlert(alertID); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Dlg_GetIText(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Handle item; + Str255 text; + if (!PyArg_ParseTuple(_args, "O&", + ResObj_Convert, &item)) + return NULL; + GetIText(item, + text); + _res = Py_BuildValue("O&", + PyMac_BuildStr255, text); + return _res; +} + +static PyObject *Dlg_SetIText(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Handle item; + Str255 text; + if (!PyArg_ParseTuple(_args, "O&O&", + ResObj_Convert, &item, + PyMac_GetStr255, text)) + return NULL; + SetIText(item, + text); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Dlg_NewCDialog(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + DialogPtr _rv; + Rect boundsRect; + Str255 title; + Boolean visible; + short procID; + WindowPtr behind; + Boolean goAwayFlag; + long refCon; + Handle items; + if (!PyArg_ParseTuple(_args, "O&O&bhO&blO&", + PyMac_GetRect, &boundsRect, + PyMac_GetStr255, title, + &visible, + &procID, + WinObj_Convert, &behind, + &goAwayFlag, + &refCon, + ResObj_Convert, &items)) + return NULL; + _rv = NewCDialog((void *)0, + &boundsRect, + title, + visible, + procID, + behind, + goAwayFlag, + refCon, + items); + _res = Py_BuildValue("O&", + DlgObj_New, _rv); + return _res; +} + +static PyObject *Dlg_ResetAlrtStage(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + ResetAlrtStage(); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Dlg_SetDAFont(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short fontNum; + if (!PyArg_ParseTuple(_args, "h", + &fontNum)) + return NULL; + SetDAFont(fontNum); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyMethodDef Dlg_methods[] = { + {"NewDialog", (PyCFunction)Dlg_NewDialog, 1, + "(Rect boundsRect, Str255 title, Boolean visible, short procID, WindowPtr behind, Boolean goAwayFlag, long refCon, Handle itmLstHndl) -> (DialogPtr _rv)"}, + {"GetNewDialog", (PyCFunction)Dlg_GetNewDialog, 1, + "(short dialogID, WindowPtr behind) -> (DialogPtr _rv)"}, + {"CouldDialog", (PyCFunction)Dlg_CouldDialog, 1, + "(short dialogID) -> None"}, + {"FreeDialog", (PyCFunction)Dlg_FreeDialog, 1, + "(short dialogID) -> None"}, + {"ParamText", (PyCFunction)Dlg_ParamText, 1, + "(Str255 param0, Str255 param1, Str255 param2, Str255 param3) -> None"}, + {"ModalDialog", (PyCFunction)Dlg_ModalDialog, 1, + "(PyObject* filterProc) -> (short itemHit)"}, + {"IsDialogEvent", (PyCFunction)Dlg_IsDialogEvent, 1, + "(EventRecord theEvent) -> (Boolean _rv)"}, + {"DialogSelect", (PyCFunction)Dlg_DialogSelect, 1, + "(EventRecord theEvent) -> (Boolean _rv, DialogPtr theDialog, short itemHit)"}, + {"Alert", (PyCFunction)Dlg_Alert, 1, + "(short alertID, PyObject* filterProc) -> (short _rv)"}, + {"StopAlert", (PyCFunction)Dlg_StopAlert, 1, + "(short alertID, PyObject* filterProc) -> (short _rv)"}, + {"NoteAlert", (PyCFunction)Dlg_NoteAlert, 1, + "(short alertID, PyObject* filterProc) -> (short _rv)"}, + {"CautionAlert", (PyCFunction)Dlg_CautionAlert, 1, + "(short alertID, PyObject* filterProc) -> (short _rv)"}, + {"CouldAlert", (PyCFunction)Dlg_CouldAlert, 1, + "(short alertID) -> None"}, + {"FreeAlert", (PyCFunction)Dlg_FreeAlert, 1, + "(short alertID) -> None"}, + {"GetIText", (PyCFunction)Dlg_GetIText, 1, + "(Handle item) -> (Str255 text)"}, + {"SetIText", (PyCFunction)Dlg_SetIText, 1, + "(Handle item, Str255 text) -> None"}, + {"NewCDialog", (PyCFunction)Dlg_NewCDialog, 1, + "(Rect boundsRect, Str255 title, Boolean visible, short procID, WindowPtr behind, Boolean goAwayFlag, long refCon, Handle items) -> (DialogPtr _rv)"}, + {"ResetAlrtStage", (PyCFunction)Dlg_ResetAlrtStage, 1, + "() -> None"}, + {"SetDAFont", (PyCFunction)Dlg_SetDAFont, 1, + "(short fontNum) -> None"}, + {NULL, NULL, 0} +}; + + + + +void initDlg() +{ + PyObject *m; + PyObject *d; + + + + + m = Py_InitModule("Dlg", Dlg_methods); + d = PyModule_GetDict(m); + Dlg_Error = PyMac_GetOSErrException(); + if (Dlg_Error == NULL || + PyDict_SetItemString(d, "Error", Dlg_Error) != 0) + Py_FatalError("can't initialize Dlg.Error"); +} + +/* ========================= End module Dlg ========================= */ + diff --git a/Mac/Modules/dlg/dlggen.py b/Mac/Modules/dlg/dlggen.py new file mode 100644 index 0000000..ea64ab7 --- /dev/null +++ b/Mac/Modules/dlg/dlggen.py @@ -0,0 +1,224 @@ +# Generated from 'D:Development:THINK C:Mac #includes:Apple #includes:Dialogs.h' + +f = Function(DialogPtr, 'NewDialog', + (NullStorage, 'wStorage', InMode), + (Rect_ptr, 'boundsRect', InMode), + (ConstStr255Param, 'title', InMode), + (Boolean, 'visible', InMode), + (short, 'procID', InMode), + (WindowPtr, 'behind', InMode), + (Boolean, 'goAwayFlag', InMode), + (long, 'refCon', InMode), + (Handle, 'itmLstHndl', InMode), +) +functions.append(f) + +f = Function(DialogPtr, 'GetNewDialog', + (short, 'dialogID', InMode), + (NullStorage, 'dStorage', InMode), + (WindowPtr, 'behind', InMode), +) +functions.append(f) + +f = Function(void, 'CouldDialog', + (short, 'dialogID', InMode), +) +functions.append(f) + +f = Function(void, 'FreeDialog', + (short, 'dialogID', InMode), +) +functions.append(f) + +f = Function(void, 'ParamText', + (ConstStr255Param, 'param0', InMode), + (ConstStr255Param, 'param1', InMode), + (ConstStr255Param, 'param2', InMode), + (ConstStr255Param, 'param3', InMode), +) +functions.append(f) + +f = Function(void, 'ModalDialog', + (ModalFilterProcPtr, 'filterProc', InMode), + (short, 'itemHit', OutMode), +) +functions.append(f) + +f = Function(Boolean, 'IsDialogEvent', + (EventRecord_ptr, 'theEvent', InMode), +) +functions.append(f) + +f = Function(Boolean, 'DialogSelect', + (EventRecord_ptr, 'theEvent', InMode), + (ExistingDialogPtr, 'theDialog', OutMode), + (short, 'itemHit', OutMode), +) +functions.append(f) + +f = Method(void, 'DrawDialog', + (DialogPtr, 'theDialog', InMode), +) +methods.append(f) + +f = Method(void, 'UpdtDialog', + (DialogPtr, 'theDialog', InMode), + (RgnHandle, 'updateRgn', InMode), +) +methods.append(f) + +f = Method(void, 'UpdateDialog', + (DialogPtr, 'theDialog', InMode), + (RgnHandle, 'updateRgn', InMode), +) +methods.append(f) + +f = Function(short, 'Alert', + (short, 'alertID', InMode), + (ModalFilterProcPtr, 'filterProc', InMode), +) +functions.append(f) + +f = Function(short, 'StopAlert', + (short, 'alertID', InMode), + (ModalFilterProcPtr, 'filterProc', InMode), +) +functions.append(f) + +f = Function(short, 'NoteAlert', + (short, 'alertID', InMode), + (ModalFilterProcPtr, 'filterProc', InMode), +) +functions.append(f) + +f = Function(short, 'CautionAlert', + (short, 'alertID', InMode), + (ModalFilterProcPtr, 'filterProc', InMode), +) +functions.append(f) + +f = Function(void, 'CouldAlert', + (short, 'alertID', InMode), +) +functions.append(f) + +f = Function(void, 'FreeAlert', + (short, 'alertID', InMode), +) +functions.append(f) + +f = Method(void, 'GetDItem', + (DialogPtr, 'theDialog', InMode), + (short, 'itemNo', InMode), + (short, 'itemType', OutMode), + (Handle, 'item', OutMode), + (Rect, 'box', OutMode), +) +methods.append(f) + +f = Method(void, 'SetDItem', + (DialogPtr, 'theDialog', InMode), + (short, 'itemNo', InMode), + (short, 'itemType', InMode), + (Handle, 'item', InMode), + (Rect_ptr, 'box', InMode), +) +methods.append(f) + +f = Method(void, 'HideDItem', + (DialogPtr, 'theDialog', InMode), + (short, 'itemNo', InMode), +) +methods.append(f) + +f = Method(void, 'ShowDItem', + (DialogPtr, 'theDialog', InMode), + (short, 'itemNo', InMode), +) +methods.append(f) + +f = Method(void, 'SelIText', + (DialogPtr, 'theDialog', InMode), + (short, 'itemNo', InMode), + (short, 'strtSel', InMode), + (short, 'endSel', InMode), +) +methods.append(f) + +f = Function(void, 'GetIText', + (Handle, 'item', InMode), + (Str255, 'text', OutMode), +) +functions.append(f) + +f = Function(void, 'SetIText', + (Handle, 'item', InMode), + (ConstStr255Param, 'text', InMode), +) +functions.append(f) + +f = Method(short, 'FindDItem', + (DialogPtr, 'theDialog', InMode), + (Point, 'thePt', InMode), +) +methods.append(f) + +f = Function(DialogPtr, 'NewCDialog', + (NullStorage, 'dStorage', InMode), + (Rect_ptr, 'boundsRect', InMode), + (ConstStr255Param, 'title', InMode), + (Boolean, 'visible', InMode), + (short, 'procID', InMode), + (WindowPtr, 'behind', InMode), + (Boolean, 'goAwayFlag', InMode), + (long, 'refCon', InMode), + (Handle, 'items', InMode), +) +functions.append(f) + +f = Function(void, 'ResetAlrtStage', +) +functions.append(f) + +f = Method(void, 'DlgCut', + (DialogPtr, 'theDialog', InMode), +) +methods.append(f) + +f = Method(void, 'DlgPaste', + (DialogPtr, 'theDialog', InMode), +) +methods.append(f) + +f = Method(void, 'DlgCopy', + (DialogPtr, 'theDialog', InMode), +) +methods.append(f) + +f = Method(void, 'DlgDelete', + (DialogPtr, 'theDialog', InMode), +) +methods.append(f) + +f = Function(void, 'SetDAFont', + (short, 'fontNum', InMode), +) +functions.append(f) + +f = Method(void, 'AppendDITL', + (DialogPtr, 'theDialog', InMode), + (Handle, 'theHandle', InMode), + (DITLMethod, 'method', InMode), +) +methods.append(f) + +f = Method(short, 'CountDITL', + (DialogPtr, 'theDialog', InMode), +) +methods.append(f) + +f = Method(void, 'ShortenDITL', + (DialogPtr, 'theDialog', InMode), + (short, 'numberItems', InMode), +) +methods.append(f) diff --git a/Mac/Modules/dlg/dlgscan.py b/Mac/Modules/dlg/dlgscan.py new file mode 100644 index 0000000..2a410f6 --- /dev/null +++ b/Mac/Modules/dlg/dlgscan.py @@ -0,0 +1,67 @@ +# Scan an Apple header file, generating a Python file of generator calls. + +from scantools import Scanner + +LONG = "Dialogs" +SHORT = "dlg" +OBJECT = "DialogPtr" + +def main(): + input = LONG + ".h" + output = SHORT + "gen.py" + defsoutput = LONG + ".py" + scanner = MyScanner(input, output, defsoutput) + scanner.scan() + scanner.close() + print "=== Done scanning and generating, now importing the generated code... ===" + exec "import " + SHORT + "support" + print "=== Done. It's up to you to compile it now! ===" + +class MyScanner(Scanner): + + def destination(self, type, name, arglist): + classname = "Function" + listname = "functions" + if arglist: + t, n, m = arglist[0] + if t == "DialogPtr" and m == "InMode": + classname = "Method" + listname = "methods" + return classname, listname + + def makeblacklistnames(self): + return [ + 'InitDialogs', + 'ErrorSound', + # Dialogs are disposed when the object is deleted + 'CloseDialog', + 'DisposDialog', + 'DisposeDialog', + ] + + def makeblacklisttypes(self): + return [ + ] + + def makerepairinstructions(self): + return [ + ([("Str255", "*", "InMode")], + [("*", "*", "OutMode")]), + + ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")], + [("InBuffer", "*", "*")]), + + ([("void", "*", "OutMode"), ("long", "*", "InMode"), + ("long", "*", "OutMode")], + [("VarVarOutBuffer", "*", "InOutMode")]), + + # NewDialog ETC. + ([("void", "*", "OutMode")], + [("NullStorage", "*", "InMode")]), + + ([("DialogPtr", "*", "OutMode")], + [("ExistingDialogPtr", "*", "*")]), + ] + +if __name__ == "__main__": + main() diff --git a/Mac/Modules/dlg/dlgsupport.py b/Mac/Modules/dlg/dlgsupport.py new file mode 100644 index 0000000..85e72bb --- /dev/null +++ b/Mac/Modules/dlg/dlgsupport.py @@ -0,0 +1,121 @@ +# This script generates the Dialogs interface for Python. +# It uses the "bgen" package to generate C code. +# It execs the file dlggen.py which contain the function definitions +# (dlggen.py was generated by dlgscan.py, scanning the <Dialogs.h> header file). + +from macsupport import * + +# Create the type objects + +DialogPtr = OpaqueByValueType("DialogPtr", "DlgObj") + +ModalFilterProcPtr = InputOnlyType("PyObject*", "O") +ModalFilterProcPtr.passInput = lambda name: "Dlg_PassFilterProc(%s)" % name + +RgnHandle = FakeType("_self->ob_itself->visRgn") # XXX + +DITLMethod = Type("DITLMethod", "h") + +includestuff = includestuff + """ +#include <Dialogs.h> + +#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */ + +/* XXX Shouldn't this be a stack? */ +static PyObject *Dlg_FilterProc_callback = NULL; + +static PyObject *DlgObj_New(DialogPtr); /* Forward */ + +static pascal Boolean Dlg_UnivFilterProc(DialogPtr dialog, + EventRecord *event, + short *itemHit) +{ + Boolean rv; + PyObject *args, *res; + PyObject *callback = Dlg_FilterProc_callback; + if (callback == NULL) + return 0; /* Default behavior */ + Dlg_FilterProc_callback = NULL; /* We'll restore it when call successful */ + args = Py_BuildValue("O&s#", DlgObj_New, dialog, event, sizeof(EventRecord)); + if (args == NULL) + res = NULL; + else { + res = PyEval_CallObject(callback, args); + Py_DECREF(args); + } + if (res == NULL) { + fprintf(stderr, "Exception in Dialog Filter\\n"); + PyErr_Print(); + *itemHit = -1; /* Fake return item */ + return 1; /* We handled it */ + } + else { + Dlg_FilterProc_callback = callback; + if (PyInt_Check(res)) { + *itemHit = PyInt_AsLong(res); + rv = 1; + } + else + rv = PyObject_IsTrue(res); + } + Py_DECREF(res); + return rv; +} + +static ModalFilterProcPtr +Dlg_PassFilterProc(PyObject *callback) +{ + PyObject *tmp = Dlg_FilterProc_callback; + Dlg_FilterProc_callback = NULL; + if (callback == Py_None) { + Py_XDECREF(tmp); + return NULL; + } + Py_INCREF(callback); + Dlg_FilterProc_callback = callback; + Py_XDECREF(tmp); + return &Dlg_UnivFilterProc; +} + +extern PyMethodChain WinObj_chain; +""" + + +# Define a class which specializes our object definition +class MyObjectDefinition(GlobalObjectDefinition): + def __init__(self, name, prefix = None, itselftype = None): + GlobalObjectDefinition.__init__(self, name, prefix, itselftype) + self.basechain = "&WinObj_chain" + def outputInitStructMembers(self): + GlobalObjectDefinition.outputInitStructMembers(self) + Output("SetWRefCon(itself, (long)it);") + def outputCheckNewArg(self): + Output("if (itself == NULL) return Py_None;") + def outputCheckConvertArg(self): + Output("if (v == Py_None) { *p_itself = NULL; return 1; }") + Output("if (PyInt_Check(v)) { *p_itself = (DialogPtr)PyInt_AsLong(v);") + Output(" return 1; }") + def outputFreeIt(self, itselfname): + Output("DisposeDialog(%s);", itselfname) + +# Create the generator groups and link them +module = MacModule('Dlg', 'Dlg', includestuff, finalstuff, initstuff) +object = MyObjectDefinition('Dialog', 'DlgObj', 'DialogPtr') +module.addobject(object) + +# Create the generator classes used to populate the lists +Function = OSErrFunctionGenerator +Method = OSErrMethodGenerator + +# Create and populate the lists +functions = [] +methods = [] +execfile("dlggen.py") + +# add the populated lists to the generator groups +for f in functions: module.add(f) +for f in methods: object.add(f) + +# generate output +SetOutputFileName('Dlgmodule.c') +module.generate() diff --git a/Mac/Modules/evt/Evtmodule.c b/Mac/Modules/evt/Evtmodule.c new file mode 100644 index 0000000..074a33e --- /dev/null +++ b/Mac/Modules/evt/Evtmodule.c @@ -0,0 +1,228 @@ + +/* =========================== Module Evt =========================== */ + +#include "Python.h" + + + +#define SystemSevenOrLater 1 + +#include "macglue.h" +#include <Memory.h> +#include <Dialogs.h> +#include <Menus.h> +#include <Controls.h> + +extern PyObject *ResObj_New(Handle); +extern int ResObj_Convert(PyObject *, Handle *); + +extern PyObject *WinObj_New(WindowPtr); +extern int WinObj_Convert(PyObject *, WindowPtr *); + +extern PyObject *DlgObj_New(DialogPtr); +extern int DlgObj_Convert(PyObject *, DialogPtr *); +extern PyTypeObject Dialog_Type; +#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type) + +extern PyObject *MenuObj_New(MenuHandle); +extern int MenuObj_Convert(PyObject *, MenuHandle *); + +extern PyObject *CtlObj_New(ControlHandle); +extern int CtlObj_Convert(PyObject *, ControlHandle *); + +#include <Events.h> + +#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */ + +static PyObject *Evt_Error; + +static PyObject *Evt_GetNextEvent(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Boolean _rv; + short eventMask; + EventRecord theEvent; + if (!PyArg_ParseTuple(_args, "h", + &eventMask)) + return NULL; + _rv = GetNextEvent(eventMask, + &theEvent); + _res = Py_BuildValue("bO&", + _rv, + PyMac_BuildEventRecord, &theEvent); + return _res; +} + +static PyObject *Evt_WaitNextEvent(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Boolean _rv; + short eventMask; + EventRecord theEvent; + unsigned long sleep; + if (!PyArg_ParseTuple(_args, "hl", + &eventMask, + &sleep)) + return NULL; + _rv = WaitNextEvent(eventMask, + &theEvent, + sleep, + (RgnHandle)0); + _res = Py_BuildValue("bO&", + _rv, + PyMac_BuildEventRecord, &theEvent); + return _res; +} + +static PyObject *Evt_EventAvail(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Boolean _rv; + short eventMask; + EventRecord theEvent; + if (!PyArg_ParseTuple(_args, "h", + &eventMask)) + return NULL; + _rv = EventAvail(eventMask, + &theEvent); + _res = Py_BuildValue("bO&", + _rv, + PyMac_BuildEventRecord, &theEvent); + return _res; +} + +static PyObject *Evt_GetMouse(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Point mouseLoc; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + GetMouse(&mouseLoc); + _res = Py_BuildValue("O&", + PyMac_BuildPoint, mouseLoc); + return _res; +} + +static PyObject *Evt_Button(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Boolean _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = Button(); + _res = Py_BuildValue("b", + _rv); + return _res; +} + +static PyObject *Evt_StillDown(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Boolean _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = StillDown(); + _res = Py_BuildValue("b", + _rv); + return _res; +} + +static PyObject *Evt_WaitMouseUp(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Boolean _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = WaitMouseUp(); + _res = Py_BuildValue("b", + _rv); + return _res; +} + +static PyObject *Evt_GetKeys(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + KeyMap theKeys__out__; + int theKeys__len__; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + GetKeys(theKeys__out__); + _res = Py_BuildValue("s#", + (char *)&theKeys__out__, sizeof(KeyMap)); + theKeys__error__: ; + return _res; +} + +static PyObject *Evt_TickCount(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + long _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = TickCount(); + _res = Py_BuildValue("l", + _rv); + return _res; +} + +static PyMethodDef Evt_methods[] = { + {"GetNextEvent", (PyCFunction)Evt_GetNextEvent, 1, + "(short eventMask) -> (Boolean _rv, EventRecord theEvent)"}, + {"WaitNextEvent", (PyCFunction)Evt_WaitNextEvent, 1, + "(short eventMask, unsigned long sleep) -> (Boolean _rv, EventRecord theEvent)"}, + {"EventAvail", (PyCFunction)Evt_EventAvail, 1, + "(short eventMask) -> (Boolean _rv, EventRecord theEvent)"}, + {"GetMouse", (PyCFunction)Evt_GetMouse, 1, + "() -> (Point mouseLoc)"}, + {"Button", (PyCFunction)Evt_Button, 1, + "() -> (Boolean _rv)"}, + {"StillDown", (PyCFunction)Evt_StillDown, 1, + "() -> (Boolean _rv)"}, + {"WaitMouseUp", (PyCFunction)Evt_WaitMouseUp, 1, + "() -> (Boolean _rv)"}, + {"GetKeys", (PyCFunction)Evt_GetKeys, 1, + "() -> (KeyMap theKeys)"}, + {"TickCount", (PyCFunction)Evt_TickCount, 1, + "() -> (long _rv)"}, + {NULL, NULL, 0} +}; + + + + +void initEvt() +{ + PyObject *m; + PyObject *d; + + + + + m = Py_InitModule("Evt", Evt_methods); + d = PyModule_GetDict(m); + Evt_Error = PyMac_GetOSErrException(); + if (Evt_Error == NULL || + PyDict_SetItemString(d, "Error", Evt_Error) != 0) + Py_FatalError("can't initialize Evt.Error"); +} + +/* ========================= End module Evt ========================= */ + diff --git a/Mac/Modules/evt/evtgen.py b/Mac/Modules/evt/evtgen.py new file mode 100644 index 0000000..ff30b8d --- /dev/null +++ b/Mac/Modules/evt/evtgen.py @@ -0,0 +1,47 @@ +# Generated from 'D:Development:THINK C:Mac #includes:Apple #includes:Events.h' + +f = Function(Boolean, 'GetNextEvent', + (short, 'eventMask', InMode), + (EventRecord, 'theEvent', OutMode), +) +functions.append(f) + +f = Function(Boolean, 'WaitNextEvent', + (short, 'eventMask', InMode), + (EventRecord, 'theEvent', OutMode), + (unsigned_long, 'sleep', InMode), + (RgnHandle, 'mouseRgn', InMode), +) +functions.append(f) + +f = Function(Boolean, 'EventAvail', + (short, 'eventMask', InMode), + (EventRecord, 'theEvent', OutMode), +) +functions.append(f) + +f = Function(void, 'GetMouse', + (Point, 'mouseLoc', OutMode), +) +functions.append(f) + +f = Function(Boolean, 'Button', +) +functions.append(f) + +f = Function(Boolean, 'StillDown', +) +functions.append(f) + +f = Function(Boolean, 'WaitMouseUp', +) +functions.append(f) + +f = Function(void, 'GetKeys', + (KeyMap, 'theKeys', OutMode), +) +functions.append(f) + +f = Function(long, 'TickCount', +) +functions.append(f) diff --git a/Mac/Modules/evt/evtscan.py b/Mac/Modules/evt/evtscan.py new file mode 100644 index 0000000..517db71 --- /dev/null +++ b/Mac/Modules/evt/evtscan.py @@ -0,0 +1,59 @@ +# Scan an Apple header file, generating a Python file of generator calls. + +from scantools import Scanner + +LONG = "Events" +SHORT = "evt" +OBJECT = "NOTUSED" + +def main(): + input = LONG + ".h" + output = SHORT + "gen.py" + defsoutput = LONG + ".py" + scanner = MyScanner(input, output, defsoutput) + scanner.scan() + scanner.close() + print "=== Done scanning and generating, now importing the generated code... ===" + exec "import " + SHORT + "support" + print "=== Done. It's up to you to compile it now! ===" + +class MyScanner(Scanner): + + def destination(self, type, name, arglist): + classname = "Function" + listname = "functions" + if arglist: + t, n, m = arglist[0] + # This is non-functional today + if t == OBJECT and m == "InMode": + classname = "Method" + listname = "methods" + return classname, listname + + def makeblacklistnames(self): + return [ + ] + + def makeblacklisttypes(self): + return [ + ] + + def makerepairinstructions(self): + return [ + ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")], + [("InBuffer", "*", "*")]), + + ([("void", "*", "OutMode"), ("long", "*", "InMode"), + ("long", "*", "OutMode")], + [("VarVarOutBuffer", "*", "InOutMode")]), + + ([("void", "wStorage", "OutMode")], + [("NullStorage", "*", "InMode")]), + + # GetKeys + ([('KeyMap', 'theKeys', 'InMode')], + [('*', '*', 'OutMode')]), + ] + +if __name__ == "__main__": + main() diff --git a/Mac/Modules/evt/evtsupport.py b/Mac/Modules/evt/evtsupport.py new file mode 100644 index 0000000..4798619 --- /dev/null +++ b/Mac/Modules/evt/evtsupport.py @@ -0,0 +1,74 @@ +# This script generates a Python interface for an Apple Macintosh Manager. +# It uses the "bgen" package to generate C code. +# The function specifications are generated by scanning the mamager's header file, +# using the "scantools" package (customized for this particular manager). + +import string + +# Declarations that change for each manager +MACHEADERFILE = 'Events.h' # The Apple header file +MODNAME = 'Evt' # The name of the module +OBJECTNAME = 'Event' # The basic name of the objects used here +KIND = 'Record' # Usually 'Ptr' or 'Handle' + +# The following is *usually* unchanged but may still require tuning +MODPREFIX = MODNAME # The prefix for module-wide routines +OBJECTTYPE = OBJECTNAME + KIND # The C type used to represent them +OBJECTPREFIX = MODPREFIX + 'Obj' # The prefix for object methods +INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner +OUTPUTFILE = MODNAME + "module.c" # The file generated by this program + +from macsupport import * + +# Create the type objects + +WindowPtr = OpaqueByValueType(OBJECTTYPE, OBJECTPREFIX) +WindowPeek = OpaqueByValueType("WindowPeek", OBJECTPREFIX) + +RgnHandle = FakeType("(RgnHandle)0") # XXX + +KeyMap = ArrayOutputBufferType("KeyMap") + +includestuff = includestuff + """ +#include <%s>""" % MACHEADERFILE + """ + +#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */ +""" + +class MyObjectDefinition(GlobalObjectDefinition): + def outputCheckNewArg(self): + Output("if (itself == NULL) return PyMac_Error(resNotFound);") + def outputCheckConvertArg(self): + OutLbrace("if (DlgObj_Check(v))") + Output("*p_itself = ((WindowObject *)v)->ob_itself;") + Output("return 1;") + OutRbrace() + Out(""" + if (v == Py_None) { *p_itself = NULL; return 1; } + if (PyInt_Check(v)) { *p_itself = (WindowPtr)PyInt_AsLong(v); return 1; } + """) + +# From here on it's basically all boiler plate... + +# Create the generator groups and link them +module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff) +##object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE) +##module.addobject(object) + +# Create the generator classes used to populate the lists +Function = OSErrFunctionGenerator +##Method = OSErrMethodGenerator + +# Create and populate the lists +functions = [] +##methods = [] +execfile(INPUTFILE) + +# add the populated lists to the generator groups +# (in a different wordl the scan program would generate this) +for f in functions: module.add(f) +##for f in methods: object.add(f) + +# generate output (open the output file as late as possible) +SetOutputFileName(OUTPUTFILE) +module.generate() diff --git a/Mac/Modules/menu/Menumodule.c b/Mac/Modules/menu/Menumodule.c new file mode 100644 index 0000000..78c4f60 --- /dev/null +++ b/Mac/Modules/menu/Menumodule.c @@ -0,0 +1,908 @@ + +/* ========================== Module Menu =========================== */ + +#include "Python.h" + + + +#define SystemSevenOrLater 1 + +#include "macglue.h" +#include <Memory.h> +#include <Dialogs.h> +#include <Menus.h> +#include <Controls.h> + +extern PyObject *ResObj_New(Handle); +extern int ResObj_Convert(PyObject *, Handle *); + +extern PyObject *WinObj_New(WindowPtr); +extern int WinObj_Convert(PyObject *, WindowPtr *); + +extern PyObject *DlgObj_New(DialogPtr); +extern int DlgObj_Convert(PyObject *, DialogPtr *); +extern PyTypeObject Dialog_Type; +#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type) + +extern PyObject *MenuObj_New(MenuHandle); +extern int MenuObj_Convert(PyObject *, MenuHandle *); + +extern PyObject *CtlObj_New(ControlHandle); +extern int CtlObj_Convert(PyObject *, ControlHandle *); + +extern PyObject *WinObj_WhichWindow(WindowPtr); + +#include <Menus.h> + +#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */ + +static PyObject *Menu_Error; + +/* ------------------------ Object type Menu ------------------------ */ + +PyTypeObject Menu_Type; + +#define MenuObj_Check(x) ((x)->ob_type == &Menu_Type) + +typedef struct MenuObject { + PyObject_HEAD + MenuHandle ob_itself; +} MenuObject; + +PyObject *MenuObj_New(itself) + const MenuHandle itself; +{ + MenuObject *it; + it = PyObject_NEW(MenuObject, &Menu_Type); + if (it == NULL) return NULL; + it->ob_itself = itself; + return (PyObject *)it; +} +MenuObj_Convert(v, p_itself) + PyObject *v; + MenuHandle *p_itself; +{ + if (!MenuObj_Check(v)) + { + PyErr_SetString(PyExc_TypeError, "Menu required"); + return 0; + } + *p_itself = ((MenuObject *)v)->ob_itself; + return 1; +} + +static void MenuObj_dealloc(self) + MenuObject *self; +{ + /* Cleanup of self->ob_itself goes here */ + PyMem_DEL(self); +} + +static PyObject *MenuObj_DisposeMenu(_self, _args) + MenuObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + DisposeMenu(_self->ob_itself); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *MenuObj_AppendMenu(_self, _args) + MenuObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Str255 data; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetStr255, data)) + return NULL; + AppendMenu(_self->ob_itself, + data); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *MenuObj_AddResMenu(_self, _args) + MenuObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + ResType theType; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetOSType, &theType)) + return NULL; + AddResMenu(_self->ob_itself, + theType); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *MenuObj_InsertResMenu(_self, _args) + MenuObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + ResType theType; + short afterItem; + if (!PyArg_ParseTuple(_args, "O&h", + PyMac_GetOSType, &theType, + &afterItem)) + return NULL; + InsertResMenu(_self->ob_itself, + theType, + afterItem); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *MenuObj_InsertMenu(_self, _args) + MenuObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short beforeID; + if (!PyArg_ParseTuple(_args, "h", + &beforeID)) + return NULL; + InsertMenu(_self->ob_itself, + beforeID); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *MenuObj_InsMenuItem(_self, _args) + MenuObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Str255 itemString; + short afterItem; + if (!PyArg_ParseTuple(_args, "O&h", + PyMac_GetStr255, itemString, + &afterItem)) + return NULL; + InsMenuItem(_self->ob_itself, + itemString, + afterItem); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *MenuObj_DelMenuItem(_self, _args) + MenuObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short item; + if (!PyArg_ParseTuple(_args, "h", + &item)) + return NULL; + DelMenuItem(_self->ob_itself, + item); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *MenuObj_SetItem(_self, _args) + MenuObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short item; + Str255 itemString; + if (!PyArg_ParseTuple(_args, "hO&", + &item, + PyMac_GetStr255, itemString)) + return NULL; + SetItem(_self->ob_itself, + item, + itemString); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *MenuObj_GetItem(_self, _args) + MenuObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short item; + Str255 itemString; + if (!PyArg_ParseTuple(_args, "h", + &item)) + return NULL; + GetItem(_self->ob_itself, + item, + itemString); + _res = Py_BuildValue("O&", + PyMac_BuildStr255, itemString); + return _res; +} + +static PyObject *MenuObj_DisableItem(_self, _args) + MenuObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short item; + if (!PyArg_ParseTuple(_args, "h", + &item)) + return NULL; + DisableItem(_self->ob_itself, + item); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *MenuObj_EnableItem(_self, _args) + MenuObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short item; + if (!PyArg_ParseTuple(_args, "h", + &item)) + return NULL; + EnableItem(_self->ob_itself, + item); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *MenuObj_CheckItem(_self, _args) + MenuObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short item; + Boolean checked; + if (!PyArg_ParseTuple(_args, "hb", + &item, + &checked)) + return NULL; + CheckItem(_self->ob_itself, + item, + checked); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *MenuObj_SetItemMark(_self, _args) + MenuObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short item; + short markChar; + if (!PyArg_ParseTuple(_args, "hh", + &item, + &markChar)) + return NULL; + SetItemMark(_self->ob_itself, + item, + markChar); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *MenuObj_GetItemMark(_self, _args) + MenuObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short item; + short markChar; + if (!PyArg_ParseTuple(_args, "h", + &item)) + return NULL; + GetItemMark(_self->ob_itself, + item, + &markChar); + _res = Py_BuildValue("h", + markChar); + return _res; +} + +static PyObject *MenuObj_SetItemIcon(_self, _args) + MenuObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short item; + short iconIndex; + if (!PyArg_ParseTuple(_args, "hh", + &item, + &iconIndex)) + return NULL; + SetItemIcon(_self->ob_itself, + item, + iconIndex); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *MenuObj_GetItemIcon(_self, _args) + MenuObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short item; + short iconIndex; + if (!PyArg_ParseTuple(_args, "h", + &item)) + return NULL; + GetItemIcon(_self->ob_itself, + item, + &iconIndex); + _res = Py_BuildValue("h", + iconIndex); + return _res; +} + +static PyObject *MenuObj_SetItemStyle(_self, _args) + MenuObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short item; + short chStyle; + if (!PyArg_ParseTuple(_args, "hh", + &item, + &chStyle)) + return NULL; + SetItemStyle(_self->ob_itself, + item, + chStyle); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *MenuObj_GetItemStyle(_self, _args) + MenuObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short item; + Style chStyle; + if (!PyArg_ParseTuple(_args, "h", + &item)) + return NULL; + GetItemStyle(_self->ob_itself, + item, + &chStyle); + _res = Py_BuildValue("b", + chStyle); + return _res; +} + +static PyObject *MenuObj_CalcMenuSize(_self, _args) + MenuObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + CalcMenuSize(_self->ob_itself); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *MenuObj_CountMItems(_self, _args) + MenuObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = CountMItems(_self->ob_itself); + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *MenuObj_GetItemCmd(_self, _args) + MenuObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short item; + short cmdChar; + if (!PyArg_ParseTuple(_args, "h", + &item)) + return NULL; + GetItemCmd(_self->ob_itself, + item, + &cmdChar); + _res = Py_BuildValue("h", + cmdChar); + return _res; +} + +static PyObject *MenuObj_SetItemCmd(_self, _args) + MenuObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short item; + short cmdChar; + if (!PyArg_ParseTuple(_args, "hh", + &item, + &cmdChar)) + return NULL; + SetItemCmd(_self->ob_itself, + item, + cmdChar); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *MenuObj_PopUpMenuSelect(_self, _args) + MenuObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + long _rv; + short top; + short left; + short popUpItem; + if (!PyArg_ParseTuple(_args, "hhh", + &top, + &left, + &popUpItem)) + return NULL; + _rv = PopUpMenuSelect(_self->ob_itself, + top, + left, + popUpItem); + _res = Py_BuildValue("l", + _rv); + return _res; +} + +static PyMethodDef MenuObj_methods[] = { + {"DisposeMenu", (PyCFunction)MenuObj_DisposeMenu, 1, + "() -> None"}, + {"AppendMenu", (PyCFunction)MenuObj_AppendMenu, 1, + "(Str255 data) -> None"}, + {"AddResMenu", (PyCFunction)MenuObj_AddResMenu, 1, + "(ResType theType) -> None"}, + {"InsertResMenu", (PyCFunction)MenuObj_InsertResMenu, 1, + "(ResType theType, short afterItem) -> None"}, + {"InsertMenu", (PyCFunction)MenuObj_InsertMenu, 1, + "(short beforeID) -> None"}, + {"InsMenuItem", (PyCFunction)MenuObj_InsMenuItem, 1, + "(Str255 itemString, short afterItem) -> None"}, + {"DelMenuItem", (PyCFunction)MenuObj_DelMenuItem, 1, + "(short item) -> None"}, + {"SetItem", (PyCFunction)MenuObj_SetItem, 1, + "(short item, Str255 itemString) -> None"}, + {"GetItem", (PyCFunction)MenuObj_GetItem, 1, + "(short item) -> (Str255 itemString)"}, + {"DisableItem", (PyCFunction)MenuObj_DisableItem, 1, + "(short item) -> None"}, + {"EnableItem", (PyCFunction)MenuObj_EnableItem, 1, + "(short item) -> None"}, + {"CheckItem", (PyCFunction)MenuObj_CheckItem, 1, + "(short item, Boolean checked) -> None"}, + {"SetItemMark", (PyCFunction)MenuObj_SetItemMark, 1, + "(short item, short markChar) -> None"}, + {"GetItemMark", (PyCFunction)MenuObj_GetItemMark, 1, + "(short item) -> (short markChar)"}, + {"SetItemIcon", (PyCFunction)MenuObj_SetItemIcon, 1, + "(short item, short iconIndex) -> None"}, + {"GetItemIcon", (PyCFunction)MenuObj_GetItemIcon, 1, + "(short item) -> (short iconIndex)"}, + {"SetItemStyle", (PyCFunction)MenuObj_SetItemStyle, 1, + "(short item, short chStyle) -> None"}, + {"GetItemStyle", (PyCFunction)MenuObj_GetItemStyle, 1, + "(short item) -> (Style chStyle)"}, + {"CalcMenuSize", (PyCFunction)MenuObj_CalcMenuSize, 1, + "() -> None"}, + {"CountMItems", (PyCFunction)MenuObj_CountMItems, 1, + "() -> (short _rv)"}, + {"GetItemCmd", (PyCFunction)MenuObj_GetItemCmd, 1, + "(short item) -> (short cmdChar)"}, + {"SetItemCmd", (PyCFunction)MenuObj_SetItemCmd, 1, + "(short item, short cmdChar) -> None"}, + {"PopUpMenuSelect", (PyCFunction)MenuObj_PopUpMenuSelect, 1, + "(short top, short left, short popUpItem) -> (long _rv)"}, + {NULL, NULL, 0} +}; + +PyMethodChain MenuObj_chain = { MenuObj_methods, NULL }; + +static PyObject *MenuObj_getattr(self, name) + MenuObject *self; + char *name; +{ + return Py_FindMethodInChain(&MenuObj_chain, (PyObject *)self, name); +} + +#define MenuObj_setattr NULL + +PyTypeObject Menu_Type = { + PyObject_HEAD_INIT(&PyType_Type) + 0, /*ob_size*/ + "Menu", /*tp_name*/ + sizeof(MenuObject), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + /* methods */ + (destructor) MenuObj_dealloc, /*tp_dealloc*/ + 0, /*tp_print*/ + (getattrfunc) MenuObj_getattr, /*tp_getattr*/ + (setattrfunc) MenuObj_setattr, /*tp_setattr*/ +}; + +/* ---------------------- End object type Menu ---------------------- */ + + +static PyObject *Menu_InitMenus(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + InitMenus(); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Menu_NewMenu(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + MenuHandle _rv; + short menuID; + Str255 menuTitle; + if (!PyArg_ParseTuple(_args, "hO&", + &menuID, + PyMac_GetStr255, menuTitle)) + return NULL; + _rv = NewMenu(menuID, + menuTitle); + _res = Py_BuildValue("O&", + MenuObj_New, _rv); + return _res; +} + +static PyObject *Menu_GetMenu(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + MenuHandle _rv; + short resourceID; + if (!PyArg_ParseTuple(_args, "h", + &resourceID)) + return NULL; + _rv = GetMenu(resourceID); + _res = Py_BuildValue("O&", + MenuObj_New, _rv); + return _res; +} + +static PyObject *Menu_DrawMenuBar(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + DrawMenuBar(); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Menu_InvalMenuBar(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + InvalMenuBar(); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Menu_DeleteMenu(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short menuID; + if (!PyArg_ParseTuple(_args, "h", + &menuID)) + return NULL; + DeleteMenu(menuID); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Menu_ClearMenuBar(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + ClearMenuBar(); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Menu_GetNewMBar(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Handle _rv; + short menuBarID; + if (!PyArg_ParseTuple(_args, "h", + &menuBarID)) + return NULL; + _rv = GetNewMBar(menuBarID); + _res = Py_BuildValue("O&", + ResObj_New, _rv); + return _res; +} + +static PyObject *Menu_GetMenuBar(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Handle _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = GetMenuBar(); + _res = Py_BuildValue("O&", + ResObj_New, _rv); + return _res; +} + +static PyObject *Menu_SetMenuBar(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Handle menuList; + if (!PyArg_ParseTuple(_args, "O&", + ResObj_Convert, &menuList)) + return NULL; + SetMenuBar(menuList); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Menu_MenuKey(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + long _rv; + short ch; + if (!PyArg_ParseTuple(_args, "h", + &ch)) + return NULL; + _rv = MenuKey(ch); + _res = Py_BuildValue("l", + _rv); + return _res; +} + +static PyObject *Menu_HiliteMenu(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short menuID; + if (!PyArg_ParseTuple(_args, "h", + &menuID)) + return NULL; + HiliteMenu(menuID); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Menu_GetMHandle(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + MenuHandle _rv; + short menuID; + if (!PyArg_ParseTuple(_args, "h", + &menuID)) + return NULL; + _rv = GetMHandle(menuID); + _res = Py_BuildValue("O&", + MenuObj_New, _rv); + return _res; +} + +static PyObject *Menu_FlashMenuBar(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short menuID; + if (!PyArg_ParseTuple(_args, "h", + &menuID)) + return NULL; + FlashMenuBar(menuID); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Menu_SetMenuFlash(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short count; + if (!PyArg_ParseTuple(_args, "h", + &count)) + return NULL; + SetMenuFlash(count); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Menu_MenuSelect(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + long _rv; + Point startPt; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetPoint, &startPt)) + return NULL; + _rv = MenuSelect(startPt); + _res = Py_BuildValue("l", + _rv); + return _res; +} + +static PyObject *Menu_InitProcMenu(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short resID; + if (!PyArg_ParseTuple(_args, "h", + &resID)) + return NULL; + InitProcMenu(resID); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Menu_MenuChoice(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + long _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = MenuChoice(); + _res = Py_BuildValue("l", + _rv); + return _res; +} + +static PyObject *Menu_DelMCEntries(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short menuID; + short menuItem; + if (!PyArg_ParseTuple(_args, "hh", + &menuID, + &menuItem)) + return NULL; + DelMCEntries(menuID, + menuItem); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyMethodDef Menu_methods[] = { + {"InitMenus", (PyCFunction)Menu_InitMenus, 1, + "() -> None"}, + {"NewMenu", (PyCFunction)Menu_NewMenu, 1, + "(short menuID, Str255 menuTitle) -> (MenuHandle _rv)"}, + {"GetMenu", (PyCFunction)Menu_GetMenu, 1, + "(short resourceID) -> (MenuHandle _rv)"}, + {"DrawMenuBar", (PyCFunction)Menu_DrawMenuBar, 1, + "() -> None"}, + {"InvalMenuBar", (PyCFunction)Menu_InvalMenuBar, 1, + "() -> None"}, + {"DeleteMenu", (PyCFunction)Menu_DeleteMenu, 1, + "(short menuID) -> None"}, + {"ClearMenuBar", (PyCFunction)Menu_ClearMenuBar, 1, + "() -> None"}, + {"GetNewMBar", (PyCFunction)Menu_GetNewMBar, 1, + "(short menuBarID) -> (Handle _rv)"}, + {"GetMenuBar", (PyCFunction)Menu_GetMenuBar, 1, + "() -> (Handle _rv)"}, + {"SetMenuBar", (PyCFunction)Menu_SetMenuBar, 1, + "(Handle menuList) -> None"}, + {"MenuKey", (PyCFunction)Menu_MenuKey, 1, + "(short ch) -> (long _rv)"}, + {"HiliteMenu", (PyCFunction)Menu_HiliteMenu, 1, + "(short menuID) -> None"}, + {"GetMHandle", (PyCFunction)Menu_GetMHandle, 1, + "(short menuID) -> (MenuHandle _rv)"}, + {"FlashMenuBar", (PyCFunction)Menu_FlashMenuBar, 1, + "(short menuID) -> None"}, + {"SetMenuFlash", (PyCFunction)Menu_SetMenuFlash, 1, + "(short count) -> None"}, + {"MenuSelect", (PyCFunction)Menu_MenuSelect, 1, + "(Point startPt) -> (long _rv)"}, + {"InitProcMenu", (PyCFunction)Menu_InitProcMenu, 1, + "(short resID) -> None"}, + {"MenuChoice", (PyCFunction)Menu_MenuChoice, 1, + "() -> (long _rv)"}, + {"DelMCEntries", (PyCFunction)Menu_DelMCEntries, 1, + "(short menuID, short menuItem) -> None"}, + {NULL, NULL, 0} +}; + + + + +void initMenu() +{ + PyObject *m; + PyObject *d; + + + + + m = Py_InitModule("Menu", Menu_methods); + d = PyModule_GetDict(m); + Menu_Error = PyMac_GetOSErrException(); + if (Menu_Error == NULL || + PyDict_SetItemString(d, "Error", Menu_Error) != 0) + Py_FatalError("can't initialize Menu.Error"); +} + +/* ======================== End module Menu ========================= */ + diff --git a/Mac/Modules/menu/menugen.py b/Mac/Modules/menu/menugen.py new file mode 100644 index 0000000..30315b8 --- /dev/null +++ b/Mac/Modules/menu/menugen.py @@ -0,0 +1,242 @@ +# Generated from 'D:Development:THINK C:Mac #includes:Apple #includes:Menus.h' + +f = Function(void, 'InitMenus', +) +functions.append(f) + +f = Function(MenuHandle, 'NewMenu', + (short, 'menuID', InMode), + (Str255, 'menuTitle', InMode), +) +functions.append(f) + +f = Function(MenuHandle, 'GetMenu', + (short, 'resourceID', InMode), +) +functions.append(f) + +f = Method(void, 'DisposeMenu', + (MenuHandle, 'theMenu', InMode), +) +methods.append(f) + +f = Method(void, 'AppendMenu', + (MenuHandle, 'menu', InMode), + (ConstStr255Param, 'data', InMode), +) +methods.append(f) + +f = Method(void, 'AddResMenu', + (MenuHandle, 'theMenu', InMode), + (ResType, 'theType', InMode), +) +methods.append(f) + +f = Method(void, 'InsertResMenu', + (MenuHandle, 'theMenu', InMode), + (ResType, 'theType', InMode), + (short, 'afterItem', InMode), +) +methods.append(f) + +f = Method(void, 'InsertMenu', + (MenuHandle, 'theMenu', InMode), + (short, 'beforeID', InMode), +) +methods.append(f) + +f = Function(void, 'DrawMenuBar', +) +functions.append(f) + +f = Function(void, 'InvalMenuBar', +) +functions.append(f) + +f = Function(void, 'DeleteMenu', + (short, 'menuID', InMode), +) +functions.append(f) + +f = Function(void, 'ClearMenuBar', +) +functions.append(f) + +f = Function(Handle, 'GetNewMBar', + (short, 'menuBarID', InMode), +) +functions.append(f) + +f = Function(Handle, 'GetMenuBar', +) +functions.append(f) + +f = Function(void, 'SetMenuBar', + (Handle, 'menuList', InMode), +) +functions.append(f) + +f = Method(void, 'InsMenuItem', + (MenuHandle, 'theMenu', InMode), + (ConstStr255Param, 'itemString', InMode), + (short, 'afterItem', InMode), +) +methods.append(f) + +f = Method(void, 'DelMenuItem', + (MenuHandle, 'theMenu', InMode), + (short, 'item', InMode), +) +methods.append(f) + +f = Function(long, 'MenuKey', + (short, 'ch', InMode), +) +functions.append(f) + +f = Function(void, 'HiliteMenu', + (short, 'menuID', InMode), +) +functions.append(f) + +f = Method(void, 'SetItem', + (MenuHandle, 'theMenu', InMode), + (short, 'item', InMode), + (ConstStr255Param, 'itemString', InMode), +) +methods.append(f) + +f = Method(void, 'GetItem', + (MenuHandle, 'theMenu', InMode), + (short, 'item', InMode), + (Str255, 'itemString', OutMode), +) +methods.append(f) + +f = Method(void, 'DisableItem', + (MenuHandle, 'theMenu', InMode), + (short, 'item', InMode), +) +methods.append(f) + +f = Method(void, 'EnableItem', + (MenuHandle, 'theMenu', InMode), + (short, 'item', InMode), +) +methods.append(f) + +f = Method(void, 'CheckItem', + (MenuHandle, 'theMenu', InMode), + (short, 'item', InMode), + (Boolean, 'checked', InMode), +) +methods.append(f) + +f = Method(void, 'SetItemMark', + (MenuHandle, 'theMenu', InMode), + (short, 'item', InMode), + (short, 'markChar', InMode), +) +methods.append(f) + +f = Method(void, 'GetItemMark', + (MenuHandle, 'theMenu', InMode), + (short, 'item', InMode), + (short, 'markChar', OutMode), +) +methods.append(f) + +f = Method(void, 'SetItemIcon', + (MenuHandle, 'theMenu', InMode), + (short, 'item', InMode), + (short, 'iconIndex', InMode), +) +methods.append(f) + +f = Method(void, 'GetItemIcon', + (MenuHandle, 'theMenu', InMode), + (short, 'item', InMode), + (short, 'iconIndex', OutMode), +) +methods.append(f) + +f = Method(void, 'SetItemStyle', + (MenuHandle, 'theMenu', InMode), + (short, 'item', InMode), + (short, 'chStyle', InMode), +) +methods.append(f) + +f = Method(void, 'GetItemStyle', + (MenuHandle, 'theMenu', InMode), + (short, 'item', InMode), + (Style, 'chStyle', OutMode), +) +methods.append(f) + +f = Method(void, 'CalcMenuSize', + (MenuHandle, 'theMenu', InMode), +) +methods.append(f) + +f = Method(short, 'CountMItems', + (MenuHandle, 'theMenu', InMode), +) +methods.append(f) + +f = Function(MenuHandle, 'GetMHandle', + (short, 'menuID', InMode), +) +functions.append(f) + +f = Function(void, 'FlashMenuBar', + (short, 'menuID', InMode), +) +functions.append(f) + +f = Function(void, 'SetMenuFlash', + (short, 'count', InMode), +) +functions.append(f) + +f = Function(long, 'MenuSelect', + (Point, 'startPt', InMode), +) +functions.append(f) + +f = Function(void, 'InitProcMenu', + (short, 'resID', InMode), +) +functions.append(f) + +f = Method(void, 'GetItemCmd', + (MenuHandle, 'theMenu', InMode), + (short, 'item', InMode), + (short, 'cmdChar', OutMode), +) +methods.append(f) + +f = Method(void, 'SetItemCmd', + (MenuHandle, 'theMenu', InMode), + (short, 'item', InMode), + (short, 'cmdChar', InMode), +) +methods.append(f) + +f = Method(long, 'PopUpMenuSelect', + (MenuHandle, 'menu', InMode), + (short, 'top', InMode), + (short, 'left', InMode), + (short, 'popUpItem', InMode), +) +methods.append(f) + +f = Function(long, 'MenuChoice', +) +functions.append(f) + +f = Function(void, 'DelMCEntries', + (short, 'menuID', InMode), + (short, 'menuItem', InMode), +) +functions.append(f) diff --git a/Mac/Modules/menu/menuscan.py b/Mac/Modules/menu/menuscan.py new file mode 100644 index 0000000..b120052 --- /dev/null +++ b/Mac/Modules/menu/menuscan.py @@ -0,0 +1,53 @@ +# Scan <Menus.h>, generating menugen.py. + +from scantools import Scanner + +def main(): + input = "Menus.h" + output = "menugen.py" + defsoutput = "Menus.py" + scanner = MyScanner(input, output, defsoutput) + scanner.scan() + scanner.close() + print "=== Done scanning and generating, now doing 'import menusupport' ===" + import menusupport + print "=== Done. It's up to you to compile Menumodule.c ===" + +class MyScanner(Scanner): + + def destination(self, type, name, arglist): + classname = "Function" + listname = "functions" + if arglist: + t, n, m = arglist[0] + if t == "MenuHandle" and m == "InMode": + classname = "Method" + listname = "methods" + return classname, listname + + def makeblacklistnames(self): + return [ + ] + + def makeblacklisttypes(self): + return [ + 'MCTableHandle', + 'MCEntryPtr', + 'MCTablePtr', + ] + + def makerepairinstructions(self): + return [ + ([("Str255", "itemString", "InMode")], + [("*", "*", "OutMode")]), + + ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")], + [("InBuffer", "*", "*")]), + + ([("void", "*", "OutMode"), ("long", "*", "InMode"), + ("long", "*", "OutMode")], + [("VarVarOutBuffer", "*", "InOutMode")]), + ] + +if __name__ == "__main__": + main() diff --git a/Mac/Modules/menu/menusupport.py b/Mac/Modules/menu/menusupport.py new file mode 100644 index 0000000..c3fb3be --- /dev/null +++ b/Mac/Modules/menu/menusupport.py @@ -0,0 +1,55 @@ +# This script generates a Python interface for an Apple Macintosh Manager. +# It uses the "bgen" package to generate C code. +# The function specifications are generated by scanning the mamager's header file, +# using the "scantools" package (customized for this particular manager). + +import string + +# Declarations that change for each manager +MACHEADERFILE = 'Menus.h' # The Apple header file +MODNAME = 'Menu' # The name of the module +OBJECTNAME = 'Menu' # The basic name of the objects used here + +# The following is *usually* unchanged but may still require tuning +MODPREFIX = MODNAME # The prefix for module-wide routines +OBJECTTYPE = OBJECTNAME + 'Handle' # The C type used to represent them +OBJECTPREFIX = MODPREFIX + 'Obj' # The prefix for object methods +INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner +OUTPUTFILE = MODNAME + "module.c" # The file generated by this program + +from macsupport import * + +# Create the type objects + +MenuHandle = OpaqueByValueType(OBJECTTYPE, OBJECTPREFIX) + +includestuff = includestuff + """ +#include <%s>""" % MACHEADERFILE + """ + +#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */ +""" + +class MyObjectDefinition(GlobalObjectDefinition): + pass + +# Create the generator groups and link them +module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff) +object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE) +module.addobject(object) + +# Create the generator classes used to populate the lists +Function = OSErrFunctionGenerator +Method = OSErrMethodGenerator + +# Create and populate the lists +functions = [] +methods = [] +execfile(INPUTFILE) + +# add the populated lists to the generator groups +for f in functions: module.add(f) +for f in methods: object.add(f) + +# generate output (open the output file as late as possible) +SetOutputFileName(OUTPUTFILE) +module.generate() diff --git a/Mac/Modules/qd/Qdmodule.c b/Mac/Modules/qd/Qdmodule.c new file mode 100644 index 0000000..2f88857 --- /dev/null +++ b/Mac/Modules/qd/Qdmodule.c @@ -0,0 +1,168 @@ + +/* =========================== Module Qd ============================ */ + +#include "Python.h" + + + +#define SystemSevenOrLater 1 + +#include "macglue.h" +#include <Memory.h> +#include <Dialogs.h> +#include <Menus.h> +#include <Controls.h> + +extern PyObject *ResObj_New(Handle); +extern int ResObj_Convert(PyObject *, Handle *); + +extern PyObject *WinObj_New(WindowPtr); +extern int WinObj_Convert(PyObject *, WindowPtr *); + +extern PyObject *DlgObj_New(DialogPtr); +extern int DlgObj_Convert(PyObject *, DialogPtr *); +extern PyTypeObject Dialog_Type; +#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type) + +extern PyObject *MenuObj_New(MenuHandle); +extern int MenuObj_Convert(PyObject *, MenuHandle *); + +extern PyObject *CtlObj_New(ControlHandle); +extern int CtlObj_Convert(PyObject *, ControlHandle *); + +extern PyObject *WinObj_WhichWindow(WindowPtr); + +#include <QuickDraw.h> +#include <Desk.h> + +#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */ + +static PyObject *Qd_Error; + +static PyObject *Qd_GlobalToLocal(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Point thePoint; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetPoint, &thePoint)) + return NULL; + GlobalToLocal(&thePoint); + _res = Py_BuildValue("O&", + PyMac_BuildPoint, thePoint); + return _res; +} + +static PyObject *Qd_LocalToGlobal(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Point thePoint; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetPoint, &thePoint)) + return NULL; + LocalToGlobal(&thePoint); + _res = Py_BuildValue("O&", + PyMac_BuildPoint, thePoint); + return _res; +} + +static PyObject *Qd_SetPort(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + WindowPtr thePort; + if (!PyArg_ParseTuple(_args, "O&", + WinObj_Convert, &thePort)) + return NULL; + SetPort(thePort); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Qd_ClipRect(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Rect r; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetRect, &r)) + return NULL; + ClipRect(&r); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Qd_EraseRect(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Rect r; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetRect, &r)) + return NULL; + EraseRect(&r); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Qd_OpenDeskAcc(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Str255 name; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetStr255, name)) + return NULL; + OpenDeskAcc(name); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyMethodDef Qd_methods[] = { + {"GlobalToLocal", (PyCFunction)Qd_GlobalToLocal, 1, + "(Point thePoint) -> (Point thePoint)"}, + {"LocalToGlobal", (PyCFunction)Qd_LocalToGlobal, 1, + "(Point thePoint) -> (Point thePoint)"}, + {"SetPort", (PyCFunction)Qd_SetPort, 1, + "(WindowPtr thePort) -> None"}, + {"ClipRect", (PyCFunction)Qd_ClipRect, 1, + "(Rect r) -> None"}, + {"EraseRect", (PyCFunction)Qd_EraseRect, 1, + "(Rect r) -> None"}, + {"OpenDeskAcc", (PyCFunction)Qd_OpenDeskAcc, 1, + "(Str255 name) -> None"}, + {NULL, NULL, 0} +}; + + + + +void initQd() +{ + PyObject *m; + PyObject *d; + + + + + m = Py_InitModule("Qd", Qd_methods); + d = PyModule_GetDict(m); + Qd_Error = PyMac_GetOSErrException(); + if (Qd_Error == NULL || + PyDict_SetItemString(d, "Error", Qd_Error) != 0) + Py_FatalError("can't initialize Qd.Error"); +} + +/* ========================= End module Qd ========================== */ + diff --git a/Mac/Modules/qd/qdedit.py b/Mac/Modules/qd/qdedit.py new file mode 100644 index 0000000..2242c5a --- /dev/null +++ b/Mac/Modules/qd/qdedit.py @@ -0,0 +1,29 @@ +f = Function(void, 'GlobalToLocal', + (Point, 'thePoint', InOutMode), +) +functions.append(f) + +f = Function(void, 'LocalToGlobal', + (Point, 'thePoint', InOutMode), +) +functions.append(f) + +f = Function(void, 'SetPort', + (WindowPtr, 'thePort', InMode), +) +functions.append(f) + +f = Function(void, 'ClipRect', + (Rect, 'r', InMode), +) +functions.append(f) + +f = Function(void, 'EraseRect', + (Rect, 'r', InMode), +) +functions.append(f) + +f = Function(void, 'OpenDeskAcc', + (Str255, 'name', InMode), +) +functions.append(f) diff --git a/Mac/Modules/qd/qdsupport.py b/Mac/Modules/qd/qdsupport.py new file mode 100644 index 0000000..e98b27a --- /dev/null +++ b/Mac/Modules/qd/qdsupport.py @@ -0,0 +1,72 @@ +# This script generates a Python interface for an Apple Macintosh Manager. +# It uses the "bgen" package to generate C code. +# The function specifications are generated by scanning the mamager's header file, +# using the "scantools" package (customized for this particular manager). + +import string + +# Declarations that change for each manager +MACHEADERFILE = 'QuickDraw.h' # The Apple header file +MODNAME = 'Qd' # The name of the module +OBJECTNAME = 'Graf' # The basic name of the objects used here + +# The following is *usually* unchanged but may still require tuning +MODPREFIX = MODNAME # The prefix for module-wide routines +OBJECTTYPE = OBJECTNAME + 'Ptr' # The C type used to represent them +OBJECTPREFIX = MODPREFIX + 'Obj' # The prefix for object methods +INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner +EXTRAFILE = string.lower(MODPREFIX) + 'edit.py' # A similar file but hand-made +OUTPUTFILE = MODNAME + "module.c" # The file generated by this program + +from macsupport import * + +# Create the type objects + +includestuff = includestuff + """ +#include <%s>""" % MACHEADERFILE + """ +#include <Desk.h> + +#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */ +""" + +class MyObjectDefinition(GlobalObjectDefinition): + def outputCheckNewArg(self): + Output("if (itself == NULL) return PyMac_Error(resNotFound);") + def outputCheckConvertArg(self): + OutLbrace("if (DlgObj_Check(v))") + Output("*p_itself = ((WindowObject *)v)->ob_itself;") + Output("return 1;") + OutRbrace() + Out(""" + if (v == Py_None) { *p_itself = NULL; return 1; } + if (PyInt_Check(v)) { *p_itself = (WindowPtr)PyInt_AsLong(v); return 1; } + """) + def outputFreeIt(self, itselfname): + Output("DisposeWindow(%s);", itselfname) + +# From here on it's basically all boiler plate... + +# Create the generator groups and link them +module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff) +##object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE) +##module.addobject(object) + +# Create the generator classes used to populate the lists +Function = OSErrFunctionGenerator +Method = OSErrMethodGenerator + +# Create and populate the lists +functions = [] +methods = [] +#execfile(INPUTFILE) +execfile(EXTRAFILE) + +# add the populated lists to the generator groups +# (in a different wordl the scan program would generate this) +for f in functions: module.add(f) +for f in methods: object.add(f) + +# generate output (open the output file as late as possible) +SetOutputFileName(OUTPUTFILE) +module.generate() +SetOutputFile() # Close it diff --git a/Mac/Modules/res/Resmodule.c b/Mac/Modules/res/Resmodule.c new file mode 100644 index 0000000..484bca6 --- /dev/null +++ b/Mac/Modules/res/Resmodule.c @@ -0,0 +1,1256 @@ + +/* =========================== Module Res =========================== */ + +#include "Python.h" + + + +#define SystemSevenOrLater 1 + +#include "macglue.h" +#include <Memory.h> +#include <Dialogs.h> +#include <Menus.h> +#include <Controls.h> + +extern PyObject *ResObj_New(Handle); +extern int ResObj_Convert(PyObject *, Handle *); + +extern PyObject *WinObj_New(WindowPtr); +extern int WinObj_Convert(PyObject *, WindowPtr *); + +extern PyObject *DlgObj_New(DialogPtr); +extern int DlgObj_Convert(PyObject *, DialogPtr *); +extern PyTypeObject Dialog_Type; +#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type) + +extern PyObject *MenuObj_New(MenuHandle); +extern int MenuObj_Convert(PyObject *, MenuHandle *); + +extern PyObject *CtlObj_New(ControlHandle); +extern int CtlObj_Convert(PyObject *, ControlHandle *); + +#include <Resources.h> + +#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */ + +static PyObject *Res_Error; + +/* ---------------------- Object type Resource ---------------------- */ + +PyTypeObject Resource_Type; + +#define ResObj_Check(x) ((x)->ob_type == &Resource_Type) + +typedef struct ResourceObject { + PyObject_HEAD + Handle ob_itself; +} ResourceObject; + +PyObject *ResObj_New(itself) + const Handle itself; +{ + ResourceObject *it; + if (itself == NULL) return PyMac_Error(resNotFound); + it = PyObject_NEW(ResourceObject, &Resource_Type); + if (it == NULL) return NULL; + it->ob_itself = itself; + return (PyObject *)it; +} +ResObj_Convert(v, p_itself) + PyObject *v; + Handle *p_itself; +{ + if (!ResObj_Check(v)) + { + PyErr_SetString(PyExc_TypeError, "Resource required"); + return 0; + } + *p_itself = ((ResourceObject *)v)->ob_itself; + return 1; +} + +static void ResObj_dealloc(self) + ResourceObject *self; +{ + /* Cleanup of self->ob_itself goes here */ + PyMem_DEL(self); +} + +static PyObject *ResObj_HomeResFile(_self, _args) + ResourceObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = HomeResFile(_self->ob_itself); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *ResObj_LoadResource(_self, _args) + ResourceObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + LoadResource(_self->ob_itself); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *ResObj_ReleaseResource(_self, _args) + ResourceObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + ReleaseResource(_self->ob_itself); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *ResObj_DetachResource(_self, _args) + ResourceObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + DetachResource(_self->ob_itself); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *ResObj_GetResAttrs(_self, _args) + ResourceObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = GetResAttrs(_self->ob_itself); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *ResObj_GetResInfo(_self, _args) + ResourceObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short theID; + ResType theType; + Str255 name; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + GetResInfo(_self->ob_itself, + &theID, + &theType, + name); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("hO&O&", + theID, + PyMac_BuildOSType, theType, + PyMac_BuildStr255, name); + return _res; +} + +static PyObject *ResObj_SetResInfo(_self, _args) + ResourceObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short theID; + Str255 name; + if (!PyArg_ParseTuple(_args, "hO&", + &theID, + PyMac_GetStr255, name)) + return NULL; + SetResInfo(_self->ob_itself, + theID, + name); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *ResObj_AddResource(_self, _args) + ResourceObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + ResType theType; + short theID; + Str255 name; + if (!PyArg_ParseTuple(_args, "O&hO&", + PyMac_GetOSType, &theType, + &theID, + PyMac_GetStr255, name)) + return NULL; + AddResource(_self->ob_itself, + theType, + theID, + name); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *ResObj_SizeResource(_self, _args) + ResourceObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + long _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = SizeResource(_self->ob_itself); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("l", + _rv); + return _res; +} + +static PyObject *ResObj_MaxSizeRsrc(_self, _args) + ResourceObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + long _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = MaxSizeRsrc(_self->ob_itself); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("l", + _rv); + return _res; +} + +static PyObject *ResObj_RsrcMapEntry(_self, _args) + ResourceObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + long _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = RsrcMapEntry(_self->ob_itself); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("l", + _rv); + return _res; +} + +static PyObject *ResObj_SetResAttrs(_self, _args) + ResourceObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short attrs; + if (!PyArg_ParseTuple(_args, "h", + &attrs)) + return NULL; + SetResAttrs(_self->ob_itself, + attrs); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *ResObj_ChangedResource(_self, _args) + ResourceObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + ChangedResource(_self->ob_itself); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *ResObj_RmveResource(_self, _args) + ResourceObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + RmveResource(_self->ob_itself); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *ResObj_WriteResource(_self, _args) + ResourceObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + WriteResource(_self->ob_itself); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *ResObj_SetResourceSize(_self, _args) + ResourceObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + long newSize; + if (!PyArg_ParseTuple(_args, "l", + &newSize)) + return NULL; + SetResourceSize(_self->ob_itself, + newSize); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyMethodDef ResObj_methods[] = { + {"HomeResFile", (PyCFunction)ResObj_HomeResFile, 1, + "() -> (short _rv)"}, + {"LoadResource", (PyCFunction)ResObj_LoadResource, 1, + "() -> None"}, + {"ReleaseResource", (PyCFunction)ResObj_ReleaseResource, 1, + "() -> None"}, + {"DetachResource", (PyCFunction)ResObj_DetachResource, 1, + "() -> None"}, + {"GetResAttrs", (PyCFunction)ResObj_GetResAttrs, 1, + "() -> (short _rv)"}, + {"GetResInfo", (PyCFunction)ResObj_GetResInfo, 1, + "() -> (short theID, ResType theType, Str255 name)"}, + {"SetResInfo", (PyCFunction)ResObj_SetResInfo, 1, + "(short theID, Str255 name) -> None"}, + {"AddResource", (PyCFunction)ResObj_AddResource, 1, + "(ResType theType, short theID, Str255 name) -> None"}, + {"SizeResource", (PyCFunction)ResObj_SizeResource, 1, + "() -> (long _rv)"}, + {"MaxSizeRsrc", (PyCFunction)ResObj_MaxSizeRsrc, 1, + "() -> (long _rv)"}, + {"RsrcMapEntry", (PyCFunction)ResObj_RsrcMapEntry, 1, + "() -> (long _rv)"}, + {"SetResAttrs", (PyCFunction)ResObj_SetResAttrs, 1, + "(short attrs) -> None"}, + {"ChangedResource", (PyCFunction)ResObj_ChangedResource, 1, + "() -> None"}, + {"RmveResource", (PyCFunction)ResObj_RmveResource, 1, + "() -> None"}, + {"WriteResource", (PyCFunction)ResObj_WriteResource, 1, + "() -> None"}, + {"SetResourceSize", (PyCFunction)ResObj_SetResourceSize, 1, + "(long newSize) -> None"}, + {NULL, NULL, 0} +}; + +PyMethodChain ResObj_chain = { ResObj_methods, NULL }; + +static PyObject *ResObj_getattr(self, name) + ResourceObject *self; + char *name; +{ + + if (strcmp(name, "size") == 0) + return PyInt_FromLong(GetHandleSize(self->ob_itself)); + if (strcmp(name, "data") == 0) { + PyObject *res; + char state; + state = HGetState(self->ob_itself); + HLock(self->ob_itself); + res = PyString_FromStringAndSize( + *self->ob_itself, + GetHandleSize(self->ob_itself)); + HUnlock(self->ob_itself); + HSetState(self->ob_itself, state); + return res; + } + if (strcmp(name, "__members__") == 0) + return Py_BuildValue("[ss]", "data", "size"); + + return Py_FindMethodInChain(&ResObj_chain, (PyObject *)self, name); +} + +#define ResObj_setattr NULL + +PyTypeObject Resource_Type = { + PyObject_HEAD_INIT(&PyType_Type) + 0, /*ob_size*/ + "Resource", /*tp_name*/ + sizeof(ResourceObject), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + /* methods */ + (destructor) ResObj_dealloc, /*tp_dealloc*/ + 0, /*tp_print*/ + (getattrfunc) ResObj_getattr, /*tp_getattr*/ + (setattrfunc) ResObj_setattr, /*tp_setattr*/ +}; + +/* -------------------- End object type Resource -------------------- */ + + +static PyObject *Res_InitResources(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = InitResources(); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *Res_RsrcZoneInit(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + RsrcZoneInit(); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Res_CloseResFile(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short refNum; + if (!PyArg_ParseTuple(_args, "h", + &refNum)) + return NULL; + CloseResFile(refNum); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Res_ResError(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = ResError(); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *Res_CurResFile(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = CurResFile(); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *Res_CreateResFile(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Str255 fileName; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetStr255, fileName)) + return NULL; + CreateResFile(fileName); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Res_OpenResFile(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + Str255 fileName; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetStr255, fileName)) + return NULL; + _rv = OpenResFile(fileName); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *Res_UseResFile(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short refNum; + if (!PyArg_ParseTuple(_args, "h", + &refNum)) + return NULL; + UseResFile(refNum); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Res_CountTypes(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = CountTypes(); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *Res_Count1Types(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = Count1Types(); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *Res_GetIndType(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + ResType theType; + short index; + if (!PyArg_ParseTuple(_args, "h", + &index)) + return NULL; + GetIndType(&theType, + index); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("O&", + PyMac_BuildOSType, theType); + return _res; +} + +static PyObject *Res_Get1IndType(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + ResType theType; + short index; + if (!PyArg_ParseTuple(_args, "h", + &index)) + return NULL; + Get1IndType(&theType, + index); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("O&", + PyMac_BuildOSType, theType); + return _res; +} + +static PyObject *Res_SetResLoad(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Boolean load; + if (!PyArg_ParseTuple(_args, "b", + &load)) + return NULL; + SetResLoad(load); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Res_CountResources(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + ResType theType; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetOSType, &theType)) + return NULL; + _rv = CountResources(theType); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *Res_Count1Resources(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + ResType theType; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetOSType, &theType)) + return NULL; + _rv = Count1Resources(theType); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *Res_GetIndResource(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Handle _rv; + ResType theType; + short index; + if (!PyArg_ParseTuple(_args, "O&h", + PyMac_GetOSType, &theType, + &index)) + return NULL; + _rv = GetIndResource(theType, + index); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("O&", + ResObj_New, _rv); + return _res; +} + +static PyObject *Res_Get1IndResource(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Handle _rv; + ResType theType; + short index; + if (!PyArg_ParseTuple(_args, "O&h", + PyMac_GetOSType, &theType, + &index)) + return NULL; + _rv = Get1IndResource(theType, + index); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("O&", + ResObj_New, _rv); + return _res; +} + +static PyObject *Res_GetResource(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Handle _rv; + ResType theType; + short theID; + if (!PyArg_ParseTuple(_args, "O&h", + PyMac_GetOSType, &theType, + &theID)) + return NULL; + _rv = GetResource(theType, + theID); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("O&", + ResObj_New, _rv); + return _res; +} + +static PyObject *Res_Get1Resource(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Handle _rv; + ResType theType; + short theID; + if (!PyArg_ParseTuple(_args, "O&h", + PyMac_GetOSType, &theType, + &theID)) + return NULL; + _rv = Get1Resource(theType, + theID); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("O&", + ResObj_New, _rv); + return _res; +} + +static PyObject *Res_GetNamedResource(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Handle _rv; + ResType theType; + Str255 name; + if (!PyArg_ParseTuple(_args, "O&O&", + PyMac_GetOSType, &theType, + PyMac_GetStr255, name)) + return NULL; + _rv = GetNamedResource(theType, + name); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("O&", + ResObj_New, _rv); + return _res; +} + +static PyObject *Res_Get1NamedResource(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Handle _rv; + ResType theType; + Str255 name; + if (!PyArg_ParseTuple(_args, "O&O&", + PyMac_GetOSType, &theType, + PyMac_GetStr255, name)) + return NULL; + _rv = Get1NamedResource(theType, + name); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("O&", + ResObj_New, _rv); + return _res; +} + +static PyObject *Res_UniqueID(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + ResType theType; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetOSType, &theType)) + return NULL; + _rv = UniqueID(theType); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *Res_Unique1ID(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + ResType theType; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetOSType, &theType)) + return NULL; + _rv = Unique1ID(theType); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *Res_UpdateResFile(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short refNum; + if (!PyArg_ParseTuple(_args, "h", + &refNum)) + return NULL; + UpdateResFile(refNum); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Res_SetResPurge(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Boolean install; + if (!PyArg_ParseTuple(_args, "b", + &install)) + return NULL; + SetResPurge(install); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Res_GetResFileAttrs(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + short refNum; + if (!PyArg_ParseTuple(_args, "h", + &refNum)) + return NULL; + _rv = GetResFileAttrs(refNum); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *Res_SetResFileAttrs(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short refNum; + short attrs; + if (!PyArg_ParseTuple(_args, "hh", + &refNum, + &attrs)) + return NULL; + SetResFileAttrs(refNum, + attrs); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Res_OpenRFPerm(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + Str255 fileName; + short vRefNum; + char permission; + if (!PyArg_ParseTuple(_args, "O&hc", + PyMac_GetStr255, fileName, + &vRefNum, + &permission)) + return NULL; + _rv = OpenRFPerm(fileName, + vRefNum, + permission); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *Res_RGetResource(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Handle _rv; + ResType theType; + short theID; + if (!PyArg_ParseTuple(_args, "O&h", + PyMac_GetOSType, &theType, + &theID)) + return NULL; + _rv = RGetResource(theType, + theID); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("O&", + ResObj_New, _rv); + return _res; +} + +static PyObject *Res_HOpenResFile(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + short vRefNum; + long dirID; + Str255 fileName; + char permission; + if (!PyArg_ParseTuple(_args, "hlO&c", + &vRefNum, + &dirID, + PyMac_GetStr255, fileName, + &permission)) + return NULL; + _rv = HOpenResFile(vRefNum, + dirID, + fileName, + permission); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *Res_HCreateResFile(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short vRefNum; + long dirID; + Str255 fileName; + if (!PyArg_ParseTuple(_args, "hlO&", + &vRefNum, + &dirID, + PyMac_GetStr255, fileName)) + return NULL; + HCreateResFile(vRefNum, + dirID, + fileName); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Res_FSpOpenResFile(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + FSSpec spec; + SignedByte permission; + if (!PyArg_ParseTuple(_args, "O&b", + PyMac_GetFSSpec, &spec, + &permission)) + return NULL; + _rv = FSpOpenResFile(&spec, + permission); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *Res_FSpCreateResFile(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + FSSpec spec; + OSType creator; + OSType fileType; + ScriptCode scriptTag; + if (!PyArg_ParseTuple(_args, "O&O&O&h", + PyMac_GetFSSpec, &spec, + PyMac_GetOSType, &creator, + PyMac_GetOSType, &fileType, + &scriptTag)) + return NULL; + FSpCreateResFile(&spec, + creator, + fileType, + scriptTag); + { + OSErr _err = ResError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyMethodDef Res_methods[] = { + {"InitResources", (PyCFunction)Res_InitResources, 1, + "() -> (short _rv)"}, + {"RsrcZoneInit", (PyCFunction)Res_RsrcZoneInit, 1, + "() -> None"}, + {"CloseResFile", (PyCFunction)Res_CloseResFile, 1, + "(short refNum) -> None"}, + {"ResError", (PyCFunction)Res_ResError, 1, + "() -> (short _rv)"}, + {"CurResFile", (PyCFunction)Res_CurResFile, 1, + "() -> (short _rv)"}, + {"CreateResFile", (PyCFunction)Res_CreateResFile, 1, + "(Str255 fileName) -> None"}, + {"OpenResFile", (PyCFunction)Res_OpenResFile, 1, + "(Str255 fileName) -> (short _rv)"}, + {"UseResFile", (PyCFunction)Res_UseResFile, 1, + "(short refNum) -> None"}, + {"CountTypes", (PyCFunction)Res_CountTypes, 1, + "() -> (short _rv)"}, + {"Count1Types", (PyCFunction)Res_Count1Types, 1, + "() -> (short _rv)"}, + {"GetIndType", (PyCFunction)Res_GetIndType, 1, + "(short index) -> (ResType theType)"}, + {"Get1IndType", (PyCFunction)Res_Get1IndType, 1, + "(short index) -> (ResType theType)"}, + {"SetResLoad", (PyCFunction)Res_SetResLoad, 1, + "(Boolean load) -> None"}, + {"CountResources", (PyCFunction)Res_CountResources, 1, + "(ResType theType) -> (short _rv)"}, + {"Count1Resources", (PyCFunction)Res_Count1Resources, 1, + "(ResType theType) -> (short _rv)"}, + {"GetIndResource", (PyCFunction)Res_GetIndResource, 1, + "(ResType theType, short index) -> (Handle _rv)"}, + {"Get1IndResource", (PyCFunction)Res_Get1IndResource, 1, + "(ResType theType, short index) -> (Handle _rv)"}, + {"GetResource", (PyCFunction)Res_GetResource, 1, + "(ResType theType, short theID) -> (Handle _rv)"}, + {"Get1Resource", (PyCFunction)Res_Get1Resource, 1, + "(ResType theType, short theID) -> (Handle _rv)"}, + {"GetNamedResource", (PyCFunction)Res_GetNamedResource, 1, + "(ResType theType, Str255 name) -> (Handle _rv)"}, + {"Get1NamedResource", (PyCFunction)Res_Get1NamedResource, 1, + "(ResType theType, Str255 name) -> (Handle _rv)"}, + {"UniqueID", (PyCFunction)Res_UniqueID, 1, + "(ResType theType) -> (short _rv)"}, + {"Unique1ID", (PyCFunction)Res_Unique1ID, 1, + "(ResType theType) -> (short _rv)"}, + {"UpdateResFile", (PyCFunction)Res_UpdateResFile, 1, + "(short refNum) -> None"}, + {"SetResPurge", (PyCFunction)Res_SetResPurge, 1, + "(Boolean install) -> None"}, + {"GetResFileAttrs", (PyCFunction)Res_GetResFileAttrs, 1, + "(short refNum) -> (short _rv)"}, + {"SetResFileAttrs", (PyCFunction)Res_SetResFileAttrs, 1, + "(short refNum, short attrs) -> None"}, + {"OpenRFPerm", (PyCFunction)Res_OpenRFPerm, 1, + "(Str255 fileName, short vRefNum, char permission) -> (short _rv)"}, + {"RGetResource", (PyCFunction)Res_RGetResource, 1, + "(ResType theType, short theID) -> (Handle _rv)"}, + {"HOpenResFile", (PyCFunction)Res_HOpenResFile, 1, + "(short vRefNum, long dirID, Str255 fileName, char permission) -> (short _rv)"}, + {"HCreateResFile", (PyCFunction)Res_HCreateResFile, 1, + "(short vRefNum, long dirID, Str255 fileName) -> None"}, + {"FSpOpenResFile", (PyCFunction)Res_FSpOpenResFile, 1, + "(FSSpec spec, SignedByte permission) -> (short _rv)"}, + {"FSpCreateResFile", (PyCFunction)Res_FSpCreateResFile, 1, + "(FSSpec spec, OSType creator, OSType fileType, ScriptCode scriptTag) -> None"}, + {NULL, NULL, 0} +}; + + + + + +void initRes() +{ + PyObject *m; + PyObject *d; + + + + + + m = Py_InitModule("Res", Res_methods); + d = PyModule_GetDict(m); + Res_Error = PyMac_GetOSErrException(); + if (Res_Error == NULL || + PyDict_SetItemString(d, "Error", Res_Error) != 0) + Py_FatalError("can't initialize Res.Error"); +} + +/* ========================= End module Res ========================= */ + diff --git a/Mac/Modules/res/resgen.py b/Mac/Modules/res/resgen.py new file mode 100644 index 0000000..3716e9e --- /dev/null +++ b/Mac/Modules/res/resgen.py @@ -0,0 +1,271 @@ +# Generated from 'D:Development:THINK C:Mac #includes:Apple #includes:Resources.h' + +f = ResFunction(short, 'InitResources', +) +functions.append(f) + +f = ResFunction(void, 'RsrcZoneInit', +) +functions.append(f) + +f = ResFunction(void, 'CloseResFile', + (short, 'refNum', InMode), +) +functions.append(f) + +f = ResFunction(short, 'ResError', +) +functions.append(f) + +f = ResFunction(short, 'CurResFile', +) +functions.append(f) + +f = ResMethod(short, 'HomeResFile', + (Handle, 'theResource', InMode), +) +resmethods.append(f) + +f = ResFunction(void, 'CreateResFile', + (ConstStr255Param, 'fileName', InMode), +) +functions.append(f) + +f = ResFunction(short, 'OpenResFile', + (ConstStr255Param, 'fileName', InMode), +) +functions.append(f) + +f = ResFunction(void, 'UseResFile', + (short, 'refNum', InMode), +) +functions.append(f) + +f = ResFunction(short, 'CountTypes', +) +functions.append(f) + +f = ResFunction(short, 'Count1Types', +) +functions.append(f) + +f = ResFunction(void, 'GetIndType', + (ResType, 'theType', OutMode), + (short, 'index', InMode), +) +functions.append(f) + +f = ResFunction(void, 'Get1IndType', + (ResType, 'theType', OutMode), + (short, 'index', InMode), +) +functions.append(f) + +f = ResFunction(void, 'SetResLoad', + (Boolean, 'load', InMode), +) +functions.append(f) + +f = ResFunction(short, 'CountResources', + (ResType, 'theType', InMode), +) +functions.append(f) + +f = ResFunction(short, 'Count1Resources', + (ResType, 'theType', InMode), +) +functions.append(f) + +f = ResFunction(Handle, 'GetIndResource', + (ResType, 'theType', InMode), + (short, 'index', InMode), +) +functions.append(f) + +f = ResFunction(Handle, 'Get1IndResource', + (ResType, 'theType', InMode), + (short, 'index', InMode), +) +functions.append(f) + +f = ResFunction(Handle, 'GetResource', + (ResType, 'theType', InMode), + (short, 'theID', InMode), +) +functions.append(f) + +f = ResFunction(Handle, 'Get1Resource', + (ResType, 'theType', InMode), + (short, 'theID', InMode), +) +functions.append(f) + +f = ResFunction(Handle, 'GetNamedResource', + (ResType, 'theType', InMode), + (ConstStr255Param, 'name', InMode), +) +functions.append(f) + +f = ResFunction(Handle, 'Get1NamedResource', + (ResType, 'theType', InMode), + (ConstStr255Param, 'name', InMode), +) +functions.append(f) + +f = ResMethod(void, 'LoadResource', + (Handle, 'theResource', InMode), +) +resmethods.append(f) + +f = ResMethod(void, 'ReleaseResource', + (Handle, 'theResource', InMode), +) +resmethods.append(f) + +f = ResMethod(void, 'DetachResource', + (Handle, 'theResource', InMode), +) +resmethods.append(f) + +f = ResFunction(short, 'UniqueID', + (ResType, 'theType', InMode), +) +functions.append(f) + +f = ResFunction(short, 'Unique1ID', + (ResType, 'theType', InMode), +) +functions.append(f) + +f = ResMethod(short, 'GetResAttrs', + (Handle, 'theResource', InMode), +) +resmethods.append(f) + +f = ResMethod(void, 'GetResInfo', + (Handle, 'theResource', InMode), + (short, 'theID', OutMode), + (ResType, 'theType', OutMode), + (Str255, 'name', OutMode), +) +resmethods.append(f) + +f = ResMethod(void, 'SetResInfo', + (Handle, 'theResource', InMode), + (short, 'theID', InMode), + (ConstStr255Param, 'name', InMode), +) +resmethods.append(f) + +f = ResMethod(void, 'AddResource', + (Handle, 'theResource', InMode), + (ResType, 'theType', InMode), + (short, 'theID', InMode), + (ConstStr255Param, 'name', InMode), +) +resmethods.append(f) + +f = ResMethod(long, 'SizeResource', + (Handle, 'theResource', InMode), +) +resmethods.append(f) + +f = ResMethod(long, 'MaxSizeRsrc', + (Handle, 'theResource', InMode), +) +resmethods.append(f) + +f = ResMethod(long, 'RsrcMapEntry', + (Handle, 'theResource', InMode), +) +resmethods.append(f) + +f = ResMethod(void, 'SetResAttrs', + (Handle, 'theResource', InMode), + (short, 'attrs', InMode), +) +resmethods.append(f) + +f = ResMethod(void, 'ChangedResource', + (Handle, 'theResource', InMode), +) +resmethods.append(f) + +f = ResMethod(void, 'RmveResource', + (Handle, 'theResource', InMode), +) +resmethods.append(f) + +f = ResFunction(void, 'UpdateResFile', + (short, 'refNum', InMode), +) +functions.append(f) + +f = ResMethod(void, 'WriteResource', + (Handle, 'theResource', InMode), +) +resmethods.append(f) + +f = ResFunction(void, 'SetResPurge', + (Boolean, 'install', InMode), +) +functions.append(f) + +f = ResFunction(short, 'GetResFileAttrs', + (short, 'refNum', InMode), +) +functions.append(f) + +f = ResFunction(void, 'SetResFileAttrs', + (short, 'refNum', InMode), + (short, 'attrs', InMode), +) +functions.append(f) + +f = ResFunction(short, 'OpenRFPerm', + (ConstStr255Param, 'fileName', InMode), + (short, 'vRefNum', InMode), + (char, 'permission', InMode), +) +functions.append(f) + +f = ResFunction(Handle, 'RGetResource', + (ResType, 'theType', InMode), + (short, 'theID', InMode), +) +functions.append(f) + +f = ResFunction(short, 'HOpenResFile', + (short, 'vRefNum', InMode), + (long, 'dirID', InMode), + (ConstStr255Param, 'fileName', InMode), + (char, 'permission', InMode), +) +functions.append(f) + +f = ResFunction(void, 'HCreateResFile', + (short, 'vRefNum', InMode), + (long, 'dirID', InMode), + (ConstStr255Param, 'fileName', InMode), +) +functions.append(f) + +f = ResFunction(short, 'FSpOpenResFile', + (FSSpec_ptr, 'spec', InMode), + (SignedByte, 'permission', InMode), +) +functions.append(f) + +f = ResFunction(void, 'FSpCreateResFile', + (FSSpec_ptr, 'spec', InMode), + (OSType, 'creator', InMode), + (OSType, 'fileType', InMode), + (ScriptCode, 'scriptTag', InMode), +) +functions.append(f) + +f = ResMethod(void, 'SetResourceSize', + (Handle, 'theResource', InMode), + (long, 'newSize', InMode), +) +resmethods.append(f) diff --git a/Mac/Modules/res/resscan.py b/Mac/Modules/res/resscan.py new file mode 100644 index 0000000..42bb389 --- /dev/null +++ b/Mac/Modules/res/resscan.py @@ -0,0 +1,60 @@ +# Scan Resources.h header file, generate resgen.py and Resources.py files. +# Then run ressupport to generate Resmodule.c. +# (Should learn how to tell the compiler to compile it as well.) + +import sys +import os +import string +import regex +import regsub +import MacOS + +from scantools import Scanner + +def main(): + input = "Resources.h" + output = "resgen.py" + defsoutput = "Resources.py" + scanner = ResourcesScanner(input, output, defsoutput) + scanner.scan() + scanner.close() + print "=== Done scanning and generating, now doing 'import ressupport' ===" + import ressupport + print "=== Done 'import ressupport'. It's up to you to compile Resmodule.c ===" + +class ResourcesScanner(Scanner): + + def destination(self, type, name, arglist): + classname = "ResFunction" + listname = "functions" + if arglist: + t, n, m = arglist[0] + if t == "Handle" and m == "InMode": + classname = "ResMethod" + listname = "resmethods" + return classname, listname + + def makeblacklistnames(self): + return [ + "ReadPartialResource", + "WritePartialResource", + ] + + def makerepairinstructions(self): + return [ + ([("Str255", "*", "InMode")], + [("*", "*", "OutMode")]), + + ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")], + [("InBuffer", "*", "*")]), + + ([("void", "*", "OutMode"), ("long", "*", "InMode")], + [("InOutBuffer", "*", "*")]), + + ([("void", "*", "OutMode"), ("long", "*", "InMode"), + ("long", "*", "OutMode")], + [("OutBuffer", "*", "InOutMode")]), + ] + +if __name__ == "__main__": + main() diff --git a/Mac/Modules/res/ressupport.py b/Mac/Modules/res/ressupport.py new file mode 100644 index 0000000..5c0d70f --- /dev/null +++ b/Mac/Modules/res/ressupport.py @@ -0,0 +1,77 @@ +# This script will generate the Resources interface for Python. +# It uses the "bgen" package to generate C code. +# It execs the file resgen.py which contain the function definitions +# (resgen.py was generated by resscan.py, scanning the <Resources.h> header file). + +from macsupport import * + + +class ResMixIn: + + def checkit(self): + OutLbrace() + Output("OSErr _err = ResError();") + Output("if (_err != noErr) return PyMac_Error(_err);") + OutRbrace() + FunctionGenerator.checkit(self) # XXX + +class ResFunction(ResMixIn, FunctionGenerator): pass +class ResMethod(ResMixIn, MethodGenerator): pass + +# includestuff etc. are imported from macsupport + +includestuff = includestuff + """ +#include <Resources.h> + +#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */ +""" + +finalstuff = finalstuff + """ +""" + +initstuff = initstuff + """ +""" + +module = MacModule('Res', 'Res', includestuff, finalstuff, initstuff) + +getattrHookCode = """ +if (strcmp(name, "size") == 0) + return PyInt_FromLong(GetHandleSize(self->ob_itself)); +if (strcmp(name, "data") == 0) { + PyObject *res; + char state; + state = HGetState(self->ob_itself); + HLock(self->ob_itself); + res = PyString_FromStringAndSize( + *self->ob_itself, + GetHandleSize(self->ob_itself)); + HUnlock(self->ob_itself); + HSetState(self->ob_itself, state); + return res; +} +if (strcmp(name, "__members__") == 0) + return Py_BuildValue("[ss]", "data", "size"); +""" + +class ResDefiniton(GlobalObjectDefinition): + + def outputCheckNewArg(self): + Output("if (itself == NULL) return PyMac_Error(resNotFound);") + + def outputGetattrHook(self): + Output(getattrHookCode) + + +resobject = ResDefiniton('Resource', 'ResObj', 'Handle') +module.addobject(resobject) + +functions = [] +resmethods = [] + +execfile('resgen.py') + +for f in functions: module.add(f) +for f in resmethods: resobject.add(f) + +SetOutputFileName('Resmodule.c') +module.generate() diff --git a/Mac/Modules/snd/Sndmodule.c b/Mac/Modules/snd/Sndmodule.c new file mode 100644 index 0000000..0f71b0d --- /dev/null +++ b/Mac/Modules/snd/Sndmodule.c @@ -0,0 +1,786 @@ + +/* =========================== Module Snd =========================== */ + +#include "Python.h" + + + +#define SystemSevenOrLater 1 + +#include "macglue.h" +#include <Memory.h> +#include <Dialogs.h> +#include <Menus.h> +#include <Controls.h> + +extern PyObject *ResObj_New(Handle); +extern int ResObj_Convert(PyObject *, Handle *); + +extern PyObject *WinObj_New(WindowPtr); +extern int WinObj_Convert(PyObject *, WindowPtr *); + +extern PyObject *DlgObj_New(DialogPtr); +extern int DlgObj_Convert(PyObject *, DialogPtr *); +extern PyTypeObject Dialog_Type; +#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type) + +extern PyObject *MenuObj_New(MenuHandle); +extern int MenuObj_Convert(PyObject *, MenuHandle *); + +extern PyObject *CtlObj_New(ControlHandle); +extern int CtlObj_Convert(PyObject *, ControlHandle *); + +#include <Sound.h> + +#ifndef __MWERKS__ +#define SndCallBackUPP ProcPtr +#define NewSndCallBackProc(x) (x) +#define SndListHandle Handle +#endif + +#include <OSUtils.h> /* for Set(Current)A5 */ + +/* Create a SndCommand object (an (int, int, int) tuple) */ +static PyObject * +SndCmd_New(SndCommand *pc) +{ + return Py_BuildValue("hhl", pc->cmd, pc->param1, pc->param2); +} + +/* Convert a SndCommand argument */ +static int +SndCmd_Convert(PyObject *v, SndCommand *pc) +{ + int len; + pc->param1 = 0; + pc->param2 = 0; + if (PyTuple_Check(v)) { + if (PyArg_ParseTuple(v, "h|hl", &pc->cmd, &pc->param1, &pc->param2)) + return 1; + PyErr_Clear(); + return PyArg_ParseTuple(v, "hhs#", &pc->cmd, &pc->param1, &pc->param2, &len); + } + return PyArg_Parse(v, "h", &pc->cmd); +} + +/* Create a NumVersion object (a quintuple of integers) */ +static PyObject * +NumVer_New(NumVersion nv) +{ + return Py_BuildValue("iiiii", + nv.majorRev, + nv.minorRev, + nv.bugFixRev, + nv.stage, + nv.nonRelRev); +} + +static pascal void SndCh_UserRoutine(SndChannelPtr chan, SndCommand *cmd); /* Forward */ + +static PyObject *Snd_Error; + +/* --------------------- Object type SndChannel --------------------- */ + +staticforward PyTypeObject SndChannel_Type; + +#define SndCh_Check(x) ((x)->ob_type == &SndChannel_Type) + +typedef struct SndChannelObject { + PyObject_HEAD + SndChannelPtr ob_itself; + /* Members used to implement callbacks: */ + PyObject *ob_callback; + long ob_A5; + SndCommand ob_cmd; +} SndChannelObject; + +static PyObject *SndCh_New(itself) + const SndChannelPtr itself; +{ + SndChannelObject *it; + it = PyObject_NEW(SndChannelObject, &SndChannel_Type); + if (it == NULL) return NULL; + it->ob_itself = itself; + it->ob_callback = NULL; + it->ob_A5 = SetCurrentA5(); + return (PyObject *)it; +} +static SndCh_Convert(v, p_itself) + PyObject *v; + SndChannelPtr *p_itself; +{ + if (!SndCh_Check(v)) + { + PyErr_SetString(PyExc_TypeError, "SndChannel required"); + return 0; + } + *p_itself = ((SndChannelObject *)v)->ob_itself; + return 1; +} + +static void SndCh_dealloc(self) + SndChannelObject *self; +{ + SndDisposeChannel(self->ob_itself, 1); + Py_XDECREF(self->ob_callback); + PyMem_DEL(self); +} + +static PyObject *SndCh_SndDoCommand(_self, _args) + SndChannelObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + SndCommand cmd; + Boolean noWait; + if (!PyArg_ParseTuple(_args, "O&b", + SndCmd_Convert, &cmd, + &noWait)) + return NULL; + _err = SndDoCommand(_self->ob_itself, + &cmd, + noWait); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *SndCh_SndDoImmediate(_self, _args) + SndChannelObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + SndCommand cmd; + if (!PyArg_ParseTuple(_args, "O&", + SndCmd_Convert, &cmd)) + return NULL; + _err = SndDoImmediate(_self->ob_itself, + &cmd); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *SndCh_SndPlay(_self, _args) + SndChannelObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + Handle sndHdl; + Boolean async; + if (!PyArg_ParseTuple(_args, "O&b", + ResObj_Convert, &sndHdl, + &async)) + return NULL; + _err = SndPlay(_self->ob_itself, + sndHdl, + async); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *SndCh_SndStartFilePlay(_self, _args) + SndChannelObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + short fRefNum; + short resNum; + long bufferSize; + Boolean async; + if (!PyArg_ParseTuple(_args, "hhlb", + &fRefNum, + &resNum, + &bufferSize, + &async)) + return NULL; + _err = SndStartFilePlay(_self->ob_itself, + fRefNum, + resNum, + bufferSize, + 0, + 0, + 0, + async); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *SndCh_SndPauseFilePlay(_self, _args) + SndChannelObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _err = SndPauseFilePlay(_self->ob_itself); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *SndCh_SndStopFilePlay(_self, _args) + SndChannelObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + Boolean async; + if (!PyArg_ParseTuple(_args, "b", + &async)) + return NULL; + _err = SndStopFilePlay(_self->ob_itself, + async); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *SndCh_SndChannelStatus(_self, _args) + SndChannelObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + short theLength; + SCStatus theStatus__out__; + int theStatus__len__; + if (!PyArg_ParseTuple(_args, "h", + &theLength)) + return NULL; + _err = SndChannelStatus(_self->ob_itself, + theLength, + &theStatus__out__); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("s#", + (char *)&theStatus__out__, sizeof(SCStatus)); + theStatus__error__: ; + return _res; +} + +static PyMethodDef SndCh_methods[] = { + {"SndDoCommand", (PyCFunction)SndCh_SndDoCommand, 1, + "(SndCommand cmd, Boolean noWait) -> None"}, + {"SndDoImmediate", (PyCFunction)SndCh_SndDoImmediate, 1, + "(SndCommand cmd) -> None"}, + {"SndPlay", (PyCFunction)SndCh_SndPlay, 1, + "(Handle sndHdl, Boolean async) -> None"}, + {"SndStartFilePlay", (PyCFunction)SndCh_SndStartFilePlay, 1, + "(short fRefNum, short resNum, long bufferSize, Boolean async) -> None"}, + {"SndPauseFilePlay", (PyCFunction)SndCh_SndPauseFilePlay, 1, + "() -> None"}, + {"SndStopFilePlay", (PyCFunction)SndCh_SndStopFilePlay, 1, + "(Boolean async) -> None"}, + {"SndChannelStatus", (PyCFunction)SndCh_SndChannelStatus, 1, + "(short theLength) -> (SCStatus theStatus)"}, + {NULL, NULL, 0} +}; + +static PyMethodChain SndCh_chain = { SndCh_methods, NULL }; + +static PyObject *SndCh_getattr(self, name) + SndChannelObject *self; + char *name; +{ + return Py_FindMethodInChain(&SndCh_chain, (PyObject *)self, name); +} + +#define SndCh_setattr NULL + +static PyTypeObject SndChannel_Type = { + PyObject_HEAD_INIT(&PyType_Type) + 0, /*ob_size*/ + "SndChannel", /*tp_name*/ + sizeof(SndChannelObject), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + /* methods */ + (destructor) SndCh_dealloc, /*tp_dealloc*/ + 0, /*tp_print*/ + (getattrfunc) SndCh_getattr, /*tp_getattr*/ + (setattrfunc) SndCh_setattr, /*tp_setattr*/ +}; + +/* ------------------- End object type SndChannel ------------------- */ + + +static PyObject *Snd_SndNewChannel(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + SndChannelPtr chan = 0; + short synth; + long init; + PyObject* userRoutine; + if (!PyArg_ParseTuple(_args, "hlO", + &synth, + &init, + &userRoutine)) + return NULL; + if (userRoutine != Py_None && !callable(userRoutine)) + { + PyErr_SetString(PyExc_TypeError, "callback must be callable"); + goto userRoutine__error__; + } + _err = SndNewChannel(&chan, + synth, + init, + (SndCallBackProcPtr)&SndCh_UserRoutine); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&", + SndCh_New, chan); + if (_res != NULL && userRoutine != Py_None) + { + SndChannelObject *p = (SndChannelObject *)_res; + p->ob_itself->userInfo = (long)p; + Py_INCREF(userRoutine); + p->ob_callback = userRoutine; + } + userRoutine__error__: ; + return _res; +} + +static PyObject *Snd_SndControl(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + short id; + SndCommand cmd; + if (!PyArg_ParseTuple(_args, "h", + &id)) + return NULL; + _err = SndControl(id, + &cmd); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("O&", + SndCmd_New, &cmd); + return _res; +} + +static PyObject *Snd_SetSoundVol(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short level; + if (!PyArg_ParseTuple(_args, "h", + &level)) + return NULL; + SetSoundVol(level); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Snd_GetSoundVol(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short level; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + GetSoundVol(&level); + _res = Py_BuildValue("h", + level); + return _res; +} + +static PyObject *Snd_StartSound(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + char *synthRec__in__; + long synthRec__len__; + if (!PyArg_ParseTuple(_args, "s#", + &synthRec__in__, &synthRec__len__)) + return NULL; + StartSound(synthRec__in__, synthRec__len__, + (SndCompletionProcPtr)0); + Py_INCREF(Py_None); + _res = Py_None; + synthRec__error__: ; + return _res; +} + +static PyObject *Snd_StopSound(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + StopSound(); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Snd_SoundDone(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Boolean _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = SoundDone(); + _res = Py_BuildValue("b", + _rv); + return _res; +} + +static PyObject *Snd_SndSoundManagerVersion(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + NumVersion _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = SndSoundManagerVersion(); + _res = Py_BuildValue("O&", + NumVer_New, _rv); + return _res; +} + +static PyObject *Snd_SndManagerStatus(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + short theLength; + SMStatus theStatus__out__; + int theStatus__len__; + if (!PyArg_ParseTuple(_args, "h", + &theLength)) + return NULL; + _err = SndManagerStatus(theLength, + &theStatus__out__); + if (_err != noErr) return PyMac_Error(_err); + _res = Py_BuildValue("s#", + (char *)&theStatus__out__, sizeof(SMStatus)); + theStatus__error__: ; + return _res; +} + +static PyObject *Snd_SndGetSysBeepState(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short sysBeepState; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + SndGetSysBeepState(&sysBeepState); + _res = Py_BuildValue("h", + sysBeepState); + return _res; +} + +static PyObject *Snd_SndSetSysBeepState(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + OSErr _err; + short sysBeepState; + if (!PyArg_ParseTuple(_args, "h", + &sysBeepState)) + return NULL; + _err = SndSetSysBeepState(sysBeepState); + if (_err != noErr) return PyMac_Error(_err); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Snd_MACEVersion(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + NumVersion _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = MACEVersion(); + _res = Py_BuildValue("O&", + NumVer_New, _rv); + return _res; +} + +static PyObject *Snd_Comp3to1(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + char *buffer__in__; + char *buffer__out__; + long buffer__len__; + char *state__in__; + char state__out__[128]; + int state__len__; + unsigned long numChannels; + unsigned long whichChannel; + if (!PyArg_ParseTuple(_args, "s#s#ll", + &buffer__in__, &buffer__len__, + &state__in__, &state__len__, + &numChannels, + &whichChannel)) + return NULL; + if ((buffer__out__ = malloc(buffer__len__)) == NULL) + { + PyErr_NoMemory(); + goto buffer__error__; + } + if (state__len__ != 128) + { + PyErr_SetString(PyExc_TypeError, "buffer length should be 128"); + goto state__error__; + } + Comp3to1(buffer__in__, buffer__out__, buffer__len__, + state__in__, state__out__, + numChannels, + whichChannel); + _res = Py_BuildValue("s#s#", + buffer__out__, buffer__len__, + state__out__, 128); + state__error__: ; + free(buffer__out__); + buffer__error__: ; + return _res; +} + +static PyObject *Snd_Exp1to3(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + char *buffer__in__; + char *buffer__out__; + long buffer__len__; + char *state__in__; + char state__out__[128]; + int state__len__; + unsigned long numChannels; + unsigned long whichChannel; + if (!PyArg_ParseTuple(_args, "s#s#ll", + &buffer__in__, &buffer__len__, + &state__in__, &state__len__, + &numChannels, + &whichChannel)) + return NULL; + if ((buffer__out__ = malloc(buffer__len__)) == NULL) + { + PyErr_NoMemory(); + goto buffer__error__; + } + if (state__len__ != 128) + { + PyErr_SetString(PyExc_TypeError, "buffer length should be 128"); + goto state__error__; + } + Exp1to3(buffer__in__, buffer__out__, buffer__len__, + state__in__, state__out__, + numChannels, + whichChannel); + _res = Py_BuildValue("s#s#", + buffer__out__, buffer__len__, + state__out__, 128); + state__error__: ; + free(buffer__out__); + buffer__error__: ; + return _res; +} + +static PyObject *Snd_Comp6to1(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + char *buffer__in__; + char *buffer__out__; + long buffer__len__; + char *state__in__; + char state__out__[128]; + int state__len__; + unsigned long numChannels; + unsigned long whichChannel; + if (!PyArg_ParseTuple(_args, "s#s#ll", + &buffer__in__, &buffer__len__, + &state__in__, &state__len__, + &numChannels, + &whichChannel)) + return NULL; + if ((buffer__out__ = malloc(buffer__len__)) == NULL) + { + PyErr_NoMemory(); + goto buffer__error__; + } + if (state__len__ != 128) + { + PyErr_SetString(PyExc_TypeError, "buffer length should be 128"); + goto state__error__; + } + Comp6to1(buffer__in__, buffer__out__, buffer__len__, + state__in__, state__out__, + numChannels, + whichChannel); + _res = Py_BuildValue("s#s#", + buffer__out__, buffer__len__, + state__out__, 128); + state__error__: ; + free(buffer__out__); + buffer__error__: ; + return _res; +} + +static PyObject *Snd_Exp1to6(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + char *buffer__in__; + char *buffer__out__; + long buffer__len__; + char *state__in__; + char state__out__[128]; + int state__len__; + unsigned long numChannels; + unsigned long whichChannel; + if (!PyArg_ParseTuple(_args, "s#s#ll", + &buffer__in__, &buffer__len__, + &state__in__, &state__len__, + &numChannels, + &whichChannel)) + return NULL; + if ((buffer__out__ = malloc(buffer__len__)) == NULL) + { + PyErr_NoMemory(); + goto buffer__error__; + } + if (state__len__ != 128) + { + PyErr_SetString(PyExc_TypeError, "buffer length should be 128"); + goto state__error__; + } + Exp1to6(buffer__in__, buffer__out__, buffer__len__, + state__in__, state__out__, + numChannels, + whichChannel); + _res = Py_BuildValue("s#s#", + buffer__out__, buffer__len__, + state__out__, 128); + state__error__: ; + free(buffer__out__); + buffer__error__: ; + return _res; +} + +static PyMethodDef Snd_methods[] = { + {"SndNewChannel", (PyCFunction)Snd_SndNewChannel, 1, + "(short synth, long init, PyObject* userRoutine) -> (SndChannelPtr chan)"}, + {"SndControl", (PyCFunction)Snd_SndControl, 1, + "(short id) -> (SndCommand cmd)"}, + {"SetSoundVol", (PyCFunction)Snd_SetSoundVol, 1, + "(short level) -> None"}, + {"GetSoundVol", (PyCFunction)Snd_GetSoundVol, 1, + "() -> (short level)"}, + {"StartSound", (PyCFunction)Snd_StartSound, 1, + "(Buffer synthRec) -> None"}, + {"StopSound", (PyCFunction)Snd_StopSound, 1, + "() -> None"}, + {"SoundDone", (PyCFunction)Snd_SoundDone, 1, + "() -> (Boolean _rv)"}, + {"SndSoundManagerVersion", (PyCFunction)Snd_SndSoundManagerVersion, 1, + "() -> (NumVersion _rv)"}, + {"SndManagerStatus", (PyCFunction)Snd_SndManagerStatus, 1, + "(short theLength) -> (SMStatus theStatus)"}, + {"SndGetSysBeepState", (PyCFunction)Snd_SndGetSysBeepState, 1, + "() -> (short sysBeepState)"}, + {"SndSetSysBeepState", (PyCFunction)Snd_SndSetSysBeepState, 1, + "(short sysBeepState) -> None"}, + {"MACEVersion", (PyCFunction)Snd_MACEVersion, 1, + "() -> (NumVersion _rv)"}, + {"Comp3to1", (PyCFunction)Snd_Comp3to1, 1, + "(Buffer buffer, Buffer state, unsigned long numChannels, unsigned long whichChannel) -> (Buffer buffer, Buffer state)"}, + {"Exp1to3", (PyCFunction)Snd_Exp1to3, 1, + "(Buffer buffer, Buffer state, unsigned long numChannels, unsigned long whichChannel) -> (Buffer buffer, Buffer state)"}, + {"Comp6to1", (PyCFunction)Snd_Comp6to1, 1, + "(Buffer buffer, Buffer state, unsigned long numChannels, unsigned long whichChannel) -> (Buffer buffer, Buffer state)"}, + {"Exp1to6", (PyCFunction)Snd_Exp1to6, 1, + "(Buffer buffer, Buffer state, unsigned long numChannels, unsigned long whichChannel) -> (Buffer buffer, Buffer state)"}, + {NULL, NULL, 0} +}; + + + +/* Routine passed to Py_AddPendingCall -- call the Python callback */ +static int +SndCh_CallCallBack(arg) + void *arg; +{ + SndChannelObject *p = (SndChannelObject *)arg; + PyObject *args; + PyObject *res; + args = Py_BuildValue("(O(hhl))", + p, p->ob_cmd.cmd, p->ob_cmd.param1, p->ob_cmd.param2); + res = PyEval_CallObject(p->ob_callback, args); + Py_DECREF(args); + if (res == NULL) + return -1; + Py_DECREF(res); + return 0; +} + +/* Routine passed to NewSndChannel -- schedule a call to SndCh_CallCallBack */ +static pascal void +SndCh_UserRoutine(SndChannelPtr chan, SndCommand *cmd) +{ + SndChannelObject *p = (SndChannelObject *)(chan->userInfo); + if (p->ob_callback != NULL) { + long A5 = SetA5(p->ob_A5); + p->ob_cmd = *cmd; + Py_AddPendingCall(SndCh_CallCallBack, (void *)p); + SetA5(A5); + } +} + + +void initSnd() +{ + PyObject *m; + PyObject *d; + + + + + + m = Py_InitModule("Snd", Snd_methods); + d = PyModule_GetDict(m); + Snd_Error = PyMac_GetOSErrException(); + if (Snd_Error == NULL || + PyDict_SetItemString(d, "Error", Snd_Error) != 0) + Py_FatalError("can't initialize Snd.Error"); +} + +/* ========================= End module Snd ========================= */ + diff --git a/Mac/Modules/snd/sndgen.py b/Mac/Modules/snd/sndgen.py new file mode 100644 index 0000000..2c77a1f --- /dev/null +++ b/Mac/Modules/snd/sndgen.py @@ -0,0 +1,131 @@ +# Generated from 'D:Development:THINK C:Mac #includes:Apple #includes:Sound.h' + +f = SndMethod(OSErr, 'SndDoCommand', + (SndChannelPtr, 'chan', InMode), + (SndCommand_ptr, 'cmd', InMode), + (Boolean, 'noWait', InMode), +) +sndmethods.append(f) + +f = SndMethod(OSErr, 'SndDoImmediate', + (SndChannelPtr, 'chan', InMode), + (SndCommand_ptr, 'cmd', InMode), +) +sndmethods.append(f) + +f = SndFunction(OSErr, 'SndNewChannel', + (SndChannelPtr, 'chan', OutMode), + (short, 'synth', InMode), + (long, 'init', InMode), + (SndCallBackProcPtr, 'userRoutine', InMode), +) +functions.append(f) + +f = SndMethod(OSErr, 'SndPlay', + (SndChannelPtr, 'chan', InMode), + (SndListHandle, 'sndHdl', InMode), + (Boolean, 'async', InMode), +) +sndmethods.append(f) + +f = SndFunction(OSErr, 'SndControl', + (short, 'id', InMode), + (SndCommand, 'cmd', OutMode), +) +functions.append(f) + +f = SndFunction(void, 'SetSoundVol', + (short, 'level', InMode), +) +functions.append(f) + +f = SndFunction(void, 'GetSoundVol', + (short, 'level', OutMode), +) +functions.append(f) + +f = SndFunction(NumVersion, 'SndSoundManagerVersion', +) +functions.append(f) + +f = SndMethod(OSErr, 'SndStartFilePlay', + (SndChannelPtr, 'chan', InMode), + (short, 'fRefNum', InMode), + (short, 'resNum', InMode), + (long, 'bufferSize', InMode), + (FakeType('0'), 'theBuffer', InMode), + (AudioSelectionPtr, 'theSelection', InMode), + (ProcPtr, 'theCompletion', InMode), + (Boolean, 'async', InMode), +) +sndmethods.append(f) + +f = SndMethod(OSErr, 'SndPauseFilePlay', + (SndChannelPtr, 'chan', InMode), +) +sndmethods.append(f) + +f = SndMethod(OSErr, 'SndStopFilePlay', + (SndChannelPtr, 'chan', InMode), + (Boolean, 'async', InMode), +) +sndmethods.append(f) + +f = SndMethod(OSErr, 'SndChannelStatus', + (SndChannelPtr, 'chan', InMode), + (short, 'theLength', InMode), + (SCStatus, 'theStatus', OutMode), +) +sndmethods.append(f) + +f = SndFunction(OSErr, 'SndManagerStatus', + (short, 'theLength', InMode), + (SMStatus, 'theStatus', OutMode), +) +functions.append(f) + +f = SndFunction(void, 'SndGetSysBeepState', + (short, 'sysBeepState', OutMode), +) +functions.append(f) + +f = SndFunction(OSErr, 'SndSetSysBeepState', + (short, 'sysBeepState', InMode), +) +functions.append(f) + +f = SndFunction(NumVersion, 'MACEVersion', +) +functions.append(f) + +f = SndFunction(void, 'Comp3to1', + (InOutBuffer, 'buffer', InOutMode), + (InOutBuf128, 'state', InOutMode), + (unsigned_long, 'numChannels', InMode), + (unsigned_long, 'whichChannel', InMode), +) +functions.append(f) + +f = SndFunction(void, 'Exp1to3', + (InOutBuffer, 'buffer', InOutMode), + (InOutBuf128, 'state', InOutMode), + (unsigned_long, 'numChannels', InMode), + (unsigned_long, 'whichChannel', InMode), +) +functions.append(f) + +f = SndFunction(void, 'Comp6to1', + (InOutBuffer, 'buffer', InOutMode), + (InOutBuf128, 'state', InOutMode), + (unsigned_long, 'numChannels', InMode), + (unsigned_long, 'whichChannel', InMode), +) +functions.append(f) + +f = SndFunction(void, 'Exp1to6', + (InOutBuffer, 'buffer', InOutMode), + (InOutBuf128, 'state', InOutMode), + (unsigned_long, 'numChannels', InMode), + (unsigned_long, 'whichChannel', InMode), +) +functions.append(f) diff --git a/Mac/Modules/snd/sndscan.py b/Mac/Modules/snd/sndscan.py new file mode 100644 index 0000000..b63691b --- /dev/null +++ b/Mac/Modules/snd/sndscan.py @@ -0,0 +1,84 @@ +# Scan Sound.h header file, generate sndgen.py and Sound.py files. +# Then import sndsupport (which execs sndgen.py) to generate Sndmodule.c. +# (Should learn how to tell the compiler to compile it as well.) + +from scantools import Scanner + +def main(): + input = "Sound.h" + output = "sndgen.py" + defsoutput = "Sound.py" + scanner = SoundScanner(input, output, defsoutput) + scanner.scan() + scanner.close() + print "=== Done scanning and generating, now doing 'import sndsupport' ===" + import sndsupport + print "=== Done. It's up to you to compile Sndmodule.c ===" + +class SoundScanner(Scanner): + + def destination(self, type, name, arglist): + classname = "SndFunction" + listname = "functions" + if arglist: + t, n, m = arglist[0] + if t == "SndChannelPtr" and m == "InMode": + classname = "SndMethod" + listname = "sndmethods" + return classname, listname + + def makeblacklistnames(self): + return [ + 'SndDisposeChannel', # automatic on deallocation + 'SndAddModifier', # for internal use only + 'SndPlayDoubleBuffer', # very low level routine + # Obsolete: + 'StartSound', + 'StopSound', + 'SoundDone', + + ] + + def makeblacklisttypes(self): + return [ + ] + + def makerepairinstructions(self): + return [ + ([("Str255", "*", "InMode")], + [("*", "*", "OutMode")]), + + ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")], + [("InBuffer", "*", "*")]), + + ([("void", "*", "OutMode"), ("long", "*", "InMode"), + ("long", "*", "OutMode")], + [("VarVarOutBuffer", "*", "InOutMode")]), + + ([("SCStatusPtr", "*", "InMode")], + [("SCStatus", "*", "OutMode")]), + + ([("SMStatusPtr", "*", "InMode")], + [("SMStatus", "*", "OutMode")]), + + # For SndPlay's SndListHandle argument + ([("Handle", "sndHdl", "InMode")], + [("SndListHandle", "*", "*")]), + + # For SndStartFilePlay + ([("long", "bufferSize", "InMode"), ("void", "theBuffer", "OutMode")], + [("*", "*", "*"), ("FakeType('0')", "*", "InMode")]), + + # For Comp3to1 etc. + ([("void_ptr", "inBuffer", "InMode"), + ("void", "outBuffer", "OutMode"), + ("unsigned_long", "cnt", "InMode")], + [("InOutBuffer", "buffer", "InOutMode")]), + + # Ditto + ([("void_ptr", "inState", "InMode"), ("void", "outState", "OutMode")], + [("InOutBuf128", "state", "InOutMode")]), + ] + +if __name__ == "__main__": + main() diff --git a/Mac/Modules/snd/sndsupport.py b/Mac/Modules/snd/sndsupport.py new file mode 100644 index 0000000..3516fa6 --- /dev/null +++ b/Mac/Modules/snd/sndsupport.py @@ -0,0 +1,218 @@ +# This script generates the Sound interface for Python. +# It uses the "bgen" package to generate C code. +# It execs the file sndgen.py which contain the function definitions +# (sndgen.py was generated by sndscan.py, scanning the <Sound.h> header file). + +from macsupport import * + + +# define our own function and module generators + +class SndMixIn: pass + +class SndFunction(SndMixIn, OSErrFunctionGenerator): pass +class SndMethod(SndMixIn, OSErrMethodGenerator): pass + + +# includestuff etc. are imported from macsupport + +includestuff = includestuff + """ +#include <Sound.h> + +#ifndef __MWERKS__ +#define SndCallBackUPP ProcPtr +#define NewSndCallBackProc(x) (x) +#define SndListHandle Handle +#endif +""" + +initstuff = initstuff + """ +""" + + +# define types used for arguments (in addition to standard and macsupport types) + +class SndChannelPtrType(OpaqueByValueType): + def declare(self, name): + # Initializing all SndChannelPtr objects to 0 saves + # special-casing NewSndChannel(), where it is formally an + # input-output parameter but we treat it as output-only + # (since Python users are not supposed to allocate memory) + Output("SndChannelPtr %s = 0;", name) + +SndChannelPtr = SndChannelPtrType('SndChannelPtr', 'SndCh') + +SndCommand = OpaqueType('SndCommand', 'SndCmd') +SndCommand_ptr = OpaqueType('SndCommand', 'SndCmd') +SndListHandle = OpaqueByValueType("SndListHandle", "ResObj") + +class SndCallBackType(InputOnlyType): + def __init__(self): + Type.__init__(self, 'PyObject*', 'O') + def getargsCheck(self, name): + Output("if (%s != Py_None && !callable(%s))", name, name) + OutLbrace() + Output('PyErr_SetString(PyExc_TypeError, "callback must be callable");') + Output("goto %s__error__;", name) + OutRbrace() + def passInput(self, name): + return "(SndCallBackProcPtr)&SndCh_UserRoutine" + def cleanup(self, name): + # XXX This knows it is executing inside the SndNewChannel wrapper + Output("if (_res != NULL && %s != Py_None)", name) + OutLbrace() + Output("SndChannelObject *p = (SndChannelObject *)_res;") + Output("p->ob_itself->userInfo = (long)p;") + Output("Py_INCREF(%s);", name) + Output("p->ob_callback = %s;", name) + OutRbrace() + DedentLevel() + Output(" %s__error__: ;", name) + IndentLevel() + +SndCallBackProcPtr = SndCallBackType() + +SndCompletionProcPtr = FakeType('(SndCompletionProcPtr)0') # XXX + +NumVersion = OpaqueByValueType('NumVersion', 'NumVer') + +InOutBuf128 = FixedInputOutputBufferType(128) + +AudioSelectionPtr = FakeType('0') # XXX + +ProcPtr = FakeType('0') # XXX + +SCStatus = StructOutputBufferType('SCStatus') +SMStatus = StructOutputBufferType('SMStatus') + +includestuff = includestuff + """ +#include <OSUtils.h> /* for Set(Current)A5 */ + +/* Create a SndCommand object (an (int, int, int) tuple) */ +static PyObject * +SndCmd_New(SndCommand *pc) +{ + return Py_BuildValue("hhl", pc->cmd, pc->param1, pc->param2); +} + +/* Convert a SndCommand argument */ +static int +SndCmd_Convert(PyObject *v, SndCommand *pc) +{ + int len; + pc->param1 = 0; + pc->param2 = 0; + if (PyTuple_Check(v)) { + if (PyArg_ParseTuple(v, "h|hl", &pc->cmd, &pc->param1, &pc->param2)) + return 1; + PyErr_Clear(); + return PyArg_ParseTuple(v, "hhs#", &pc->cmd, &pc->param1, &pc->param2, &len); + } + return PyArg_Parse(v, "h", &pc->cmd); +} + +/* Create a NumVersion object (a quintuple of integers) */ +static PyObject * +NumVer_New(NumVersion nv) +{ + return Py_BuildValue("iiiii", + nv.majorRev, +#ifdef THINK_C + nv.minorRev, + nv.bugFixRev, +#else + (nv.minorAndBugRev>>4) & 0xf, + nv.minorAndBugRev & 0xf, +#endif + nv.stage, + nv.nonRelRev); +} + +static pascal void SndCh_UserRoutine(SndChannelPtr chan, SndCommand *cmd); /* Forward */ +""" + + +finalstuff = finalstuff + """ +/* Routine passed to Py_AddPendingCall -- call the Python callback */ +static int +SndCh_CallCallBack(arg) + void *arg; +{ + SndChannelObject *p = (SndChannelObject *)arg; + PyObject *args; + PyObject *res; + args = Py_BuildValue("(O(hhl))", + p, p->ob_cmd.cmd, p->ob_cmd.param1, p->ob_cmd.param2); + res = PyEval_CallObject(p->ob_callback, args); + Py_DECREF(args); + if (res == NULL) + return -1; + Py_DECREF(res); + return 0; +} + +/* Routine passed to NewSndChannel -- schedule a call to SndCh_CallCallBack */ +static pascal void +SndCh_UserRoutine(SndChannelPtr chan, SndCommand *cmd) +{ + SndChannelObject *p = (SndChannelObject *)(chan->userInfo); + if (p->ob_callback != NULL) { + long A5 = SetA5(p->ob_A5); + p->ob_cmd = *cmd; + Py_AddPendingCall(SndCh_CallCallBack, (void *)p); + SetA5(A5); + } +} +""" + + +# create the module and object definition and link them + +class SndObjectDefinition(ObjectDefinition): + + def outputStructMembers(self): + ObjectDefinition.outputStructMembers(self) + Output("/* Members used to implement callbacks: */") + Output("PyObject *ob_callback;") + Output("long ob_A5;"); + Output("SndCommand ob_cmd;") + + def outputInitStructMembers(self): + ObjectDefinition.outputInitStructMembers(self) + Output("it->ob_callback = NULL;") + Output("it->ob_A5 = SetCurrentA5();"); + + def outputCleanupStructMembers(self): + ObjectDefinition.outputCleanupStructMembers(self) + Output("Py_XDECREF(self->ob_callback);") + + def outputFreeIt(self, itselfname): + Output("SndDisposeChannel(%s, 1);", itselfname) + + +sndobject = SndObjectDefinition('SndChannel', 'SndCh', 'SndChannelPtr') +module = MacModule('Snd', 'Snd', includestuff, finalstuff, initstuff) +module.addobject(sndobject) + + +# create lists of functions and object methods + +functions = [] +sndmethods = [] + + +# populate the lists + +execfile('sndgen.py') + + +# add the functions and methods to the module and object, respectively + +for f in functions: module.add(f) +for f in sndmethods: sndobject.add(f) + + +# generate output + +SetOutputFileName('Sndmodule.c') +module.generate() diff --git a/Mac/Modules/win/Winmodule.c b/Mac/Modules/win/Winmodule.c new file mode 100644 index 0000000..3f60d37 --- /dev/null +++ b/Mac/Modules/win/Winmodule.c @@ -0,0 +1,872 @@ + +/* =========================== Module Win =========================== */ + +#include "Python.h" + + + +#define SystemSevenOrLater 1 + +#include "macglue.h" +#include <Memory.h> +#include <Dialogs.h> +#include <Menus.h> +#include <Controls.h> + +extern PyObject *ResObj_New(Handle); +extern int ResObj_Convert(PyObject *, Handle *); + +extern PyObject *WinObj_New(WindowPtr); +extern int WinObj_Convert(PyObject *, WindowPtr *); + +extern PyObject *DlgObj_New(DialogPtr); +extern int DlgObj_Convert(PyObject *, DialogPtr *); +extern PyTypeObject Dialog_Type; +#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type) + +extern PyObject *MenuObj_New(MenuHandle); +extern int MenuObj_Convert(PyObject *, MenuHandle *); + +extern PyObject *CtlObj_New(ControlHandle); +extern int CtlObj_Convert(PyObject *, ControlHandle *); + +extern PyObject *WinObj_WhichWindow(WindowPtr); + +#include <Windows.h> + +#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */ + +#ifdef __MWERKS__ +#define WindowPeek WindowPtr +#endif + +extern PyObject *WinObj_WhichWindow(WindowPtr w); /* Forward */ + +static PyObject *Win_Error; + +/* ----------------------- Object type Window ----------------------- */ + +PyTypeObject Window_Type; + +#define WinObj_Check(x) ((x)->ob_type == &Window_Type) + +typedef struct WindowObject { + PyObject_HEAD + WindowPtr ob_itself; +} WindowObject; + +PyObject *WinObj_New(itself) + const WindowPtr itself; +{ + WindowObject *it; + if (itself == NULL) return PyMac_Error(resNotFound); + it = PyObject_NEW(WindowObject, &Window_Type); + if (it == NULL) return NULL; + it->ob_itself = itself; + SetWRefCon(itself, (long)it); + return (PyObject *)it; +} +WinObj_Convert(v, p_itself) + PyObject *v; + WindowPtr *p_itself; +{ + if (DlgObj_Check(v)) { + *p_itself = ((WindowObject *)v)->ob_itself; + return 1; + } + + if (v == Py_None) { *p_itself = NULL; return 1; } + if (PyInt_Check(v)) { *p_itself = (WindowPtr)PyInt_AsLong(v); return 1; } + + if (!WinObj_Check(v)) + { + PyErr_SetString(PyExc_TypeError, "Window required"); + return 0; + } + *p_itself = ((WindowObject *)v)->ob_itself; + return 1; +} + +static void WinObj_dealloc(self) + WindowObject *self; +{ + DisposeWindow(self->ob_itself); + PyMem_DEL(self); +} + +static PyObject *WinObj_GetWTitle(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Str255 title; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + GetWTitle(_self->ob_itself, + title); + _res = Py_BuildValue("O&", + PyMac_BuildStr255, title); + return _res; +} + +static PyObject *WinObj_SelectWindow(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + SelectWindow(_self->ob_itself); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *WinObj_HideWindow(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + HideWindow(_self->ob_itself); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *WinObj_ShowWindow(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + ShowWindow(_self->ob_itself); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *WinObj_ShowHide(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Boolean showFlag; + if (!PyArg_ParseTuple(_args, "b", + &showFlag)) + return NULL; + ShowHide(_self->ob_itself, + showFlag); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *WinObj_HiliteWindow(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Boolean fHilite; + if (!PyArg_ParseTuple(_args, "b", + &fHilite)) + return NULL; + HiliteWindow(_self->ob_itself, + fHilite); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *WinObj_BringToFront(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + BringToFront(_self->ob_itself); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *WinObj_SendBehind(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + WindowPtr behindWindow; + if (!PyArg_ParseTuple(_args, "O&", + WinObj_Convert, &behindWindow)) + return NULL; + SendBehind(_self->ob_itself, + behindWindow); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *WinObj_DrawGrowIcon(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + DrawGrowIcon(_self->ob_itself); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *WinObj_MoveWindow(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short hGlobal; + short vGlobal; + Boolean front; + if (!PyArg_ParseTuple(_args, "hhb", + &hGlobal, + &vGlobal, + &front)) + return NULL; + MoveWindow(_self->ob_itself, + hGlobal, + vGlobal, + front); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *WinObj_SizeWindow(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short w; + short h; + Boolean fUpdate; + if (!PyArg_ParseTuple(_args, "hhb", + &w, + &h, + &fUpdate)) + return NULL; + SizeWindow(_self->ob_itself, + w, + h, + fUpdate); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *WinObj_ZoomWindow(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short partCode; + Boolean front; + if (!PyArg_ParseTuple(_args, "hb", + &partCode, + &front)) + return NULL; + ZoomWindow(_self->ob_itself, + partCode, + front); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *WinObj_BeginUpdate(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + BeginUpdate(_self->ob_itself); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *WinObj_EndUpdate(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + EndUpdate(_self->ob_itself); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *WinObj_SetWRefCon(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + long data; + if (!PyArg_ParseTuple(_args, "l", + &data)) + return NULL; + SetWRefCon(_self->ob_itself, + data); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *WinObj_GetWRefCon(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + long _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = GetWRefCon(_self->ob_itself); + _res = Py_BuildValue("l", + _rv); + return _res; +} + +static PyObject *WinObj_ClipAbove(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + ClipAbove((WindowPeek)(_self->ob_itself)); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *WinObj_SaveOld(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + SaveOld((WindowPeek)(_self->ob_itself)); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *WinObj_DrawNew(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Boolean update; + if (!PyArg_ParseTuple(_args, "b", + &update)) + return NULL; + DrawNew((WindowPeek)(_self->ob_itself), + update); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *WinObj_CalcVis(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + CalcVis((WindowPeek)(_self->ob_itself)); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *WinObj_GrowWindow(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + long _rv; + Point startPt; + Rect bBox; + if (!PyArg_ParseTuple(_args, "O&O&", + PyMac_GetPoint, &startPt, + PyMac_GetRect, &bBox)) + return NULL; + _rv = GrowWindow(_self->ob_itself, + startPt, + &bBox); + _res = Py_BuildValue("l", + _rv); + return _res; +} + +static PyObject *WinObj_TrackBox(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Boolean _rv; + Point thePt; + short partCode; + if (!PyArg_ParseTuple(_args, "O&h", + PyMac_GetPoint, &thePt, + &partCode)) + return NULL; + _rv = TrackBox(_self->ob_itself, + thePt, + partCode); + _res = Py_BuildValue("b", + _rv); + return _res; +} + +static PyObject *WinObj_GetWVariant(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = GetWVariant(_self->ob_itself); + _res = Py_BuildValue("h", + _rv); + return _res; +} + +static PyObject *WinObj_SetWTitle(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Str255 title; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetStr255, title)) + return NULL; + SetWTitle(_self->ob_itself, + title); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *WinObj_TrackGoAway(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Boolean _rv; + Point thePt; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetPoint, &thePt)) + return NULL; + _rv = TrackGoAway(_self->ob_itself, + thePt); + _res = Py_BuildValue("b", + _rv); + return _res; +} + +static PyObject *WinObj_DragWindow(_self, _args) + WindowObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Point startPt; + Rect boundsRect; + if (!PyArg_ParseTuple(_args, "O&O&", + PyMac_GetPoint, &startPt, + PyMac_GetRect, &boundsRect)) + return NULL; + DragWindow(_self->ob_itself, + startPt, + &boundsRect); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyMethodDef WinObj_methods[] = { + {"GetWTitle", (PyCFunction)WinObj_GetWTitle, 1, + "() -> (Str255 title)"}, + {"SelectWindow", (PyCFunction)WinObj_SelectWindow, 1, + "() -> None"}, + {"HideWindow", (PyCFunction)WinObj_HideWindow, 1, + "() -> None"}, + {"ShowWindow", (PyCFunction)WinObj_ShowWindow, 1, + "() -> None"}, + {"ShowHide", (PyCFunction)WinObj_ShowHide, 1, + "(Boolean showFlag) -> None"}, + {"HiliteWindow", (PyCFunction)WinObj_HiliteWindow, 1, + "(Boolean fHilite) -> None"}, + {"BringToFront", (PyCFunction)WinObj_BringToFront, 1, + "() -> None"}, + {"SendBehind", (PyCFunction)WinObj_SendBehind, 1, + "(WindowPtr behindWindow) -> None"}, + {"DrawGrowIcon", (PyCFunction)WinObj_DrawGrowIcon, 1, + "() -> None"}, + {"MoveWindow", (PyCFunction)WinObj_MoveWindow, 1, + "(short hGlobal, short vGlobal, Boolean front) -> None"}, + {"SizeWindow", (PyCFunction)WinObj_SizeWindow, 1, + "(short w, short h, Boolean fUpdate) -> None"}, + {"ZoomWindow", (PyCFunction)WinObj_ZoomWindow, 1, + "(short partCode, Boolean front) -> None"}, + {"BeginUpdate", (PyCFunction)WinObj_BeginUpdate, 1, + "() -> None"}, + {"EndUpdate", (PyCFunction)WinObj_EndUpdate, 1, + "() -> None"}, + {"SetWRefCon", (PyCFunction)WinObj_SetWRefCon, 1, + "(long data) -> None"}, + {"GetWRefCon", (PyCFunction)WinObj_GetWRefCon, 1, + "() -> (long _rv)"}, + {"ClipAbove", (PyCFunction)WinObj_ClipAbove, 1, + "() -> None"}, + {"SaveOld", (PyCFunction)WinObj_SaveOld, 1, + "() -> None"}, + {"DrawNew", (PyCFunction)WinObj_DrawNew, 1, + "(Boolean update) -> None"}, + {"CalcVis", (PyCFunction)WinObj_CalcVis, 1, + "() -> None"}, + {"GrowWindow", (PyCFunction)WinObj_GrowWindow, 1, + "(Point startPt, Rect bBox) -> (long _rv)"}, + {"TrackBox", (PyCFunction)WinObj_TrackBox, 1, + "(Point thePt, short partCode) -> (Boolean _rv)"}, + {"GetWVariant", (PyCFunction)WinObj_GetWVariant, 1, + "() -> (short _rv)"}, + {"SetWTitle", (PyCFunction)WinObj_SetWTitle, 1, + "(Str255 title) -> None"}, + {"TrackGoAway", (PyCFunction)WinObj_TrackGoAway, 1, + "(Point thePt) -> (Boolean _rv)"}, + {"DragWindow", (PyCFunction)WinObj_DragWindow, 1, + "(Point startPt, Rect boundsRect) -> None"}, + {NULL, NULL, 0} +}; + +PyMethodChain WinObj_chain = { WinObj_methods, NULL }; + +static PyObject *WinObj_getattr(self, name) + WindowObject *self; + char *name; +{ + return Py_FindMethodInChain(&WinObj_chain, (PyObject *)self, name); +} + +#define WinObj_setattr NULL + +PyTypeObject Window_Type = { + PyObject_HEAD_INIT(&PyType_Type) + 0, /*ob_size*/ + "Window", /*tp_name*/ + sizeof(WindowObject), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + /* methods */ + (destructor) WinObj_dealloc, /*tp_dealloc*/ + 0, /*tp_print*/ + (getattrfunc) WinObj_getattr, /*tp_getattr*/ + (setattrfunc) WinObj_setattr, /*tp_setattr*/ +}; + +/* --------------------- End object type Window --------------------- */ + + +static PyObject *Win_InitWindows(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + InitWindows(); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Win_NewWindow(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + WindowPtr _rv; + Rect boundsRect; + Str255 title; + Boolean visible; + short theProc; + WindowPtr behind; + Boolean goAwayFlag; + long refCon; + if (!PyArg_ParseTuple(_args, "O&O&bhO&bl", + PyMac_GetRect, &boundsRect, + PyMac_GetStr255, title, + &visible, + &theProc, + WinObj_Convert, &behind, + &goAwayFlag, + &refCon)) + return NULL; + _rv = NewWindow((void *)0, + &boundsRect, + title, + visible, + theProc, + behind, + goAwayFlag, + refCon); + _res = Py_BuildValue("O&", + WinObj_New, _rv); + return _res; +} + +static PyObject *Win_GetNewWindow(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + WindowPtr _rv; + short windowID; + WindowPtr behind; + if (!PyArg_ParseTuple(_args, "hO&", + &windowID, + WinObj_Convert, &behind)) + return NULL; + _rv = GetNewWindow(windowID, + (void *)0, + behind); + _res = Py_BuildValue("O&", + WinObj_New, _rv); + return _res; +} + +static PyObject *Win_FrontWindow(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + WindowPtr _rv; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = FrontWindow(); + _res = Py_BuildValue("O&", + WinObj_New, _rv); + return _res; +} + +static PyObject *Win_InvalRect(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Rect badRect; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetRect, &badRect)) + return NULL; + InvalRect(&badRect); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Win_ValidRect(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Rect goodRect; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetRect, &goodRect)) + return NULL; + ValidRect(&goodRect); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Win_CheckUpdate(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Boolean _rv; + EventRecord theEvent; + if (!PyArg_ParseTuple(_args, "")) + return NULL; + _rv = CheckUpdate(&theEvent); + _res = Py_BuildValue("bO&", + _rv, + PyMac_BuildEventRecord, &theEvent); + return _res; +} + +static PyObject *Win_FindWindow(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + short _rv; + Point thePoint; + WindowPtr theWindow; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetPoint, &thePoint)) + return NULL; + _rv = FindWindow(thePoint, + &theWindow); + _res = Py_BuildValue("hO&", + _rv, + WinObj_WhichWindow, theWindow); + return _res; +} + +static PyObject *Win_PinRect(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + long _rv; + Rect theRect; + Point thePt; + if (!PyArg_ParseTuple(_args, "O&O&", + PyMac_GetRect, &theRect, + PyMac_GetPoint, &thePt)) + return NULL; + _rv = PinRect(&theRect, + thePt); + _res = Py_BuildValue("l", + _rv); + return _res; +} + +static PyObject *Win_NewCWindow(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + WindowPtr _rv; + Rect boundsRect; + Str255 title; + Boolean visible; + short procID; + WindowPtr behind; + Boolean goAwayFlag; + long refCon; + if (!PyArg_ParseTuple(_args, "O&O&bhO&bl", + PyMac_GetRect, &boundsRect, + PyMac_GetStr255, title, + &visible, + &procID, + WinObj_Convert, &behind, + &goAwayFlag, + &refCon)) + return NULL; + _rv = NewCWindow((void *)0, + &boundsRect, + title, + visible, + procID, + behind, + goAwayFlag, + refCon); + _res = Py_BuildValue("O&", + WinObj_New, _rv); + return _res; +} + +static PyObject *Win_GetNewCWindow(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + WindowPtr _rv; + short windowID; + WindowPtr behind; + if (!PyArg_ParseTuple(_args, "hO&", + &windowID, + WinObj_Convert, &behind)) + return NULL; + _rv = GetNewCWindow(windowID, + (void *)0, + behind); + _res = Py_BuildValue("O&", + WinObj_New, _rv); + return _res; +} + +static PyMethodDef Win_methods[] = { + {"InitWindows", (PyCFunction)Win_InitWindows, 1, + "() -> None"}, + {"NewWindow", (PyCFunction)Win_NewWindow, 1, + "(Rect boundsRect, Str255 title, Boolean visible, short theProc, WindowPtr behind, Boolean goAwayFlag, long refCon) -> (WindowPtr _rv)"}, + {"GetNewWindow", (PyCFunction)Win_GetNewWindow, 1, + "(short windowID, WindowPtr behind) -> (WindowPtr _rv)"}, + {"FrontWindow", (PyCFunction)Win_FrontWindow, 1, + "() -> (WindowPtr _rv)"}, + {"InvalRect", (PyCFunction)Win_InvalRect, 1, + "(Rect badRect) -> None"}, + {"ValidRect", (PyCFunction)Win_ValidRect, 1, + "(Rect goodRect) -> None"}, + {"CheckUpdate", (PyCFunction)Win_CheckUpdate, 1, + "() -> (Boolean _rv, EventRecord theEvent)"}, + {"FindWindow", (PyCFunction)Win_FindWindow, 1, + "(Point thePoint) -> (short _rv, WindowPtr theWindow)"}, + {"PinRect", (PyCFunction)Win_PinRect, 1, + "(Rect theRect, Point thePt) -> (long _rv)"}, + {"NewCWindow", (PyCFunction)Win_NewCWindow, 1, + "(Rect boundsRect, Str255 title, Boolean visible, short procID, WindowPtr behind, Boolean goAwayFlag, long refCon) -> (WindowPtr _rv)"}, + {"GetNewCWindow", (PyCFunction)Win_GetNewCWindow, 1, + "(short windowID, WindowPtr behind) -> (WindowPtr _rv)"}, + {NULL, NULL, 0} +}; + + + +/* Return the object corresponding to the window, or NULL */ + +PyObject * +WinObj_WhichWindow(w) + WindowPtr w; +{ + PyObject *it; + + /* XXX What if we find a stdwin window or a window belonging + to some other package? */ + it = (PyObject *) GetWRefCon(w); + if (it == NULL || ((WindowObject *)it)->ob_itself != w) + it = Py_None; + Py_INCREF(it); + return it; +} + + +void initWin() +{ + PyObject *m; + PyObject *d; + + + + + m = Py_InitModule("Win", Win_methods); + d = PyModule_GetDict(m); + Win_Error = PyMac_GetOSErrException(); + if (Win_Error == NULL || + PyDict_SetItemString(d, "Error", Win_Error) != 0) + Py_FatalError("can't initialize Win.Error"); +} + +/* ========================= End module Win ========================= */ + diff --git a/Mac/Modules/win/wingen.py b/Mac/Modules/win/wingen.py new file mode 100644 index 0000000..a8c0cc2 --- /dev/null +++ b/Mac/Modules/win/wingen.py @@ -0,0 +1,226 @@ +# Generated from 'D:Development:THINK C:Mac #includes:Apple #includes:Windows.h' + +f = Function(void, 'InitWindows', +) +functions.append(f) + +f = Function(WindowPtr, 'NewWindow', + (NullStorage, 'wStorage', InMode), + (Rect_ptr, 'boundsRect', InMode), + (ConstStr255Param, 'title', InMode), + (Boolean, 'visible', InMode), + (short, 'theProc', InMode), + (WindowPtr, 'behind', InMode), + (Boolean, 'goAwayFlag', InMode), + (long, 'refCon', InMode), +) +functions.append(f) + +f = Function(WindowPtr, 'GetNewWindow', + (short, 'windowID', InMode), + (NullStorage, 'wStorage', InMode), + (WindowPtr, 'behind', InMode), +) +functions.append(f) + +f = Method(void, 'GetWTitle', + (WindowPtr, 'theWindow', InMode), + (Str255, 'title', OutMode), +) +methods.append(f) + +f = Method(void, 'SelectWindow', + (WindowPtr, 'theWindow', InMode), +) +methods.append(f) + +f = Method(void, 'HideWindow', + (WindowPtr, 'theWindow', InMode), +) +methods.append(f) + +f = Method(void, 'ShowWindow', + (WindowPtr, 'theWindow', InMode), +) +methods.append(f) + +f = Method(void, 'ShowHide', + (WindowPtr, 'theWindow', InMode), + (Boolean, 'showFlag', InMode), +) +methods.append(f) + +f = Method(void, 'HiliteWindow', + (WindowPtr, 'theWindow', InMode), + (Boolean, 'fHilite', InMode), +) +methods.append(f) + +f = Method(void, 'BringToFront', + (WindowPtr, 'theWindow', InMode), +) +methods.append(f) + +f = Method(void, 'SendBehind', + (WindowPtr, 'theWindow', InMode), + (WindowPtr, 'behindWindow', InMode), +) +methods.append(f) + +f = Function(WindowPtr, 'FrontWindow', +) +functions.append(f) + +f = Method(void, 'DrawGrowIcon', + (WindowPtr, 'theWindow', InMode), +) +methods.append(f) + +f = Method(void, 'MoveWindow', + (WindowPtr, 'theWindow', InMode), + (short, 'hGlobal', InMode), + (short, 'vGlobal', InMode), + (Boolean, 'front', InMode), +) +methods.append(f) + +f = Method(void, 'SizeWindow', + (WindowPtr, 'theWindow', InMode), + (short, 'w', InMode), + (short, 'h', InMode), + (Boolean, 'fUpdate', InMode), +) +methods.append(f) + +f = Method(void, 'ZoomWindow', + (WindowPtr, 'theWindow', InMode), + (short, 'partCode', InMode), + (Boolean, 'front', InMode), +) +methods.append(f) + +f = Function(void, 'InvalRect', + (Rect_ptr, 'badRect', InMode), +) +functions.append(f) + +f = Function(void, 'ValidRect', + (Rect_ptr, 'goodRect', InMode), +) +functions.append(f) + +f = Method(void, 'BeginUpdate', + (WindowPtr, 'theWindow', InMode), +) +methods.append(f) + +f = Method(void, 'EndUpdate', + (WindowPtr, 'theWindow', InMode), +) +methods.append(f) + +f = Method(void, 'SetWRefCon', + (WindowPtr, 'theWindow', InMode), + (long, 'data', InMode), +) +methods.append(f) + +f = Method(long, 'GetWRefCon', + (WindowPtr, 'theWindow', InMode), +) +methods.append(f) + +f = Function(Boolean, 'CheckUpdate', + (EventRecord, 'theEvent', OutMode), +) +functions.append(f) + +f = Method(void, 'ClipAbove', + (WindowPeek, 'window', InMode), +) +methods.append(f) + +f = Method(void, 'SaveOld', + (WindowPeek, 'window', InMode), +) +methods.append(f) + +f = Method(void, 'DrawNew', + (WindowPeek, 'window', InMode), + (Boolean, 'update', InMode), +) +methods.append(f) + +f = Method(void, 'CalcVis', + (WindowPeek, 'window', InMode), +) +methods.append(f) + +f = Method(long, 'GrowWindow', + (WindowPtr, 'theWindow', InMode), + (Point, 'startPt', InMode), + (Rect_ptr, 'bBox', InMode), +) +methods.append(f) + +f = Function(short, 'FindWindow', + (Point, 'thePoint', InMode), + (ExistingWindowPtr, 'theWindow', OutMode), +) +functions.append(f) + +f = Function(long, 'PinRect', + (Rect_ptr, 'theRect', InMode), + (Point, 'thePt', InMode), +) +functions.append(f) + +f = Method(Boolean, 'TrackBox', + (WindowPtr, 'theWindow', InMode), + (Point, 'thePt', InMode), + (short, 'partCode', InMode), +) +methods.append(f) + +f = Function(WindowPtr, 'NewCWindow', + (NullStorage, 'wStorage', InMode), + (Rect_ptr, 'boundsRect', InMode), + (ConstStr255Param, 'title', InMode), + (Boolean, 'visible', InMode), + (short, 'procID', InMode), + (WindowPtr, 'behind', InMode), + (Boolean, 'goAwayFlag', InMode), + (long, 'refCon', InMode), +) +functions.append(f) + +f = Function(WindowPtr, 'GetNewCWindow', + (short, 'windowID', InMode), + (NullStorage, 'wStorage', InMode), + (WindowPtr, 'behind', InMode), +) +functions.append(f) + +f = Method(short, 'GetWVariant', + (WindowPtr, 'theWindow', InMode), +) +methods.append(f) + +f = Method(void, 'SetWTitle', + (WindowPtr, 'theWindow', InMode), + (ConstStr255Param, 'title', InMode), +) +methods.append(f) + +f = Method(Boolean, 'TrackGoAway', + (WindowPtr, 'theWindow', InMode), + (Point, 'thePt', InMode), +) +methods.append(f) + +f = Method(void, 'DragWindow', + (WindowPtr, 'theWindow', InMode), + (Point, 'startPt', InMode), + (Rect_ptr, 'boundsRect', InMode), +) +methods.append(f) diff --git a/Mac/Modules/win/winscan.py b/Mac/Modules/win/winscan.py new file mode 100644 index 0000000..6ae03f4 --- /dev/null +++ b/Mac/Modules/win/winscan.py @@ -0,0 +1,68 @@ +# Scan an Apple header file, generating a Python file of generator calls. + +from scantools import Scanner + +def main(): + input = "Windows.h" + output = "wingen.py" + defsoutput = "Windows.py" + scanner = MyScanner(input, output, defsoutput) + scanner.scan() + scanner.close() + print "=== Done scanning and generating, now importing the generated code... ===" + import winsupport + print "=== Done. It's up to you to compile it now! ===" + +class MyScanner(Scanner): + + def destination(self, type, name, arglist): + classname = "Function" + listname = "functions" + if arglist: + t, n, m = arglist[0] + if t in ("WindowPtr", "WindowPeek") and m == "InMode": + classname = "Method" + listname = "methods" + return classname, listname + + def makeblacklistnames(self): + return [ + 'DisposeWindow', # Implied when the object is deleted + 'CloseWindow', + ] + + def makeblacklisttypes(self): + return [ + 'ProcPtr', + 'GrafPtr', + 'CGrafPtr', + 'RgnHandle', + 'PicHandle', + 'WCTabHandle', + 'AuxWinHandle', + 'PixPatHandle', + ] + + def makerepairinstructions(self): + return [ + + # GetWTitle + ([("Str255", "*", "InMode")], + [("*", "*", "OutMode")]), + + ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")], + [("InBuffer", "*", "*")]), + + ([("void", "*", "OutMode"), ("long", "*", "InMode"), + ("long", "*", "OutMode")], + [("VarVarOutBuffer", "*", "InOutMode")]), + + ([("void", "wStorage", "OutMode")], + [("NullStorage", "*", "InMode")]), + + ([("WindowPtr", "*", "OutMode")], + [("ExistingWindowPtr", "*", "*")]), + ] + +if __name__ == "__main__": + main() diff --git a/Mac/Modules/win/winsupport.py b/Mac/Modules/win/winsupport.py new file mode 100644 index 0000000..c1057e2 --- /dev/null +++ b/Mac/Modules/win/winsupport.py @@ -0,0 +1,103 @@ +# This script generates a Python interface for an Apple Macintosh Manager. +# It uses the "bgen" package to generate C code. +# The function specifications are generated by scanning the mamager's header file, +# using the "scantools" package (customized for this particular manager). + +import string + +# Declarations that change for each manager +MACHEADERFILE = 'Windows.h' # The Apple header file +MODNAME = 'Win' # The name of the module +OBJECTNAME = 'Window' # The basic name of the objects used here + +# The following is *usually* unchanged but may still require tuning +MODPREFIX = MODNAME # The prefix for module-wide routines +OBJECTTYPE = OBJECTNAME + 'Ptr' # The C type used to represent them +OBJECTPREFIX = MODPREFIX + 'Obj' # The prefix for object methods +INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner +OUTPUTFILE = MODNAME + "module.c" # The file generated by this program + +from macsupport import * + +# Create the type objects + +WindowPtr = OpaqueByValueType(OBJECTTYPE, OBJECTPREFIX) +WindowPeek = OpaqueByValueType("WindowPeek", OBJECTPREFIX) +WindowPeek.passInput = lambda name: "(WindowPeek)(%s)" % name + +#RgnHandle = FakeType("theWindow->updtRgn") # XXX + +includestuff = includestuff + """ +#include <%s>""" % MACHEADERFILE + """ + +#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */ + +#ifdef __MWERKS__ +#define WindowPeek WindowPtr +#endif +""" + +finalstuff = finalstuff + """ +/* Return the object corresponding to the window, or NULL */ + +PyObject * +WinObj_WhichWindow(w) + WindowPtr w; +{ + PyObject *it; + + /* XXX What if we find a stdwin window or a window belonging + to some other package? */ + if (w == NULL) + it = NULL; + else + it = (PyObject *) GetWRefCon(w); + if (it == NULL || ((WindowObject *)it)->ob_itself != w) + it = Py_None; + Py_INCREF(it); + return it; +} +""" + +class MyObjectDefinition(GlobalObjectDefinition): + def outputCheckNewArg(self): + Output("if (itself == NULL) return PyMac_Error(resNotFound);") + def outputInitStructMembers(self): + GlobalObjectDefinition.outputInitStructMembers(self) + Output("SetWRefCon(itself, (long)it);") + def outputCheckConvertArg(self): + OutLbrace("if (DlgObj_Check(v))") + Output("*p_itself = ((WindowObject *)v)->ob_itself;") + Output("return 1;") + OutRbrace() + Out(""" + if (v == Py_None) { *p_itself = NULL; return 1; } + if (PyInt_Check(v)) { *p_itself = (WindowPtr)PyInt_AsLong(v); return 1; } + """) + def outputFreeIt(self, itselfname): + Output("DisposeWindow(%s);", itselfname) + +# From here on it's basically all boiler plate... + +# Create the generator groups and link them +module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff) +object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE) +module.addobject(object) + +# Create the generator classes used to populate the lists +Function = OSErrFunctionGenerator +Method = OSErrMethodGenerator + +# Create and populate the lists +functions = [] +methods = [] +execfile(INPUTFILE) + +# add the populated lists to the generator groups +# (in a different wordl the scan program would generate this) +for f in functions: module.add(f) +for f in methods: object.add(f) + +# generate output (open the output file as late as possible) +SetOutputFileName(OUTPUTFILE) +module.generate() |