Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9bcb641

Browse files
committed
added Resource(), to create new resources from Python
1 parent 0818a4c commit 9bcb641

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

Mac/Modules/res/Resmodule.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ extern int MenuObj_Convert(PyObject *, MenuHandle *);
3030
extern PyObject *CtlObj_New(ControlHandle);
3131
extern int CtlObj_Convert(PyObject *, ControlHandle *);
3232

33+
extern PyObject *WinObj_WhichWindow(WindowPtr);
34+
3335
#include <Resources.h>
3436

3537
#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
@@ -1161,6 +1163,30 @@ static PyObject *Res_FSpCreateResFile(_self, _args)
11611163
return _res;
11621164
}
11631165

1166+
static PyObject *Res_Resource(_self, _args)
1167+
PyObject *_self;
1168+
PyObject *_args;
1169+
{
1170+
PyObject *_res = NULL;
1171+
1172+
char *buf;
1173+
int len;
1174+
Handle h;
1175+
1176+
if (!PyArg_ParseTuple(_args, "s#", &buf, &len))
1177+
return NULL;
1178+
h = NewHandle(len);
1179+
if ( h == NULL ) {
1180+
PyErr_NoMemory();
1181+
return NULL;
1182+
}
1183+
HLock(h);
1184+
memcpy(*h, buf, len);
1185+
HUnlock(h);
1186+
return (PyObject *)ResObj_New(h);
1187+
1188+
}
1189+
11641190
static PyMethodDef Res_methods[] = {
11651191
{"InitResources", (PyCFunction)Res_InitResources, 1,
11661192
"() -> (short _rv)"},
@@ -1228,6 +1254,8 @@ static PyMethodDef Res_methods[] = {
12281254
"(FSSpec spec, SignedByte permission) -> (short _rv)"},
12291255
{"FSpCreateResFile", (PyCFunction)Res_FSpCreateResFile, 1,
12301256
"(FSSpec spec, OSType creator, OSType fileType, ScriptCode scriptTag) -> None"},
1257+
{"Resource", (PyCFunction)Res_Resource, 1,
1258+
"Convert a string to a resource object.\n\nThe created resource object is actually just a handle.\nApply AddResource() to write it to a resource file.\n"},
12311259
{NULL, NULL, 0}
12321260
};
12331261

Mac/Modules/res/ressupport.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def outputGetattrHook(self):
6969
resmethods = []
7070

7171
execfile('resgen.py')
72+
execfile('resedit.py')
7273

7374
for f in functions: module.add(f)
7475
for f in resmethods: resobject.add(f)

0 commit comments

Comments
 (0)