Guido van Rossum | 81920f1 | 1995-02-05 17:01:24 +0000 | [diff] [blame] | 1 | resource_body = """ |
| 2 | char *buf; |
| 3 | int len; |
| 4 | Handle h; |
| 5 | |
| 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; |
| 12 | } |
| 13 | HLock(h); |
| 14 | memcpy(*h, buf, len); |
| 15 | HUnlock(h); |
| 16 | return (PyObject *)ResObj_New(h); |
| 17 | """ |
| 18 | |
| 19 | f = ManualGenerator("Resource", resource_body) |
| 20 | f.docstring = lambda: """Convert a string to a resource object. |
| 21 | |
| 22 | The created resource object is actually just a handle. |
| 23 | Apply AddResource() to write it to a resource file. |
| 24 | """ |
| 25 | functions.append(f) |
Jack Jansen | 1e05402 | 1995-06-18 20:20:27 +0000 | [diff] [blame] | 26 | |
| 27 | # Convert resources to other things. |
| 28 | |
| 29 | as_xxx_body = """ |
| 30 | return %sObj_New((%sHandle)_self->ob_itself); |
| 31 | """ |
| 32 | |
| 33 | def genresconverter(longname, shortname): |
| 34 | |
| 35 | f = ManualGenerator("as_%s"%longname, as_xxx_body%(shortname, longname)) |
| 36 | docstring = "Return this resource/handle as a %s"%longname |
| 37 | f.docstring = lambda docstring=docstring: docstring |
| 38 | return f |
| 39 | |
| 40 | resmethods.append(genresconverter("Control", "Ctl")) |
| 41 | resmethods.append(genresconverter("Menu", "Menu")) |
Jack Jansen | e180d99 | 1998-04-24 10:28:20 +0000 | [diff] [blame] | 42 | |
| 43 | # The definition of this one is MacLoadResource, so we do it by hand... |
| 44 | |
| 45 | f = ResMethod(void, 'LoadResource', |
| 46 | (Handle, 'theResource', InMode), |
| 47 | ) |
| 48 | resmethods.append(f) |