6 ##if (!PyArg_ParseTuple(_args, "s#", &buf, &len))
14 ##memcpy(*h, buf, len);
16 ##_res = ResObj_New(h);
20 ##f = ManualGenerator("Resource", resource_body)
21 ##f.docstring = lambda: """Convert a string to a resource object.
23 ##The created resource object is actually just a handle,
24 ##apply AddResource() to write it to a resource file.
25 ##See also the Handle() docstring.
35 if (!PyArg_ParseTuple(_args, "s#", &buf, &len))
45 rv = (ResourceObject *)ResObj_New(h);
46 rv->ob_freeit = PyMac_AutoDisposeHandle;
47 _res = (PyObject *)rv;
51 f
= ManualGenerator("Handle", handle_body
)
52 f
.docstring
= lambda: """Convert a string to a Handle object.
54 Resource() and Handle() are very similar, but objects created with Handle() are
55 by default automatically DisposeHandle()d upon object cleanup. Use AutoDispose()
60 # Convert resources to other things.
63 _res = %sObj_New((%sHandle)_self->ob_itself);
67 def genresconverter(longname
, shortname
):
69 f
= ManualGenerator("as_%s"%longname
, as_xxx_body
%(shortname
, longname
))
70 docstring
= "Return this resource/handle as a %s"%longname
71 f
.docstring
= lambda docstring
=docstring
: docstring
74 resmethods
.append(genresconverter("Control", "Ctl"))
75 resmethods
.append(genresconverter("Menu", "Menu"))
77 # The definition of this one is MacLoadResource, so we do it by hand...
79 f
= ResMethod(void
, 'LoadResource',
80 (Handle
, 'theResource', InMode
),
85 # A method to set the auto-dispose flag
87 AutoDispose_body
= """
89 if (!PyArg_ParseTuple(_args, "i", &onoff))
91 if ( _self->ob_freeit )
94 _self->ob_freeit = PyMac_AutoDisposeHandle;
96 _self->ob_freeit = NULL;
97 _res = Py_BuildValue("i", old);
100 f
= ManualGenerator("AutoDispose", AutoDispose_body
)
101 f
.docstring
= lambda: "(int)->int. Automatically DisposeHandle the object on Python object cleanup"