diff options
author | Guido van Rossum <guido@python.org> | 1995-01-30 11:53:55 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1995-01-30 11:53:55 (GMT) |
commit | 17448e24081eb713ac00d7bcb681f4f0d8abfcbf (patch) | |
tree | 4f9d6768ef326173e1141b1a92af63247a42b13a /Mac/Modules/res | |
parent | 80ffd6683ca7b06ed743c629459b06b07defbfb3 (diff) | |
download | cpython-17448e24081eb713ac00d7bcb681f4f0d8abfcbf.zip cpython-17448e24081eb713ac00d7bcb681f4f0d8abfcbf.tar.gz cpython-17448e24081eb713ac00d7bcb681f4f0d8abfcbf.tar.bz2 |
Committed a more or less working version.
Diffstat (limited to 'Mac/Modules/res')
-rw-r--r-- | Mac/Modules/res/Resmodule.c | 1256 | ||||
-rw-r--r-- | Mac/Modules/res/resgen.py | 271 | ||||
-rw-r--r-- | Mac/Modules/res/resscan.py | 60 | ||||
-rw-r--r-- | Mac/Modules/res/ressupport.py | 77 |
4 files changed, 1664 insertions, 0 deletions
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() |