Teach Windows build and installer about new _symtable module/DLL.
[python/dscho.git] / Mac / Modules / res / resedit.py
blob16848704b5d0476b9c84f420eab888fd631f7c73
1 resource_body = """
2 char *buf;
3 int len;
4 Handle h;
6 if (!PyArg_ParseTuple(_args, "s#", &buf, &len))
7 return NULL;
8 h = NewHandle(len);
9 if ( h == NULL ) {
10 PyErr_NoMemory();
11 return NULL;
13 HLock(h);
14 memcpy(*h, buf, len);
15 HUnlock(h);
16 return ResObj_New(h);
17 """
19 f = ManualGenerator("Resource", resource_body)
20 f.docstring = lambda: """Convert a string to a resource object.
22 The created resource object is actually just a handle,
23 apply AddResource() to write it to a resource file.
24 See also the Handle() docstring.
25 """
26 functions.append(f)
28 handle_body = """
29 char *buf;
30 int len;
31 Handle h;
32 ResourceObject *rv;
34 if (!PyArg_ParseTuple(_args, "s#", &buf, &len))
35 return NULL;
36 h = NewHandle(len);
37 if ( h == NULL ) {
38 PyErr_NoMemory();
39 return NULL;
41 HLock(h);
42 memcpy(*h, buf, len);
43 HUnlock(h);
44 rv = (ResourceObject *)ResObj_New(h);
45 rv->ob_freeit = PyMac_AutoDisposeHandle;
46 return (PyObject *)rv;
47 """
49 f = ManualGenerator("Handle", handle_body)
50 f.docstring = lambda: """Convert a string to a Handle object.
52 Resource() and Handle() are very similar, but objects created with Handle() are
53 by default automatically DisposeHandle()d upon object cleanup. Use AutoDispose()
54 to change this.
55 """
56 functions.append(f)
58 # Convert resources to other things.
60 as_xxx_body = """
61 return %sObj_New((%sHandle)_self->ob_itself);
62 """
64 def genresconverter(longname, shortname):
66 f = ManualGenerator("as_%s"%longname, as_xxx_body%(shortname, longname))
67 docstring = "Return this resource/handle as a %s"%longname
68 f.docstring = lambda docstring=docstring: docstring
69 return f
71 resmethods.append(genresconverter("Control", "Ctl"))
72 resmethods.append(genresconverter("Menu", "Menu"))
74 # The definition of this one is MacLoadResource, so we do it by hand...
76 f = ResMethod(void, 'LoadResource',
77 (Handle, 'theResource', InMode),
79 resmethods.append(f)
82 # A method to set the auto-dispose flag
84 AutoDispose_body = """
85 int onoff, old = 0;
86 if (!PyArg_ParseTuple(_args, "i", &onoff))
87 return NULL;
88 if ( _self->ob_freeit )
89 old = 1;
90 if ( onoff )
91 _self->ob_freeit = PyMac_AutoDisposeHandle;
92 else
93 _self->ob_freeit = NULL;
94 return Py_BuildValue("i", old);
95 """
96 f = ManualGenerator("AutoDispose", AutoDispose_body)
97 f.docstring = lambda: "(int)->int. Automatically DisposeHandle the object on Python object cleanup"
98 resmethods.append(f)