Mercurial > cpython-lru_cache-weakref
annotate Mac/Modules/res/resedit.py @ 54294:dba767bc3155 legacy-trunk
remove mention of old ctypes version
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Sat, 23 May 2009 20:59:09 +0000 |
| parents | c3a096bfbd6b |
| children |
| rev | line source |
|---|---|
|
26545
8a75c66bfa14
Fixed so the Res.Resource() accepts either another resource, a string
Jack Jansen <jack.jansen@cwi.nl>
parents:
19734
diff
changeset
|
1 ##resource_body = """ |
|
8a75c66bfa14
Fixed so the Res.Resource() accepts either another resource, a string
Jack Jansen <jack.jansen@cwi.nl>
parents:
19734
diff
changeset
|
2 ##char *buf; |
|
8a75c66bfa14
Fixed so the Res.Resource() accepts either another resource, a string
Jack Jansen <jack.jansen@cwi.nl>
parents:
19734
diff
changeset
|
3 ##int len; |
|
8a75c66bfa14
Fixed so the Res.Resource() accepts either another resource, a string
Jack Jansen <jack.jansen@cwi.nl>
parents:
19734
diff
changeset
|
4 ##Handle h; |
|
8a75c66bfa14
Fixed so the Res.Resource() accepts either another resource, a string
Jack Jansen <jack.jansen@cwi.nl>
parents:
19734
diff
changeset
|
5 ## |
|
8a75c66bfa14
Fixed so the Res.Resource() accepts either another resource, a string
Jack Jansen <jack.jansen@cwi.nl>
parents:
19734
diff
changeset
|
6 ##if (!PyArg_ParseTuple(_args, "s#", &buf, &len)) |
|
32736
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
26545
diff
changeset
|
7 ## return NULL; |
|
26545
8a75c66bfa14
Fixed so the Res.Resource() accepts either another resource, a string
Jack Jansen <jack.jansen@cwi.nl>
parents:
19734
diff
changeset
|
8 ##h = NewHandle(len); |
|
8a75c66bfa14
Fixed so the Res.Resource() accepts either another resource, a string
Jack Jansen <jack.jansen@cwi.nl>
parents:
19734
diff
changeset
|
9 ##if ( h == NULL ) { |
|
32736
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
26545
diff
changeset
|
10 ## PyErr_NoMemory(); |
|
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
26545
diff
changeset
|
11 ## return NULL; |
|
26545
8a75c66bfa14
Fixed so the Res.Resource() accepts either another resource, a string
Jack Jansen <jack.jansen@cwi.nl>
parents:
19734
diff
changeset
|
12 ##} |
|
8a75c66bfa14
Fixed so the Res.Resource() accepts either another resource, a string
Jack Jansen <jack.jansen@cwi.nl>
parents:
19734
diff
changeset
|
13 ##HLock(h); |
|
8a75c66bfa14
Fixed so the Res.Resource() accepts either another resource, a string
Jack Jansen <jack.jansen@cwi.nl>
parents:
19734
diff
changeset
|
14 ##memcpy(*h, buf, len); |
|
8a75c66bfa14
Fixed so the Res.Resource() accepts either another resource, a string
Jack Jansen <jack.jansen@cwi.nl>
parents:
19734
diff
changeset
|
15 ##HUnlock(h); |
|
8a75c66bfa14
Fixed so the Res.Resource() accepts either another resource, a string
Jack Jansen <jack.jansen@cwi.nl>
parents:
19734
diff
changeset
|
16 ##_res = ResObj_New(h); |
|
8a75c66bfa14
Fixed so the Res.Resource() accepts either another resource, a string
Jack Jansen <jack.jansen@cwi.nl>
parents:
19734
diff
changeset
|
17 ##return _res; |
|
8a75c66bfa14
Fixed so the Res.Resource() accepts either another resource, a string
Jack Jansen <jack.jansen@cwi.nl>
parents:
19734
diff
changeset
|
18 ##""" |
|
8a75c66bfa14
Fixed so the Res.Resource() accepts either another resource, a string
Jack Jansen <jack.jansen@cwi.nl>
parents:
19734
diff
changeset
|
19 ## |
|
8a75c66bfa14
Fixed so the Res.Resource() accepts either another resource, a string
Jack Jansen <jack.jansen@cwi.nl>
parents:
19734
diff
changeset
|
20 ##f = ManualGenerator("Resource", resource_body) |
|
8a75c66bfa14
Fixed so the Res.Resource() accepts either another resource, a string
Jack Jansen <jack.jansen@cwi.nl>
parents:
19734
diff
changeset
|
21 ##f.docstring = lambda: """Convert a string to a resource object. |
|
8a75c66bfa14
Fixed so the Res.Resource() accepts either another resource, a string
Jack Jansen <jack.jansen@cwi.nl>
parents:
19734
diff
changeset
|
22 ## |
|
8a75c66bfa14
Fixed so the Res.Resource() accepts either another resource, a string
Jack Jansen <jack.jansen@cwi.nl>
parents:
19734
diff
changeset
|
23 ##The created resource object is actually just a handle, |
|
8a75c66bfa14
Fixed so the Res.Resource() accepts either another resource, a string
Jack Jansen <jack.jansen@cwi.nl>
parents:
19734
diff
changeset
|
24 ##apply AddResource() to write it to a resource file. |
|
8a75c66bfa14
Fixed so the Res.Resource() accepts either another resource, a string
Jack Jansen <jack.jansen@cwi.nl>
parents:
19734
diff
changeset
|
25 ##See also the Handle() docstring. |
|
8a75c66bfa14
Fixed so the Res.Resource() accepts either another resource, a string
Jack Jansen <jack.jansen@cwi.nl>
parents:
19734
diff
changeset
|
26 ##""" |
|
8a75c66bfa14
Fixed so the Res.Resource() accepts either another resource, a string
Jack Jansen <jack.jansen@cwi.nl>
parents:
19734
diff
changeset
|
27 ##functions.append(f) |
|
11951
addea1157aa7
Handles were never disposed. Added an AutoDispose(onoff) method to control this.
Jack Jansen <jack.jansen@cwi.nl>
parents:
8135
diff
changeset
|
28 |
|
addea1157aa7
Handles were never disposed. Added an AutoDispose(onoff) method to control this.
Jack Jansen <jack.jansen@cwi.nl>
parents:
8135
diff
changeset
|
29 handle_body = """ |
|
addea1157aa7
Handles were never disposed. Added an AutoDispose(onoff) method to control this.
Jack Jansen <jack.jansen@cwi.nl>
parents:
8135
diff
changeset
|
30 char *buf; |
|
addea1157aa7
Handles were never disposed. Added an AutoDispose(onoff) method to control this.
Jack Jansen <jack.jansen@cwi.nl>
parents:
8135
diff
changeset
|
31 int len; |
|
addea1157aa7
Handles were never disposed. Added an AutoDispose(onoff) method to control this.
Jack Jansen <jack.jansen@cwi.nl>
parents:
8135
diff
changeset
|
32 Handle h; |
|
addea1157aa7
Handles were never disposed. Added an AutoDispose(onoff) method to control this.
Jack Jansen <jack.jansen@cwi.nl>
parents:
8135
diff
changeset
|
33 ResourceObject *rv; |
|
addea1157aa7
Handles were never disposed. Added an AutoDispose(onoff) method to control this.
Jack Jansen <jack.jansen@cwi.nl>
parents:
8135
diff
changeset
|
34 |
|
addea1157aa7
Handles were never disposed. Added an AutoDispose(onoff) method to control this.
Jack Jansen <jack.jansen@cwi.nl>
parents:
8135
diff
changeset
|
35 if (!PyArg_ParseTuple(_args, "s#", &buf, &len)) |
|
32736
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
26545
diff
changeset
|
36 return NULL; |
|
11951
addea1157aa7
Handles were never disposed. Added an AutoDispose(onoff) method to control this.
Jack Jansen <jack.jansen@cwi.nl>
parents:
8135
diff
changeset
|
37 h = NewHandle(len); |
|
addea1157aa7
Handles were never disposed. Added an AutoDispose(onoff) method to control this.
Jack Jansen <jack.jansen@cwi.nl>
parents:
8135
diff
changeset
|
38 if ( h == NULL ) { |
|
32736
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
26545
diff
changeset
|
39 PyErr_NoMemory(); |
|
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
26545
diff
changeset
|
40 return NULL; |
|
11951
addea1157aa7
Handles were never disposed. Added an AutoDispose(onoff) method to control this.
Jack Jansen <jack.jansen@cwi.nl>
parents:
8135
diff
changeset
|
41 } |
|
addea1157aa7
Handles were never disposed. Added an AutoDispose(onoff) method to control this.
Jack Jansen <jack.jansen@cwi.nl>
parents:
8135
diff
changeset
|
42 HLock(h); |
|
addea1157aa7
Handles were never disposed. Added an AutoDispose(onoff) method to control this.
Jack Jansen <jack.jansen@cwi.nl>
parents:
8135
diff
changeset
|
43 memcpy(*h, buf, len); |
|
addea1157aa7
Handles were never disposed. Added an AutoDispose(onoff) method to control this.
Jack Jansen <jack.jansen@cwi.nl>
parents:
8135
diff
changeset
|
44 HUnlock(h); |
|
addea1157aa7
Handles were never disposed. Added an AutoDispose(onoff) method to control this.
Jack Jansen <jack.jansen@cwi.nl>
parents:
8135
diff
changeset
|
45 rv = (ResourceObject *)ResObj_New(h); |
|
addea1157aa7
Handles were never disposed. Added an AutoDispose(onoff) method to control this.
Jack Jansen <jack.jansen@cwi.nl>
parents:
8135
diff
changeset
|
46 rv->ob_freeit = PyMac_AutoDisposeHandle; |
|
19734
d9daa4a67be2
A few more gcc warnings bite the dust.
Jack Jansen <jack.jansen@cwi.nl>
parents:
19723
diff
changeset
|
47 _res = (PyObject *)rv; |
|
d9daa4a67be2
A few more gcc warnings bite the dust.
Jack Jansen <jack.jansen@cwi.nl>
parents:
19723
diff
changeset
|
48 return _res; |
|
11951
addea1157aa7
Handles were never disposed. Added an AutoDispose(onoff) method to control this.
Jack Jansen <jack.jansen@cwi.nl>
parents:
8135
diff
changeset
|
49 """ |
|
addea1157aa7
Handles were never disposed. Added an AutoDispose(onoff) method to control this.
Jack Jansen <jack.jansen@cwi.nl>
parents:
8135
diff
changeset
|
50 |
|
addea1157aa7
Handles were never disposed. Added an AutoDispose(onoff) method to control this.
Jack Jansen <jack.jansen@cwi.nl>
parents:
8135
diff
changeset
|
51 f = ManualGenerator("Handle", handle_body) |
|
addea1157aa7
Handles were never disposed. Added an AutoDispose(onoff) method to control this.
Jack Jansen <jack.jansen@cwi.nl>
parents:
8135
diff
changeset
|
52 f.docstring = lambda: """Convert a string to a Handle object. |
|
addea1157aa7
Handles were never disposed. Added an AutoDispose(onoff) method to control this.
Jack Jansen <jack.jansen@cwi.nl>
parents:
8135
diff
changeset
|
53 |
|
addea1157aa7
Handles were never disposed. Added an AutoDispose(onoff) method to control this.
Jack Jansen <jack.jansen@cwi.nl>
parents:
8135
diff
changeset
|
54 Resource() and Handle() are very similar, but objects created with Handle() are |
|
addea1157aa7
Handles were never disposed. Added an AutoDispose(onoff) method to control this.
Jack Jansen <jack.jansen@cwi.nl>
parents:
8135
diff
changeset
|
55 by default automatically DisposeHandle()d upon object cleanup. Use AutoDispose() |
|
addea1157aa7
Handles were never disposed. Added an AutoDispose(onoff) method to control this.
Jack Jansen <jack.jansen@cwi.nl>
parents:
8135
diff
changeset
|
56 to change this. |
|
2288
b4caac1428d0
manually defined Resource() function
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
57 """ |
|
b4caac1428d0
manually defined Resource() function
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
58 functions.append(f) |
|
2753
4b74b3b43269
Added methods as_Menu and as_Control to convert a resource
Jack Jansen <jack.jansen@cwi.nl>
parents:
2288
diff
changeset
|
59 |
|
4b74b3b43269
Added methods as_Menu and as_Control to convert a resource
Jack Jansen <jack.jansen@cwi.nl>
parents:
2288
diff
changeset
|
60 # Convert resources to other things. |
|
4b74b3b43269
Added methods as_Menu and as_Control to convert a resource
Jack Jansen <jack.jansen@cwi.nl>
parents:
2288
diff
changeset
|
61 |
|
4b74b3b43269
Added methods as_Menu and as_Control to convert a resource
Jack Jansen <jack.jansen@cwi.nl>
parents:
2288
diff
changeset
|
62 as_xxx_body = """ |
|
19723
2a9bbdbefbb1
Shut up many more gcc warnings.
Jack Jansen <jack.jansen@cwi.nl>
parents:
11951
diff
changeset
|
63 _res = %sObj_New((%sHandle)_self->ob_itself); |
|
2a9bbdbefbb1
Shut up many more gcc warnings.
Jack Jansen <jack.jansen@cwi.nl>
parents:
11951
diff
changeset
|
64 return _res; |
|
2753
4b74b3b43269
Added methods as_Menu and as_Control to convert a resource
Jack Jansen <jack.jansen@cwi.nl>
parents:
2288
diff
changeset
|
65 """ |
|
4b74b3b43269
Added methods as_Menu and as_Control to convert a resource
Jack Jansen <jack.jansen@cwi.nl>
parents:
2288
diff
changeset
|
66 |
|
4b74b3b43269
Added methods as_Menu and as_Control to convert a resource
Jack Jansen <jack.jansen@cwi.nl>
parents:
2288
diff
changeset
|
67 def genresconverter(longname, shortname): |
|
4b74b3b43269
Added methods as_Menu and as_Control to convert a resource
Jack Jansen <jack.jansen@cwi.nl>
parents:
2288
diff
changeset
|
68 |
|
32736
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
26545
diff
changeset
|
69 f = ManualGenerator("as_%s"%longname, as_xxx_body%(shortname, longname)) |
|
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
26545
diff
changeset
|
70 docstring = "Return this resource/handle as a %s"%longname |
|
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
26545
diff
changeset
|
71 f.docstring = lambda docstring=docstring: docstring |
|
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
26545
diff
changeset
|
72 return f |
|
2753
4b74b3b43269
Added methods as_Menu and as_Control to convert a resource
Jack Jansen <jack.jansen@cwi.nl>
parents:
2288
diff
changeset
|
73 |
|
4b74b3b43269
Added methods as_Menu and as_Control to convert a resource
Jack Jansen <jack.jansen@cwi.nl>
parents:
2288
diff
changeset
|
74 resmethods.append(genresconverter("Control", "Ctl")) |
|
4b74b3b43269
Added methods as_Menu and as_Control to convert a resource
Jack Jansen <jack.jansen@cwi.nl>
parents:
2288
diff
changeset
|
75 resmethods.append(genresconverter("Menu", "Menu")) |
|
8135
ac288db5bc91
Grmpf, a lot more routines have gotten a "Mac" prefix for their
Jack Jansen <jack.jansen@cwi.nl>
parents:
2753
diff
changeset
|
76 |
|
ac288db5bc91
Grmpf, a lot more routines have gotten a "Mac" prefix for their
Jack Jansen <jack.jansen@cwi.nl>
parents:
2753
diff
changeset
|
77 # The definition of this one is MacLoadResource, so we do it by hand... |
|
ac288db5bc91
Grmpf, a lot more routines have gotten a "Mac" prefix for their
Jack Jansen <jack.jansen@cwi.nl>
parents:
2753
diff
changeset
|
78 |
|
ac288db5bc91
Grmpf, a lot more routines have gotten a "Mac" prefix for their
Jack Jansen <jack.jansen@cwi.nl>
parents:
2753
diff
changeset
|
79 f = ResMethod(void, 'LoadResource', |
|
ac288db5bc91
Grmpf, a lot more routines have gotten a "Mac" prefix for their
Jack Jansen <jack.jansen@cwi.nl>
parents:
2753
diff
changeset
|
80 (Handle, 'theResource', InMode), |
|
ac288db5bc91
Grmpf, a lot more routines have gotten a "Mac" prefix for their
Jack Jansen <jack.jansen@cwi.nl>
parents:
2753
diff
changeset
|
81 ) |
|
ac288db5bc91
Grmpf, a lot more routines have gotten a "Mac" prefix for their
Jack Jansen <jack.jansen@cwi.nl>
parents:
2753
diff
changeset
|
82 resmethods.append(f) |
|
11951
addea1157aa7
Handles were never disposed. Added an AutoDispose(onoff) method to control this.
Jack Jansen <jack.jansen@cwi.nl>
parents:
8135
diff
changeset
|
83 |
|
addea1157aa7
Handles were never disposed. Added an AutoDispose(onoff) method to control this.
Jack Jansen <jack.jansen@cwi.nl>
parents:
8135
diff
changeset
|
84 # |
|
addea1157aa7
Handles were never disposed. Added an AutoDispose(onoff) method to control this.
Jack Jansen <jack.jansen@cwi.nl>
parents:
8135
diff
changeset
|
85 # A method to set the auto-dispose flag |
|
addea1157aa7
Handles were never disposed. Added an AutoDispose(onoff) method to control this.
Jack Jansen <jack.jansen@cwi.nl>
parents:
8135
diff
changeset
|
86 # |
|
addea1157aa7
Handles were never disposed. Added an AutoDispose(onoff) method to control this.
Jack Jansen <jack.jansen@cwi.nl>
parents:
8135
diff
changeset
|
87 AutoDispose_body = """ |
|
addea1157aa7
Handles were never disposed. Added an AutoDispose(onoff) method to control this.
Jack Jansen <jack.jansen@cwi.nl>
parents:
8135
diff
changeset
|
88 int onoff, old = 0; |
|
addea1157aa7
Handles were never disposed. Added an AutoDispose(onoff) method to control this.
Jack Jansen <jack.jansen@cwi.nl>
parents:
8135
diff
changeset
|
89 if (!PyArg_ParseTuple(_args, "i", &onoff)) |
|
32736
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
26545
diff
changeset
|
90 return NULL; |
|
11951
addea1157aa7
Handles were never disposed. Added an AutoDispose(onoff) method to control this.
Jack Jansen <jack.jansen@cwi.nl>
parents:
8135
diff
changeset
|
91 if ( _self->ob_freeit ) |
|
32736
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
26545
diff
changeset
|
92 old = 1; |
|
11951
addea1157aa7
Handles were never disposed. Added an AutoDispose(onoff) method to control this.
Jack Jansen <jack.jansen@cwi.nl>
parents:
8135
diff
changeset
|
93 if ( onoff ) |
|
32736
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
26545
diff
changeset
|
94 _self->ob_freeit = PyMac_AutoDisposeHandle; |
|
11951
addea1157aa7
Handles were never disposed. Added an AutoDispose(onoff) method to control this.
Jack Jansen <jack.jansen@cwi.nl>
parents:
8135
diff
changeset
|
95 else |
|
32736
c3a096bfbd6b
Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents:
26545
diff
changeset
|
96 _self->ob_freeit = NULL; |
|
19734
d9daa4a67be2
A few more gcc warnings bite the dust.
Jack Jansen <jack.jansen@cwi.nl>
parents:
19723
diff
changeset
|
97 _res = Py_BuildValue("i", old); |
|
d9daa4a67be2
A few more gcc warnings bite the dust.
Jack Jansen <jack.jansen@cwi.nl>
parents:
19723
diff
changeset
|
98 return _res; |
|
11951
addea1157aa7
Handles were never disposed. Added an AutoDispose(onoff) method to control this.
Jack Jansen <jack.jansen@cwi.nl>
parents:
8135
diff
changeset
|
99 """ |
|
addea1157aa7
Handles were never disposed. Added an AutoDispose(onoff) method to control this.
Jack Jansen <jack.jansen@cwi.nl>
parents:
8135
diff
changeset
|
100 f = ManualGenerator("AutoDispose", AutoDispose_body) |
|
addea1157aa7
Handles were never disposed. Added an AutoDispose(onoff) method to control this.
Jack Jansen <jack.jansen@cwi.nl>
parents:
8135
diff
changeset
|
101 f.docstring = lambda: "(int)->int. Automatically DisposeHandle the object on Python object cleanup" |
|
addea1157aa7
Handles were never disposed. Added an AutoDispose(onoff) method to control this.
Jack Jansen <jack.jansen@cwi.nl>
parents:
8135
diff
changeset
|
102 resmethods.append(f) |
