1995-02-05 13:01:24 -04:00
|
|
|
resource_body = """
|
|
|
|
char *buf;
|
|
|
|
int len;
|
|
|
|
Handle h;
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple(_args, "s#", &buf, &len))
|
|
|
|
return NULL;
|
|
|
|
h = NewHandle(len);
|
|
|
|
if ( h == NULL ) {
|
|
|
|
PyErr_NoMemory();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
HLock(h);
|
|
|
|
memcpy(*h, buf, len);
|
|
|
|
HUnlock(h);
|
2001-09-05 12:44:37 -03:00
|
|
|
_res = ResObj_New(h);
|
|
|
|
return _res;
|
1995-02-05 13:01:24 -04:00
|
|
|
"""
|
|
|
|
|
|
|
|
f = ManualGenerator("Resource", resource_body)
|
|
|
|
f.docstring = lambda: """Convert a string to a resource object.
|
|
|
|
|
2000-03-08 12:58:15 -04:00
|
|
|
The created resource object is actually just a handle,
|
|
|
|
apply AddResource() to write it to a resource file.
|
|
|
|
See also the Handle() docstring.
|
|
|
|
"""
|
|
|
|
functions.append(f)
|
|
|
|
|
|
|
|
handle_body = """
|
|
|
|
char *buf;
|
|
|
|
int len;
|
|
|
|
Handle h;
|
|
|
|
ResourceObject *rv;
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple(_args, "s#", &buf, &len))
|
|
|
|
return NULL;
|
|
|
|
h = NewHandle(len);
|
|
|
|
if ( h == NULL ) {
|
|
|
|
PyErr_NoMemory();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
HLock(h);
|
|
|
|
memcpy(*h, buf, len);
|
|
|
|
HUnlock(h);
|
|
|
|
rv = (ResourceObject *)ResObj_New(h);
|
|
|
|
rv->ob_freeit = PyMac_AutoDisposeHandle;
|
2001-09-05 12:44:37 -03:00
|
|
|
_res = (PyObject *)rv;
|
|
|
|
return _res;
|
2000-03-08 12:58:15 -04:00
|
|
|
"""
|
|
|
|
|
|
|
|
f = ManualGenerator("Handle", handle_body)
|
|
|
|
f.docstring = lambda: """Convert a string to a Handle object.
|
|
|
|
|
|
|
|
Resource() and Handle() are very similar, but objects created with Handle() are
|
|
|
|
by default automatically DisposeHandle()d upon object cleanup. Use AutoDispose()
|
|
|
|
to change this.
|
1995-02-05 13:01:24 -04:00
|
|
|
"""
|
|
|
|
functions.append(f)
|
1995-06-18 17:20:27 -03:00
|
|
|
|
|
|
|
# Convert resources to other things.
|
|
|
|
|
|
|
|
as_xxx_body = """
|
2001-09-05 07:31:52 -03:00
|
|
|
_res = %sObj_New((%sHandle)_self->ob_itself);
|
|
|
|
return _res;
|
1995-06-18 17:20:27 -03:00
|
|
|
"""
|
|
|
|
|
|
|
|
def genresconverter(longname, shortname):
|
|
|
|
|
|
|
|
f = ManualGenerator("as_%s"%longname, as_xxx_body%(shortname, longname))
|
|
|
|
docstring = "Return this resource/handle as a %s"%longname
|
|
|
|
f.docstring = lambda docstring=docstring: docstring
|
|
|
|
return f
|
|
|
|
|
|
|
|
resmethods.append(genresconverter("Control", "Ctl"))
|
|
|
|
resmethods.append(genresconverter("Menu", "Menu"))
|
1998-04-24 07:28:20 -03:00
|
|
|
|
|
|
|
# The definition of this one is MacLoadResource, so we do it by hand...
|
|
|
|
|
|
|
|
f = ResMethod(void, 'LoadResource',
|
|
|
|
(Handle, 'theResource', InMode),
|
|
|
|
)
|
|
|
|
resmethods.append(f)
|
2000-03-08 12:58:15 -04:00
|
|
|
|
|
|
|
#
|
|
|
|
# A method to set the auto-dispose flag
|
|
|
|
#
|
|
|
|
AutoDispose_body = """
|
|
|
|
int onoff, old = 0;
|
|
|
|
if (!PyArg_ParseTuple(_args, "i", &onoff))
|
|
|
|
return NULL;
|
|
|
|
if ( _self->ob_freeit )
|
|
|
|
old = 1;
|
|
|
|
if ( onoff )
|
|
|
|
_self->ob_freeit = PyMac_AutoDisposeHandle;
|
|
|
|
else
|
|
|
|
_self->ob_freeit = NULL;
|
2001-09-05 12:44:37 -03:00
|
|
|
_res = Py_BuildValue("i", old);
|
|
|
|
return _res;
|
2000-03-08 12:58:15 -04:00
|
|
|
"""
|
|
|
|
f = ManualGenerator("AutoDispose", AutoDispose_body)
|
|
|
|
f.docstring = lambda: "(int)->int. Automatically DisposeHandle the object on Python object cleanup"
|
|
|
|
resmethods.append(f)
|