Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1 | |
| 2 | /* =========================== Module Res =========================== */ |
| 3 | |
| 4 | #include "Python.h" |
| 5 | |
| 6 | |
| 7 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 8 | #include "macglue.h" |
Jack Jansen | 9d8b96c | 2000-07-14 22:16:45 +0000 | [diff] [blame] | 9 | #include "pymactoolbox.h" |
Guido van Rossum | 9bcb641 | 1995-02-05 16:54:27 +0000 | [diff] [blame] | 10 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 11 | #include <Resources.h> |
Jack Jansen | eaf3c9b | 1997-08-15 14:36:45 +0000 | [diff] [blame] | 12 | #include <string.h> |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 13 | |
Jack Jansen | 0e04eec | 2001-05-17 21:58:34 +0000 | [diff] [blame] | 14 | #ifdef USE_TOOLBOX_OBJECT_GLUE |
| 15 | extern PyObject *_ResObj_New(Handle); |
| 16 | extern int _ResObj_Convert(PyObject *, Handle *); |
| 17 | extern PyObject *_OptResObj_New(Handle); |
| 18 | extern int _OptResObj_Convert(PyObject *, Handle *); |
| 19 | #define ResObj_New _ResObj_New |
| 20 | #define ResObj_Convert _ResObj_Convert |
| 21 | #define OptResObj_New _OptResObj_New |
| 22 | #define OptResObj_Convert _OptResObj_Convert |
| 23 | #endif |
| 24 | |
Jack Jansen | add03b6 | 2000-03-08 16:58:15 +0000 | [diff] [blame] | 25 | /* Function to dispose a resource, with a "normal" calling sequence */ |
| 26 | static void |
| 27 | PyMac_AutoDisposeHandle(Handle h) |
| 28 | { |
| 29 | DisposeHandle(h); |
| 30 | } |
| 31 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 32 | static PyObject *Res_Error; |
| 33 | |
| 34 | /* ---------------------- Object type Resource ---------------------- */ |
| 35 | |
| 36 | PyTypeObject Resource_Type; |
| 37 | |
| 38 | #define ResObj_Check(x) ((x)->ob_type == &Resource_Type) |
| 39 | |
| 40 | typedef struct ResourceObject { |
| 41 | PyObject_HEAD |
| 42 | Handle ob_itself; |
Jack Jansen | add03b6 | 2000-03-08 16:58:15 +0000 | [diff] [blame] | 43 | void (*ob_freeit)(Handle ptr); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 44 | } ResourceObject; |
| 45 | |
| 46 | PyObject *ResObj_New(itself) |
Guido van Rossum | 227a423 | 1995-03-10 14:42:57 +0000 | [diff] [blame] | 47 | Handle itself; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 48 | { |
| 49 | ResourceObject *it; |
| 50 | if (itself == NULL) return PyMac_Error(resNotFound); |
| 51 | it = PyObject_NEW(ResourceObject, &Resource_Type); |
| 52 | if (it == NULL) return NULL; |
| 53 | it->ob_itself = itself; |
Jack Jansen | add03b6 | 2000-03-08 16:58:15 +0000 | [diff] [blame] | 54 | it->ob_freeit = NULL; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 55 | return (PyObject *)it; |
| 56 | } |
| 57 | ResObj_Convert(v, p_itself) |
| 58 | PyObject *v; |
| 59 | Handle *p_itself; |
| 60 | { |
| 61 | if (!ResObj_Check(v)) |
| 62 | { |
Jack Jansen | 2d76c25 | 1999-12-12 22:57:29 +0000 | [diff] [blame] | 63 | PyObject *tmp; |
| 64 | if ( (tmp=PyObject_CallMethod(v, "as_Resource", "")) ) |
| 65 | { |
| 66 | *p_itself = ((ResourceObject *)tmp)->ob_itself; |
| 67 | Py_DECREF(tmp); |
| 68 | return 1; |
| 69 | } |
| 70 | PyErr_Clear(); |
| 71 | } |
| 72 | if (!ResObj_Check(v)) |
| 73 | { |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 74 | PyErr_SetString(PyExc_TypeError, "Resource required"); |
| 75 | return 0; |
| 76 | } |
| 77 | *p_itself = ((ResourceObject *)v)->ob_itself; |
| 78 | return 1; |
| 79 | } |
| 80 | |
| 81 | static void ResObj_dealloc(self) |
| 82 | ResourceObject *self; |
| 83 | { |
Jack Jansen | add03b6 | 2000-03-08 16:58:15 +0000 | [diff] [blame] | 84 | if (self->ob_freeit && self->ob_itself) |
| 85 | { |
| 86 | self->ob_freeit(self->ob_itself); |
| 87 | } |
| 88 | self->ob_itself = NULL; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 89 | PyMem_DEL(self); |
| 90 | } |
| 91 | |
| 92 | static PyObject *ResObj_HomeResFile(_self, _args) |
| 93 | ResourceObject *_self; |
| 94 | PyObject *_args; |
| 95 | { |
| 96 | PyObject *_res = NULL; |
| 97 | short _rv; |
| 98 | if (!PyArg_ParseTuple(_args, "")) |
| 99 | return NULL; |
| 100 | _rv = HomeResFile(_self->ob_itself); |
| 101 | { |
| 102 | OSErr _err = ResError(); |
| 103 | if (_err != noErr) return PyMac_Error(_err); |
| 104 | } |
| 105 | _res = Py_BuildValue("h", |
| 106 | _rv); |
| 107 | return _res; |
| 108 | } |
| 109 | |
Jack Jansen | 1c4e614 | 1998-04-21 15:23:55 +0000 | [diff] [blame] | 110 | static PyObject *ResObj_MacLoadResource(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 111 | ResourceObject *_self; |
| 112 | PyObject *_args; |
| 113 | { |
| 114 | PyObject *_res = NULL; |
| 115 | if (!PyArg_ParseTuple(_args, "")) |
| 116 | return NULL; |
Jack Jansen | 1c4e614 | 1998-04-21 15:23:55 +0000 | [diff] [blame] | 117 | MacLoadResource(_self->ob_itself); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 118 | { |
| 119 | OSErr _err = ResError(); |
| 120 | if (_err != noErr) return PyMac_Error(_err); |
| 121 | } |
| 122 | Py_INCREF(Py_None); |
| 123 | _res = Py_None; |
| 124 | return _res; |
| 125 | } |
| 126 | |
| 127 | static PyObject *ResObj_ReleaseResource(_self, _args) |
| 128 | ResourceObject *_self; |
| 129 | PyObject *_args; |
| 130 | { |
| 131 | PyObject *_res = NULL; |
| 132 | if (!PyArg_ParseTuple(_args, "")) |
| 133 | return NULL; |
| 134 | ReleaseResource(_self->ob_itself); |
| 135 | { |
| 136 | OSErr _err = ResError(); |
| 137 | if (_err != noErr) return PyMac_Error(_err); |
| 138 | } |
| 139 | Py_INCREF(Py_None); |
| 140 | _res = Py_None; |
| 141 | return _res; |
| 142 | } |
| 143 | |
| 144 | static PyObject *ResObj_DetachResource(_self, _args) |
| 145 | ResourceObject *_self; |
| 146 | PyObject *_args; |
| 147 | { |
| 148 | PyObject *_res = NULL; |
| 149 | if (!PyArg_ParseTuple(_args, "")) |
| 150 | return NULL; |
| 151 | DetachResource(_self->ob_itself); |
| 152 | { |
| 153 | OSErr _err = ResError(); |
| 154 | if (_err != noErr) return PyMac_Error(_err); |
| 155 | } |
| 156 | Py_INCREF(Py_None); |
| 157 | _res = Py_None; |
| 158 | return _res; |
| 159 | } |
| 160 | |
| 161 | static PyObject *ResObj_GetResAttrs(_self, _args) |
| 162 | ResourceObject *_self; |
| 163 | PyObject *_args; |
| 164 | { |
| 165 | PyObject *_res = NULL; |
| 166 | short _rv; |
| 167 | if (!PyArg_ParseTuple(_args, "")) |
| 168 | return NULL; |
| 169 | _rv = GetResAttrs(_self->ob_itself); |
| 170 | { |
| 171 | OSErr _err = ResError(); |
| 172 | if (_err != noErr) return PyMac_Error(_err); |
| 173 | } |
| 174 | _res = Py_BuildValue("h", |
| 175 | _rv); |
| 176 | return _res; |
| 177 | } |
| 178 | |
| 179 | static PyObject *ResObj_GetResInfo(_self, _args) |
| 180 | ResourceObject *_self; |
| 181 | PyObject *_args; |
| 182 | { |
| 183 | PyObject *_res = NULL; |
| 184 | short theID; |
| 185 | ResType theType; |
| 186 | Str255 name; |
| 187 | if (!PyArg_ParseTuple(_args, "")) |
| 188 | return NULL; |
| 189 | GetResInfo(_self->ob_itself, |
| 190 | &theID, |
| 191 | &theType, |
| 192 | name); |
| 193 | { |
| 194 | OSErr _err = ResError(); |
| 195 | if (_err != noErr) return PyMac_Error(_err); |
| 196 | } |
| 197 | _res = Py_BuildValue("hO&O&", |
| 198 | theID, |
| 199 | PyMac_BuildOSType, theType, |
| 200 | PyMac_BuildStr255, name); |
| 201 | return _res; |
| 202 | } |
| 203 | |
| 204 | static PyObject *ResObj_SetResInfo(_self, _args) |
| 205 | ResourceObject *_self; |
| 206 | PyObject *_args; |
| 207 | { |
| 208 | PyObject *_res = NULL; |
| 209 | short theID; |
| 210 | Str255 name; |
| 211 | if (!PyArg_ParseTuple(_args, "hO&", |
| 212 | &theID, |
| 213 | PyMac_GetStr255, name)) |
| 214 | return NULL; |
| 215 | SetResInfo(_self->ob_itself, |
| 216 | theID, |
| 217 | name); |
| 218 | { |
| 219 | OSErr _err = ResError(); |
| 220 | if (_err != noErr) return PyMac_Error(_err); |
| 221 | } |
| 222 | Py_INCREF(Py_None); |
| 223 | _res = Py_None; |
| 224 | return _res; |
| 225 | } |
| 226 | |
| 227 | static PyObject *ResObj_AddResource(_self, _args) |
| 228 | ResourceObject *_self; |
| 229 | PyObject *_args; |
| 230 | { |
| 231 | PyObject *_res = NULL; |
| 232 | ResType theType; |
| 233 | short theID; |
| 234 | Str255 name; |
| 235 | if (!PyArg_ParseTuple(_args, "O&hO&", |
| 236 | PyMac_GetOSType, &theType, |
| 237 | &theID, |
| 238 | PyMac_GetStr255, name)) |
| 239 | return NULL; |
| 240 | AddResource(_self->ob_itself, |
| 241 | theType, |
| 242 | theID, |
| 243 | name); |
| 244 | { |
| 245 | OSErr _err = ResError(); |
| 246 | if (_err != noErr) return PyMac_Error(_err); |
| 247 | } |
| 248 | Py_INCREF(Py_None); |
| 249 | _res = Py_None; |
| 250 | return _res; |
| 251 | } |
| 252 | |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 253 | static PyObject *ResObj_GetResourceSizeOnDisk(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 254 | ResourceObject *_self; |
| 255 | PyObject *_args; |
| 256 | { |
| 257 | PyObject *_res = NULL; |
| 258 | long _rv; |
| 259 | if (!PyArg_ParseTuple(_args, "")) |
| 260 | return NULL; |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 261 | _rv = GetResourceSizeOnDisk(_self->ob_itself); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 262 | { |
| 263 | OSErr _err = ResError(); |
| 264 | if (_err != noErr) return PyMac_Error(_err); |
| 265 | } |
| 266 | _res = Py_BuildValue("l", |
| 267 | _rv); |
| 268 | return _res; |
| 269 | } |
| 270 | |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 271 | static PyObject *ResObj_GetMaxResourceSize(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 272 | ResourceObject *_self; |
| 273 | PyObject *_args; |
| 274 | { |
| 275 | PyObject *_res = NULL; |
| 276 | long _rv; |
| 277 | if (!PyArg_ParseTuple(_args, "")) |
| 278 | return NULL; |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 279 | _rv = GetMaxResourceSize(_self->ob_itself); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 280 | { |
| 281 | OSErr _err = ResError(); |
| 282 | if (_err != noErr) return PyMac_Error(_err); |
| 283 | } |
| 284 | _res = Py_BuildValue("l", |
| 285 | _rv); |
| 286 | return _res; |
| 287 | } |
| 288 | |
Jack Jansen | 74a1e63 | 2000-07-14 22:37:27 +0000 | [diff] [blame] | 289 | #if !TARGET_API_MAC_CARBON |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 290 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 291 | static PyObject *ResObj_RsrcMapEntry(_self, _args) |
| 292 | ResourceObject *_self; |
| 293 | PyObject *_args; |
| 294 | { |
| 295 | PyObject *_res = NULL; |
| 296 | long _rv; |
| 297 | if (!PyArg_ParseTuple(_args, "")) |
| 298 | return NULL; |
| 299 | _rv = RsrcMapEntry(_self->ob_itself); |
| 300 | { |
| 301 | OSErr _err = ResError(); |
| 302 | if (_err != noErr) return PyMac_Error(_err); |
| 303 | } |
| 304 | _res = Py_BuildValue("l", |
| 305 | _rv); |
| 306 | return _res; |
| 307 | } |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 308 | #endif |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 309 | |
| 310 | static PyObject *ResObj_SetResAttrs(_self, _args) |
| 311 | ResourceObject *_self; |
| 312 | PyObject *_args; |
| 313 | { |
| 314 | PyObject *_res = NULL; |
| 315 | short attrs; |
| 316 | if (!PyArg_ParseTuple(_args, "h", |
| 317 | &attrs)) |
| 318 | return NULL; |
| 319 | SetResAttrs(_self->ob_itself, |
| 320 | attrs); |
| 321 | { |
| 322 | OSErr _err = ResError(); |
| 323 | if (_err != noErr) return PyMac_Error(_err); |
| 324 | } |
| 325 | Py_INCREF(Py_None); |
| 326 | _res = Py_None; |
| 327 | return _res; |
| 328 | } |
| 329 | |
| 330 | static PyObject *ResObj_ChangedResource(_self, _args) |
| 331 | ResourceObject *_self; |
| 332 | PyObject *_args; |
| 333 | { |
| 334 | PyObject *_res = NULL; |
| 335 | if (!PyArg_ParseTuple(_args, "")) |
| 336 | return NULL; |
| 337 | ChangedResource(_self->ob_itself); |
| 338 | { |
| 339 | OSErr _err = ResError(); |
| 340 | if (_err != noErr) return PyMac_Error(_err); |
| 341 | } |
| 342 | Py_INCREF(Py_None); |
| 343 | _res = Py_None; |
| 344 | return _res; |
| 345 | } |
| 346 | |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 347 | static PyObject *ResObj_RemoveResource(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 348 | ResourceObject *_self; |
| 349 | PyObject *_args; |
| 350 | { |
| 351 | PyObject *_res = NULL; |
| 352 | if (!PyArg_ParseTuple(_args, "")) |
| 353 | return NULL; |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 354 | RemoveResource(_self->ob_itself); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 355 | { |
| 356 | OSErr _err = ResError(); |
| 357 | if (_err != noErr) return PyMac_Error(_err); |
| 358 | } |
| 359 | Py_INCREF(Py_None); |
| 360 | _res = Py_None; |
| 361 | return _res; |
| 362 | } |
| 363 | |
| 364 | static PyObject *ResObj_WriteResource(_self, _args) |
| 365 | ResourceObject *_self; |
| 366 | PyObject *_args; |
| 367 | { |
| 368 | PyObject *_res = NULL; |
| 369 | if (!PyArg_ParseTuple(_args, "")) |
| 370 | return NULL; |
| 371 | WriteResource(_self->ob_itself); |
| 372 | { |
| 373 | OSErr _err = ResError(); |
| 374 | if (_err != noErr) return PyMac_Error(_err); |
| 375 | } |
| 376 | Py_INCREF(Py_None); |
| 377 | _res = Py_None; |
| 378 | return _res; |
| 379 | } |
| 380 | |
| 381 | static PyObject *ResObj_SetResourceSize(_self, _args) |
| 382 | ResourceObject *_self; |
| 383 | PyObject *_args; |
| 384 | { |
| 385 | PyObject *_res = NULL; |
| 386 | long newSize; |
| 387 | if (!PyArg_ParseTuple(_args, "l", |
| 388 | &newSize)) |
| 389 | return NULL; |
| 390 | SetResourceSize(_self->ob_itself, |
| 391 | newSize); |
| 392 | { |
| 393 | OSErr _err = ResError(); |
| 394 | if (_err != noErr) return PyMac_Error(_err); |
| 395 | } |
| 396 | Py_INCREF(Py_None); |
| 397 | _res = Py_None; |
| 398 | return _res; |
| 399 | } |
| 400 | |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 401 | static PyObject *ResObj_GetNextFOND(_self, _args) |
| 402 | ResourceObject *_self; |
| 403 | PyObject *_args; |
| 404 | { |
| 405 | PyObject *_res = NULL; |
| 406 | Handle _rv; |
| 407 | if (!PyArg_ParseTuple(_args, "")) |
| 408 | return NULL; |
| 409 | _rv = GetNextFOND(_self->ob_itself); |
| 410 | { |
| 411 | OSErr _err = ResError(); |
| 412 | if (_err != noErr) return PyMac_Error(_err); |
| 413 | } |
| 414 | _res = Py_BuildValue("O&", |
| 415 | ResObj_New, _rv); |
| 416 | return _res; |
| 417 | } |
| 418 | |
Jack Jansen | 1e05402 | 1995-06-18 20:20:27 +0000 | [diff] [blame] | 419 | static PyObject *ResObj_as_Control(_self, _args) |
| 420 | ResourceObject *_self; |
| 421 | PyObject *_args; |
| 422 | { |
| 423 | PyObject *_res = NULL; |
| 424 | |
| 425 | return CtlObj_New((ControlHandle)_self->ob_itself); |
| 426 | |
| 427 | } |
| 428 | |
| 429 | static PyObject *ResObj_as_Menu(_self, _args) |
| 430 | ResourceObject *_self; |
| 431 | PyObject *_args; |
| 432 | { |
| 433 | PyObject *_res = NULL; |
| 434 | |
| 435 | return MenuObj_New((MenuHandle)_self->ob_itself); |
| 436 | |
| 437 | } |
| 438 | |
Jack Jansen | e180d99 | 1998-04-24 10:28:20 +0000 | [diff] [blame] | 439 | static PyObject *ResObj_LoadResource(_self, _args) |
| 440 | ResourceObject *_self; |
| 441 | PyObject *_args; |
| 442 | { |
| 443 | PyObject *_res = NULL; |
| 444 | if (!PyArg_ParseTuple(_args, "")) |
| 445 | return NULL; |
| 446 | LoadResource(_self->ob_itself); |
| 447 | { |
| 448 | OSErr _err = ResError(); |
| 449 | if (_err != noErr) return PyMac_Error(_err); |
| 450 | } |
| 451 | Py_INCREF(Py_None); |
| 452 | _res = Py_None; |
| 453 | return _res; |
| 454 | } |
| 455 | |
Jack Jansen | add03b6 | 2000-03-08 16:58:15 +0000 | [diff] [blame] | 456 | static PyObject *ResObj_AutoDispose(_self, _args) |
| 457 | ResourceObject *_self; |
| 458 | PyObject *_args; |
| 459 | { |
| 460 | PyObject *_res = NULL; |
| 461 | |
| 462 | int onoff, old = 0; |
| 463 | if (!PyArg_ParseTuple(_args, "i", &onoff)) |
| 464 | return NULL; |
| 465 | if ( _self->ob_freeit ) |
| 466 | old = 1; |
| 467 | if ( onoff ) |
| 468 | _self->ob_freeit = PyMac_AutoDisposeHandle; |
| 469 | else |
| 470 | _self->ob_freeit = NULL; |
| 471 | return Py_BuildValue("i", old); |
| 472 | |
| 473 | } |
| 474 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 475 | static PyMethodDef ResObj_methods[] = { |
| 476 | {"HomeResFile", (PyCFunction)ResObj_HomeResFile, 1, |
| 477 | "() -> (short _rv)"}, |
Jack Jansen | 1c4e614 | 1998-04-21 15:23:55 +0000 | [diff] [blame] | 478 | {"MacLoadResource", (PyCFunction)ResObj_MacLoadResource, 1, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 479 | "() -> None"}, |
| 480 | {"ReleaseResource", (PyCFunction)ResObj_ReleaseResource, 1, |
| 481 | "() -> None"}, |
| 482 | {"DetachResource", (PyCFunction)ResObj_DetachResource, 1, |
| 483 | "() -> None"}, |
| 484 | {"GetResAttrs", (PyCFunction)ResObj_GetResAttrs, 1, |
| 485 | "() -> (short _rv)"}, |
| 486 | {"GetResInfo", (PyCFunction)ResObj_GetResInfo, 1, |
| 487 | "() -> (short theID, ResType theType, Str255 name)"}, |
| 488 | {"SetResInfo", (PyCFunction)ResObj_SetResInfo, 1, |
| 489 | "(short theID, Str255 name) -> None"}, |
| 490 | {"AddResource", (PyCFunction)ResObj_AddResource, 1, |
| 491 | "(ResType theType, short theID, Str255 name) -> None"}, |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 492 | {"GetResourceSizeOnDisk", (PyCFunction)ResObj_GetResourceSizeOnDisk, 1, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 493 | "() -> (long _rv)"}, |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 494 | {"GetMaxResourceSize", (PyCFunction)ResObj_GetMaxResourceSize, 1, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 495 | "() -> (long _rv)"}, |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 496 | |
Jack Jansen | 74a1e63 | 2000-07-14 22:37:27 +0000 | [diff] [blame] | 497 | #if !TARGET_API_MAC_CARBON |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 498 | {"RsrcMapEntry", (PyCFunction)ResObj_RsrcMapEntry, 1, |
| 499 | "() -> (long _rv)"}, |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 500 | #endif |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 501 | {"SetResAttrs", (PyCFunction)ResObj_SetResAttrs, 1, |
| 502 | "(short attrs) -> None"}, |
| 503 | {"ChangedResource", (PyCFunction)ResObj_ChangedResource, 1, |
| 504 | "() -> None"}, |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 505 | {"RemoveResource", (PyCFunction)ResObj_RemoveResource, 1, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 506 | "() -> None"}, |
| 507 | {"WriteResource", (PyCFunction)ResObj_WriteResource, 1, |
| 508 | "() -> None"}, |
| 509 | {"SetResourceSize", (PyCFunction)ResObj_SetResourceSize, 1, |
| 510 | "(long newSize) -> None"}, |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 511 | {"GetNextFOND", (PyCFunction)ResObj_GetNextFOND, 1, |
| 512 | "() -> (Handle _rv)"}, |
Jack Jansen | 1e05402 | 1995-06-18 20:20:27 +0000 | [diff] [blame] | 513 | {"as_Control", (PyCFunction)ResObj_as_Control, 1, |
| 514 | "Return this resource/handle as a Control"}, |
| 515 | {"as_Menu", (PyCFunction)ResObj_as_Menu, 1, |
| 516 | "Return this resource/handle as a Menu"}, |
Jack Jansen | e180d99 | 1998-04-24 10:28:20 +0000 | [diff] [blame] | 517 | {"LoadResource", (PyCFunction)ResObj_LoadResource, 1, |
| 518 | "() -> None"}, |
Jack Jansen | add03b6 | 2000-03-08 16:58:15 +0000 | [diff] [blame] | 519 | {"AutoDispose", (PyCFunction)ResObj_AutoDispose, 1, |
| 520 | "(int)->int. Automatically DisposeHandle the object on Python object cleanup"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 521 | {NULL, NULL, 0} |
| 522 | }; |
| 523 | |
| 524 | PyMethodChain ResObj_chain = { ResObj_methods, NULL }; |
| 525 | |
| 526 | static PyObject *ResObj_getattr(self, name) |
| 527 | ResourceObject *self; |
| 528 | char *name; |
| 529 | { |
| 530 | |
| 531 | if (strcmp(name, "size") == 0) |
| 532 | return PyInt_FromLong(GetHandleSize(self->ob_itself)); |
| 533 | if (strcmp(name, "data") == 0) { |
| 534 | PyObject *res; |
| 535 | char state; |
| 536 | state = HGetState(self->ob_itself); |
| 537 | HLock(self->ob_itself); |
| 538 | res = PyString_FromStringAndSize( |
| 539 | *self->ob_itself, |
| 540 | GetHandleSize(self->ob_itself)); |
| 541 | HUnlock(self->ob_itself); |
| 542 | HSetState(self->ob_itself, state); |
| 543 | return res; |
| 544 | } |
| 545 | if (strcmp(name, "__members__") == 0) |
| 546 | return Py_BuildValue("[ss]", "data", "size"); |
| 547 | |
| 548 | return Py_FindMethodInChain(&ResObj_chain, (PyObject *)self, name); |
| 549 | } |
| 550 | |
Jack Jansen | 1e05402 | 1995-06-18 20:20:27 +0000 | [diff] [blame] | 551 | static int |
| 552 | ResObj_setattr(self, name, value) |
| 553 | ResourceObject *self; |
| 554 | char *name; |
| 555 | PyObject *value; |
| 556 | { |
| 557 | char *data; |
| 558 | long size; |
| 559 | |
| 560 | if (strcmp(name, "data") != 0 || value == NULL ) |
| 561 | return -1; |
| 562 | if ( !PyString_Check(value) ) |
| 563 | return -1; |
| 564 | size = PyString_Size(value); |
| 565 | data = PyString_AsString(value); |
| 566 | /* XXXX Do I need the GetState/SetState calls? */ |
| 567 | SetHandleSize(self->ob_itself, size); |
| 568 | if ( MemError()) |
| 569 | return -1; |
| 570 | HLock(self->ob_itself); |
| 571 | memcpy((char *)*self->ob_itself, data, size); |
| 572 | HUnlock(self->ob_itself); |
| 573 | /* XXXX Should I do the Changed call immedeately? */ |
| 574 | return 0; |
| 575 | } |
| 576 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 577 | |
Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 578 | #define ResObj_compare NULL |
| 579 | |
| 580 | #define ResObj_repr NULL |
| 581 | |
| 582 | #define ResObj_hash NULL |
| 583 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 584 | PyTypeObject Resource_Type = { |
| 585 | PyObject_HEAD_INIT(&PyType_Type) |
| 586 | 0, /*ob_size*/ |
| 587 | "Resource", /*tp_name*/ |
| 588 | sizeof(ResourceObject), /*tp_basicsize*/ |
| 589 | 0, /*tp_itemsize*/ |
| 590 | /* methods */ |
| 591 | (destructor) ResObj_dealloc, /*tp_dealloc*/ |
| 592 | 0, /*tp_print*/ |
| 593 | (getattrfunc) ResObj_getattr, /*tp_getattr*/ |
| 594 | (setattrfunc) ResObj_setattr, /*tp_setattr*/ |
Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 595 | (cmpfunc) ResObj_compare, /*tp_compare*/ |
| 596 | (reprfunc) ResObj_repr, /*tp_repr*/ |
| 597 | (PyNumberMethods *)0, /* tp_as_number */ |
| 598 | (PySequenceMethods *)0, /* tp_as_sequence */ |
| 599 | (PyMappingMethods *)0, /* tp_as_mapping */ |
| 600 | (hashfunc) ResObj_hash, /*tp_hash*/ |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 601 | }; |
| 602 | |
| 603 | /* -------------------- End object type Resource -------------------- */ |
| 604 | |
| 605 | |
Jack Jansen | 74a1e63 | 2000-07-14 22:37:27 +0000 | [diff] [blame] | 606 | #if !TARGET_API_MAC_CARBON |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 607 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 608 | static PyObject *Res_InitResources(_self, _args) |
| 609 | PyObject *_self; |
| 610 | PyObject *_args; |
| 611 | { |
| 612 | PyObject *_res = NULL; |
| 613 | short _rv; |
| 614 | if (!PyArg_ParseTuple(_args, "")) |
| 615 | return NULL; |
| 616 | _rv = InitResources(); |
| 617 | { |
| 618 | OSErr _err = ResError(); |
| 619 | if (_err != noErr) return PyMac_Error(_err); |
| 620 | } |
| 621 | _res = Py_BuildValue("h", |
| 622 | _rv); |
| 623 | return _res; |
| 624 | } |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 625 | #endif |
| 626 | |
Jack Jansen | 74a1e63 | 2000-07-14 22:37:27 +0000 | [diff] [blame] | 627 | #if !TARGET_API_MAC_CARBON |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 628 | |
| 629 | static PyObject *Res_RsrcZoneInit(_self, _args) |
| 630 | PyObject *_self; |
| 631 | PyObject *_args; |
| 632 | { |
| 633 | PyObject *_res = NULL; |
| 634 | if (!PyArg_ParseTuple(_args, "")) |
| 635 | return NULL; |
| 636 | RsrcZoneInit(); |
| 637 | { |
| 638 | OSErr _err = ResError(); |
| 639 | if (_err != noErr) return PyMac_Error(_err); |
| 640 | } |
| 641 | Py_INCREF(Py_None); |
| 642 | _res = Py_None; |
| 643 | return _res; |
| 644 | } |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 645 | #endif |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 646 | |
| 647 | static PyObject *Res_CloseResFile(_self, _args) |
| 648 | PyObject *_self; |
| 649 | PyObject *_args; |
| 650 | { |
| 651 | PyObject *_res = NULL; |
| 652 | short refNum; |
| 653 | if (!PyArg_ParseTuple(_args, "h", |
| 654 | &refNum)) |
| 655 | return NULL; |
| 656 | CloseResFile(refNum); |
| 657 | { |
| 658 | OSErr _err = ResError(); |
| 659 | if (_err != noErr) return PyMac_Error(_err); |
| 660 | } |
| 661 | Py_INCREF(Py_None); |
| 662 | _res = Py_None; |
| 663 | return _res; |
| 664 | } |
| 665 | |
| 666 | static PyObject *Res_ResError(_self, _args) |
| 667 | PyObject *_self; |
| 668 | PyObject *_args; |
| 669 | { |
| 670 | PyObject *_res = NULL; |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 671 | OSErr _rv; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 672 | if (!PyArg_ParseTuple(_args, "")) |
| 673 | return NULL; |
| 674 | _rv = ResError(); |
| 675 | { |
| 676 | OSErr _err = ResError(); |
| 677 | if (_err != noErr) return PyMac_Error(_err); |
| 678 | } |
| 679 | _res = Py_BuildValue("h", |
| 680 | _rv); |
| 681 | return _res; |
| 682 | } |
| 683 | |
| 684 | static PyObject *Res_CurResFile(_self, _args) |
| 685 | PyObject *_self; |
| 686 | PyObject *_args; |
| 687 | { |
| 688 | PyObject *_res = NULL; |
| 689 | short _rv; |
| 690 | if (!PyArg_ParseTuple(_args, "")) |
| 691 | return NULL; |
| 692 | _rv = CurResFile(); |
| 693 | { |
| 694 | OSErr _err = ResError(); |
| 695 | if (_err != noErr) return PyMac_Error(_err); |
| 696 | } |
| 697 | _res = Py_BuildValue("h", |
| 698 | _rv); |
| 699 | return _res; |
| 700 | } |
| 701 | |
Jack Jansen | 74a1e63 | 2000-07-14 22:37:27 +0000 | [diff] [blame] | 702 | #if !TARGET_API_MAC_CARBON |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 703 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 704 | static PyObject *Res_CreateResFile(_self, _args) |
| 705 | PyObject *_self; |
| 706 | PyObject *_args; |
| 707 | { |
| 708 | PyObject *_res = NULL; |
| 709 | Str255 fileName; |
| 710 | if (!PyArg_ParseTuple(_args, "O&", |
| 711 | PyMac_GetStr255, fileName)) |
| 712 | return NULL; |
| 713 | CreateResFile(fileName); |
| 714 | { |
| 715 | OSErr _err = ResError(); |
| 716 | if (_err != noErr) return PyMac_Error(_err); |
| 717 | } |
| 718 | Py_INCREF(Py_None); |
| 719 | _res = Py_None; |
| 720 | return _res; |
| 721 | } |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 722 | #endif |
| 723 | |
Jack Jansen | 74a1e63 | 2000-07-14 22:37:27 +0000 | [diff] [blame] | 724 | #if !TARGET_API_MAC_CARBON |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 725 | |
| 726 | static PyObject *Res_OpenResFile(_self, _args) |
| 727 | PyObject *_self; |
| 728 | PyObject *_args; |
| 729 | { |
| 730 | PyObject *_res = NULL; |
| 731 | short _rv; |
| 732 | Str255 fileName; |
| 733 | if (!PyArg_ParseTuple(_args, "O&", |
| 734 | PyMac_GetStr255, fileName)) |
| 735 | return NULL; |
| 736 | _rv = OpenResFile(fileName); |
| 737 | { |
| 738 | OSErr _err = ResError(); |
| 739 | if (_err != noErr) return PyMac_Error(_err); |
| 740 | } |
| 741 | _res = Py_BuildValue("h", |
| 742 | _rv); |
| 743 | return _res; |
| 744 | } |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 745 | #endif |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 746 | |
| 747 | static PyObject *Res_UseResFile(_self, _args) |
| 748 | PyObject *_self; |
| 749 | PyObject *_args; |
| 750 | { |
| 751 | PyObject *_res = NULL; |
| 752 | short refNum; |
| 753 | if (!PyArg_ParseTuple(_args, "h", |
| 754 | &refNum)) |
| 755 | return NULL; |
| 756 | UseResFile(refNum); |
| 757 | { |
| 758 | OSErr _err = ResError(); |
| 759 | if (_err != noErr) return PyMac_Error(_err); |
| 760 | } |
| 761 | Py_INCREF(Py_None); |
| 762 | _res = Py_None; |
| 763 | return _res; |
| 764 | } |
| 765 | |
| 766 | static PyObject *Res_CountTypes(_self, _args) |
| 767 | PyObject *_self; |
| 768 | PyObject *_args; |
| 769 | { |
| 770 | PyObject *_res = NULL; |
| 771 | short _rv; |
| 772 | if (!PyArg_ParseTuple(_args, "")) |
| 773 | return NULL; |
| 774 | _rv = CountTypes(); |
| 775 | { |
| 776 | OSErr _err = ResError(); |
| 777 | if (_err != noErr) return PyMac_Error(_err); |
| 778 | } |
| 779 | _res = Py_BuildValue("h", |
| 780 | _rv); |
| 781 | return _res; |
| 782 | } |
| 783 | |
| 784 | static PyObject *Res_Count1Types(_self, _args) |
| 785 | PyObject *_self; |
| 786 | PyObject *_args; |
| 787 | { |
| 788 | PyObject *_res = NULL; |
| 789 | short _rv; |
| 790 | if (!PyArg_ParseTuple(_args, "")) |
| 791 | return NULL; |
| 792 | _rv = Count1Types(); |
| 793 | { |
| 794 | OSErr _err = ResError(); |
| 795 | if (_err != noErr) return PyMac_Error(_err); |
| 796 | } |
| 797 | _res = Py_BuildValue("h", |
| 798 | _rv); |
| 799 | return _res; |
| 800 | } |
| 801 | |
| 802 | static PyObject *Res_GetIndType(_self, _args) |
| 803 | PyObject *_self; |
| 804 | PyObject *_args; |
| 805 | { |
| 806 | PyObject *_res = NULL; |
| 807 | ResType theType; |
| 808 | short index; |
| 809 | if (!PyArg_ParseTuple(_args, "h", |
| 810 | &index)) |
| 811 | return NULL; |
| 812 | GetIndType(&theType, |
| 813 | index); |
| 814 | { |
| 815 | OSErr _err = ResError(); |
| 816 | if (_err != noErr) return PyMac_Error(_err); |
| 817 | } |
| 818 | _res = Py_BuildValue("O&", |
| 819 | PyMac_BuildOSType, theType); |
| 820 | return _res; |
| 821 | } |
| 822 | |
| 823 | static PyObject *Res_Get1IndType(_self, _args) |
| 824 | PyObject *_self; |
| 825 | PyObject *_args; |
| 826 | { |
| 827 | PyObject *_res = NULL; |
| 828 | ResType theType; |
| 829 | short index; |
| 830 | if (!PyArg_ParseTuple(_args, "h", |
| 831 | &index)) |
| 832 | return NULL; |
| 833 | Get1IndType(&theType, |
| 834 | index); |
| 835 | { |
| 836 | OSErr _err = ResError(); |
| 837 | if (_err != noErr) return PyMac_Error(_err); |
| 838 | } |
| 839 | _res = Py_BuildValue("O&", |
| 840 | PyMac_BuildOSType, theType); |
| 841 | return _res; |
| 842 | } |
| 843 | |
| 844 | static PyObject *Res_SetResLoad(_self, _args) |
| 845 | PyObject *_self; |
| 846 | PyObject *_args; |
| 847 | { |
| 848 | PyObject *_res = NULL; |
| 849 | Boolean load; |
| 850 | if (!PyArg_ParseTuple(_args, "b", |
| 851 | &load)) |
| 852 | return NULL; |
| 853 | SetResLoad(load); |
| 854 | { |
| 855 | OSErr _err = ResError(); |
| 856 | if (_err != noErr) return PyMac_Error(_err); |
| 857 | } |
| 858 | Py_INCREF(Py_None); |
| 859 | _res = Py_None; |
| 860 | return _res; |
| 861 | } |
| 862 | |
| 863 | static PyObject *Res_CountResources(_self, _args) |
| 864 | PyObject *_self; |
| 865 | PyObject *_args; |
| 866 | { |
| 867 | PyObject *_res = NULL; |
| 868 | short _rv; |
| 869 | ResType theType; |
| 870 | if (!PyArg_ParseTuple(_args, "O&", |
| 871 | PyMac_GetOSType, &theType)) |
| 872 | return NULL; |
| 873 | _rv = CountResources(theType); |
| 874 | { |
| 875 | OSErr _err = ResError(); |
| 876 | if (_err != noErr) return PyMac_Error(_err); |
| 877 | } |
| 878 | _res = Py_BuildValue("h", |
| 879 | _rv); |
| 880 | return _res; |
| 881 | } |
| 882 | |
| 883 | static PyObject *Res_Count1Resources(_self, _args) |
| 884 | PyObject *_self; |
| 885 | PyObject *_args; |
| 886 | { |
| 887 | PyObject *_res = NULL; |
| 888 | short _rv; |
| 889 | ResType theType; |
| 890 | if (!PyArg_ParseTuple(_args, "O&", |
| 891 | PyMac_GetOSType, &theType)) |
| 892 | return NULL; |
| 893 | _rv = Count1Resources(theType); |
| 894 | { |
| 895 | OSErr _err = ResError(); |
| 896 | if (_err != noErr) return PyMac_Error(_err); |
| 897 | } |
| 898 | _res = Py_BuildValue("h", |
| 899 | _rv); |
| 900 | return _res; |
| 901 | } |
| 902 | |
| 903 | static PyObject *Res_GetIndResource(_self, _args) |
| 904 | PyObject *_self; |
| 905 | PyObject *_args; |
| 906 | { |
| 907 | PyObject *_res = NULL; |
| 908 | Handle _rv; |
| 909 | ResType theType; |
| 910 | short index; |
| 911 | if (!PyArg_ParseTuple(_args, "O&h", |
| 912 | PyMac_GetOSType, &theType, |
| 913 | &index)) |
| 914 | return NULL; |
| 915 | _rv = GetIndResource(theType, |
| 916 | index); |
| 917 | { |
| 918 | OSErr _err = ResError(); |
| 919 | if (_err != noErr) return PyMac_Error(_err); |
| 920 | } |
| 921 | _res = Py_BuildValue("O&", |
| 922 | ResObj_New, _rv); |
| 923 | return _res; |
| 924 | } |
| 925 | |
| 926 | static PyObject *Res_Get1IndResource(_self, _args) |
| 927 | PyObject *_self; |
| 928 | PyObject *_args; |
| 929 | { |
| 930 | PyObject *_res = NULL; |
| 931 | Handle _rv; |
| 932 | ResType theType; |
| 933 | short index; |
| 934 | if (!PyArg_ParseTuple(_args, "O&h", |
| 935 | PyMac_GetOSType, &theType, |
| 936 | &index)) |
| 937 | return NULL; |
| 938 | _rv = Get1IndResource(theType, |
| 939 | index); |
| 940 | { |
| 941 | OSErr _err = ResError(); |
| 942 | if (_err != noErr) return PyMac_Error(_err); |
| 943 | } |
| 944 | _res = Py_BuildValue("O&", |
| 945 | ResObj_New, _rv); |
| 946 | return _res; |
| 947 | } |
| 948 | |
| 949 | static PyObject *Res_GetResource(_self, _args) |
| 950 | PyObject *_self; |
| 951 | PyObject *_args; |
| 952 | { |
| 953 | PyObject *_res = NULL; |
| 954 | Handle _rv; |
| 955 | ResType theType; |
| 956 | short theID; |
| 957 | if (!PyArg_ParseTuple(_args, "O&h", |
| 958 | PyMac_GetOSType, &theType, |
| 959 | &theID)) |
| 960 | return NULL; |
| 961 | _rv = GetResource(theType, |
| 962 | theID); |
| 963 | { |
| 964 | OSErr _err = ResError(); |
| 965 | if (_err != noErr) return PyMac_Error(_err); |
| 966 | } |
| 967 | _res = Py_BuildValue("O&", |
| 968 | ResObj_New, _rv); |
| 969 | return _res; |
| 970 | } |
| 971 | |
| 972 | static PyObject *Res_Get1Resource(_self, _args) |
| 973 | PyObject *_self; |
| 974 | PyObject *_args; |
| 975 | { |
| 976 | PyObject *_res = NULL; |
| 977 | Handle _rv; |
| 978 | ResType theType; |
| 979 | short theID; |
| 980 | if (!PyArg_ParseTuple(_args, "O&h", |
| 981 | PyMac_GetOSType, &theType, |
| 982 | &theID)) |
| 983 | return NULL; |
| 984 | _rv = Get1Resource(theType, |
| 985 | theID); |
| 986 | { |
| 987 | OSErr _err = ResError(); |
| 988 | if (_err != noErr) return PyMac_Error(_err); |
| 989 | } |
| 990 | _res = Py_BuildValue("O&", |
| 991 | ResObj_New, _rv); |
| 992 | return _res; |
| 993 | } |
| 994 | |
| 995 | static PyObject *Res_GetNamedResource(_self, _args) |
| 996 | PyObject *_self; |
| 997 | PyObject *_args; |
| 998 | { |
| 999 | PyObject *_res = NULL; |
| 1000 | Handle _rv; |
| 1001 | ResType theType; |
| 1002 | Str255 name; |
| 1003 | if (!PyArg_ParseTuple(_args, "O&O&", |
| 1004 | PyMac_GetOSType, &theType, |
| 1005 | PyMac_GetStr255, name)) |
| 1006 | return NULL; |
| 1007 | _rv = GetNamedResource(theType, |
| 1008 | name); |
| 1009 | { |
| 1010 | OSErr _err = ResError(); |
| 1011 | if (_err != noErr) return PyMac_Error(_err); |
| 1012 | } |
| 1013 | _res = Py_BuildValue("O&", |
| 1014 | ResObj_New, _rv); |
| 1015 | return _res; |
| 1016 | } |
| 1017 | |
| 1018 | static PyObject *Res_Get1NamedResource(_self, _args) |
| 1019 | PyObject *_self; |
| 1020 | PyObject *_args; |
| 1021 | { |
| 1022 | PyObject *_res = NULL; |
| 1023 | Handle _rv; |
| 1024 | ResType theType; |
| 1025 | Str255 name; |
| 1026 | if (!PyArg_ParseTuple(_args, "O&O&", |
| 1027 | PyMac_GetOSType, &theType, |
| 1028 | PyMac_GetStr255, name)) |
| 1029 | return NULL; |
| 1030 | _rv = Get1NamedResource(theType, |
| 1031 | name); |
| 1032 | { |
| 1033 | OSErr _err = ResError(); |
| 1034 | if (_err != noErr) return PyMac_Error(_err); |
| 1035 | } |
| 1036 | _res = Py_BuildValue("O&", |
| 1037 | ResObj_New, _rv); |
| 1038 | return _res; |
| 1039 | } |
| 1040 | |
| 1041 | static PyObject *Res_UniqueID(_self, _args) |
| 1042 | PyObject *_self; |
| 1043 | PyObject *_args; |
| 1044 | { |
| 1045 | PyObject *_res = NULL; |
| 1046 | short _rv; |
| 1047 | ResType theType; |
| 1048 | if (!PyArg_ParseTuple(_args, "O&", |
| 1049 | PyMac_GetOSType, &theType)) |
| 1050 | return NULL; |
| 1051 | _rv = UniqueID(theType); |
| 1052 | { |
| 1053 | OSErr _err = ResError(); |
| 1054 | if (_err != noErr) return PyMac_Error(_err); |
| 1055 | } |
| 1056 | _res = Py_BuildValue("h", |
| 1057 | _rv); |
| 1058 | return _res; |
| 1059 | } |
| 1060 | |
| 1061 | static PyObject *Res_Unique1ID(_self, _args) |
| 1062 | PyObject *_self; |
| 1063 | PyObject *_args; |
| 1064 | { |
| 1065 | PyObject *_res = NULL; |
| 1066 | short _rv; |
| 1067 | ResType theType; |
| 1068 | if (!PyArg_ParseTuple(_args, "O&", |
| 1069 | PyMac_GetOSType, &theType)) |
| 1070 | return NULL; |
| 1071 | _rv = Unique1ID(theType); |
| 1072 | { |
| 1073 | OSErr _err = ResError(); |
| 1074 | if (_err != noErr) return PyMac_Error(_err); |
| 1075 | } |
| 1076 | _res = Py_BuildValue("h", |
| 1077 | _rv); |
| 1078 | return _res; |
| 1079 | } |
| 1080 | |
| 1081 | static PyObject *Res_UpdateResFile(_self, _args) |
| 1082 | PyObject *_self; |
| 1083 | PyObject *_args; |
| 1084 | { |
| 1085 | PyObject *_res = NULL; |
| 1086 | short refNum; |
| 1087 | if (!PyArg_ParseTuple(_args, "h", |
| 1088 | &refNum)) |
| 1089 | return NULL; |
| 1090 | UpdateResFile(refNum); |
| 1091 | { |
| 1092 | OSErr _err = ResError(); |
| 1093 | if (_err != noErr) return PyMac_Error(_err); |
| 1094 | } |
| 1095 | Py_INCREF(Py_None); |
| 1096 | _res = Py_None; |
| 1097 | return _res; |
| 1098 | } |
| 1099 | |
| 1100 | static PyObject *Res_SetResPurge(_self, _args) |
| 1101 | PyObject *_self; |
| 1102 | PyObject *_args; |
| 1103 | { |
| 1104 | PyObject *_res = NULL; |
| 1105 | Boolean install; |
| 1106 | if (!PyArg_ParseTuple(_args, "b", |
| 1107 | &install)) |
| 1108 | return NULL; |
| 1109 | SetResPurge(install); |
| 1110 | { |
| 1111 | OSErr _err = ResError(); |
| 1112 | if (_err != noErr) return PyMac_Error(_err); |
| 1113 | } |
| 1114 | Py_INCREF(Py_None); |
| 1115 | _res = Py_None; |
| 1116 | return _res; |
| 1117 | } |
| 1118 | |
| 1119 | static PyObject *Res_GetResFileAttrs(_self, _args) |
| 1120 | PyObject *_self; |
| 1121 | PyObject *_args; |
| 1122 | { |
| 1123 | PyObject *_res = NULL; |
| 1124 | short _rv; |
| 1125 | short refNum; |
| 1126 | if (!PyArg_ParseTuple(_args, "h", |
| 1127 | &refNum)) |
| 1128 | return NULL; |
| 1129 | _rv = GetResFileAttrs(refNum); |
| 1130 | { |
| 1131 | OSErr _err = ResError(); |
| 1132 | if (_err != noErr) return PyMac_Error(_err); |
| 1133 | } |
| 1134 | _res = Py_BuildValue("h", |
| 1135 | _rv); |
| 1136 | return _res; |
| 1137 | } |
| 1138 | |
| 1139 | static PyObject *Res_SetResFileAttrs(_self, _args) |
| 1140 | PyObject *_self; |
| 1141 | PyObject *_args; |
| 1142 | { |
| 1143 | PyObject *_res = NULL; |
| 1144 | short refNum; |
| 1145 | short attrs; |
| 1146 | if (!PyArg_ParseTuple(_args, "hh", |
| 1147 | &refNum, |
| 1148 | &attrs)) |
| 1149 | return NULL; |
| 1150 | SetResFileAttrs(refNum, |
| 1151 | attrs); |
| 1152 | { |
| 1153 | OSErr _err = ResError(); |
| 1154 | if (_err != noErr) return PyMac_Error(_err); |
| 1155 | } |
| 1156 | Py_INCREF(Py_None); |
| 1157 | _res = Py_None; |
| 1158 | return _res; |
| 1159 | } |
| 1160 | |
| 1161 | static PyObject *Res_OpenRFPerm(_self, _args) |
| 1162 | PyObject *_self; |
| 1163 | PyObject *_args; |
| 1164 | { |
| 1165 | PyObject *_res = NULL; |
| 1166 | short _rv; |
| 1167 | Str255 fileName; |
| 1168 | short vRefNum; |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 1169 | SignedByte permission; |
| 1170 | if (!PyArg_ParseTuple(_args, "O&hb", |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1171 | PyMac_GetStr255, fileName, |
| 1172 | &vRefNum, |
| 1173 | &permission)) |
| 1174 | return NULL; |
| 1175 | _rv = OpenRFPerm(fileName, |
| 1176 | vRefNum, |
| 1177 | permission); |
| 1178 | { |
| 1179 | OSErr _err = ResError(); |
| 1180 | if (_err != noErr) return PyMac_Error(_err); |
| 1181 | } |
| 1182 | _res = Py_BuildValue("h", |
| 1183 | _rv); |
| 1184 | return _res; |
| 1185 | } |
| 1186 | |
Jack Jansen | 74a1e63 | 2000-07-14 22:37:27 +0000 | [diff] [blame] | 1187 | #if !TARGET_API_MAC_CARBON |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 1188 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1189 | static PyObject *Res_RGetResource(_self, _args) |
| 1190 | PyObject *_self; |
| 1191 | PyObject *_args; |
| 1192 | { |
| 1193 | PyObject *_res = NULL; |
| 1194 | Handle _rv; |
| 1195 | ResType theType; |
| 1196 | short theID; |
| 1197 | if (!PyArg_ParseTuple(_args, "O&h", |
| 1198 | PyMac_GetOSType, &theType, |
| 1199 | &theID)) |
| 1200 | return NULL; |
| 1201 | _rv = RGetResource(theType, |
| 1202 | theID); |
| 1203 | { |
| 1204 | OSErr _err = ResError(); |
| 1205 | if (_err != noErr) return PyMac_Error(_err); |
| 1206 | } |
| 1207 | _res = Py_BuildValue("O&", |
| 1208 | ResObj_New, _rv); |
| 1209 | return _res; |
| 1210 | } |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 1211 | #endif |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1212 | |
| 1213 | static PyObject *Res_HOpenResFile(_self, _args) |
| 1214 | PyObject *_self; |
| 1215 | PyObject *_args; |
| 1216 | { |
| 1217 | PyObject *_res = NULL; |
| 1218 | short _rv; |
| 1219 | short vRefNum; |
| 1220 | long dirID; |
| 1221 | Str255 fileName; |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 1222 | SignedByte permission; |
| 1223 | if (!PyArg_ParseTuple(_args, "hlO&b", |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1224 | &vRefNum, |
| 1225 | &dirID, |
| 1226 | PyMac_GetStr255, fileName, |
| 1227 | &permission)) |
| 1228 | return NULL; |
| 1229 | _rv = HOpenResFile(vRefNum, |
| 1230 | dirID, |
| 1231 | fileName, |
| 1232 | permission); |
| 1233 | { |
| 1234 | OSErr _err = ResError(); |
| 1235 | if (_err != noErr) return PyMac_Error(_err); |
| 1236 | } |
| 1237 | _res = Py_BuildValue("h", |
| 1238 | _rv); |
| 1239 | return _res; |
| 1240 | } |
| 1241 | |
| 1242 | static PyObject *Res_HCreateResFile(_self, _args) |
| 1243 | PyObject *_self; |
| 1244 | PyObject *_args; |
| 1245 | { |
| 1246 | PyObject *_res = NULL; |
| 1247 | short vRefNum; |
| 1248 | long dirID; |
| 1249 | Str255 fileName; |
| 1250 | if (!PyArg_ParseTuple(_args, "hlO&", |
| 1251 | &vRefNum, |
| 1252 | &dirID, |
| 1253 | PyMac_GetStr255, fileName)) |
| 1254 | return NULL; |
| 1255 | HCreateResFile(vRefNum, |
| 1256 | dirID, |
| 1257 | fileName); |
| 1258 | { |
| 1259 | OSErr _err = ResError(); |
| 1260 | if (_err != noErr) return PyMac_Error(_err); |
| 1261 | } |
| 1262 | Py_INCREF(Py_None); |
| 1263 | _res = Py_None; |
| 1264 | return _res; |
| 1265 | } |
| 1266 | |
| 1267 | static PyObject *Res_FSpOpenResFile(_self, _args) |
| 1268 | PyObject *_self; |
| 1269 | PyObject *_args; |
| 1270 | { |
| 1271 | PyObject *_res = NULL; |
| 1272 | short _rv; |
| 1273 | FSSpec spec; |
| 1274 | SignedByte permission; |
| 1275 | if (!PyArg_ParseTuple(_args, "O&b", |
| 1276 | PyMac_GetFSSpec, &spec, |
| 1277 | &permission)) |
| 1278 | return NULL; |
| 1279 | _rv = FSpOpenResFile(&spec, |
| 1280 | permission); |
| 1281 | { |
| 1282 | OSErr _err = ResError(); |
| 1283 | if (_err != noErr) return PyMac_Error(_err); |
| 1284 | } |
| 1285 | _res = Py_BuildValue("h", |
| 1286 | _rv); |
| 1287 | return _res; |
| 1288 | } |
| 1289 | |
| 1290 | static PyObject *Res_FSpCreateResFile(_self, _args) |
| 1291 | PyObject *_self; |
| 1292 | PyObject *_args; |
| 1293 | { |
| 1294 | PyObject *_res = NULL; |
| 1295 | FSSpec spec; |
| 1296 | OSType creator; |
| 1297 | OSType fileType; |
| 1298 | ScriptCode scriptTag; |
| 1299 | if (!PyArg_ParseTuple(_args, "O&O&O&h", |
| 1300 | PyMac_GetFSSpec, &spec, |
| 1301 | PyMac_GetOSType, &creator, |
| 1302 | PyMac_GetOSType, &fileType, |
| 1303 | &scriptTag)) |
| 1304 | return NULL; |
| 1305 | FSpCreateResFile(&spec, |
| 1306 | creator, |
| 1307 | fileType, |
| 1308 | scriptTag); |
| 1309 | { |
| 1310 | OSErr _err = ResError(); |
| 1311 | if (_err != noErr) return PyMac_Error(_err); |
| 1312 | } |
| 1313 | Py_INCREF(Py_None); |
| 1314 | _res = Py_None; |
| 1315 | return _res; |
| 1316 | } |
| 1317 | |
Jack Jansen | 723ad8a | 2000-12-12 22:10:21 +0000 | [diff] [blame] | 1318 | #if TARGET_API_MAC_CARBON |
| 1319 | |
| 1320 | static PyObject *Res_InsertResourceFile(_self, _args) |
| 1321 | PyObject *_self; |
| 1322 | PyObject *_args; |
| 1323 | { |
| 1324 | PyObject *_res = NULL; |
| 1325 | OSErr _rv; |
| 1326 | SInt16 refNum; |
| 1327 | RsrcChainLocation where; |
| 1328 | if (!PyArg_ParseTuple(_args, "hh", |
| 1329 | &refNum, |
| 1330 | &where)) |
| 1331 | return NULL; |
| 1332 | _rv = InsertResourceFile(refNum, |
| 1333 | where); |
| 1334 | { |
| 1335 | OSErr _err = ResError(); |
| 1336 | if (_err != noErr) return PyMac_Error(_err); |
| 1337 | } |
| 1338 | _res = Py_BuildValue("h", |
| 1339 | _rv); |
| 1340 | return _res; |
| 1341 | } |
| 1342 | #endif |
| 1343 | |
| 1344 | #if TARGET_API_MAC_CARBON |
| 1345 | |
| 1346 | static PyObject *Res_DetachResourceFile(_self, _args) |
| 1347 | PyObject *_self; |
| 1348 | PyObject *_args; |
| 1349 | { |
| 1350 | PyObject *_res = NULL; |
| 1351 | OSErr _rv; |
| 1352 | SInt16 refNum; |
| 1353 | if (!PyArg_ParseTuple(_args, "h", |
| 1354 | &refNum)) |
| 1355 | return NULL; |
| 1356 | _rv = DetachResourceFile(refNum); |
| 1357 | { |
| 1358 | OSErr _err = ResError(); |
| 1359 | if (_err != noErr) return PyMac_Error(_err); |
| 1360 | } |
| 1361 | _res = Py_BuildValue("h", |
| 1362 | _rv); |
| 1363 | return _res; |
| 1364 | } |
| 1365 | #endif |
| 1366 | |
Jack Jansen | 043732e | 2001-03-02 16:32:03 +0000 | [diff] [blame] | 1367 | #if TARGET_API_MAC_CARBON |
| 1368 | |
Jack Jansen | 723ad8a | 2000-12-12 22:10:21 +0000 | [diff] [blame] | 1369 | static PyObject *Res_FSpResourceFileAlreadyOpen(_self, _args) |
| 1370 | PyObject *_self; |
| 1371 | PyObject *_args; |
| 1372 | { |
| 1373 | PyObject *_res = NULL; |
| 1374 | Boolean _rv; |
| 1375 | FSSpec resourceFile; |
| 1376 | Boolean inChain; |
| 1377 | SInt16 refNum; |
| 1378 | if (!PyArg_ParseTuple(_args, "O&", |
| 1379 | PyMac_GetFSSpec, &resourceFile)) |
| 1380 | return NULL; |
| 1381 | _rv = FSpResourceFileAlreadyOpen(&resourceFile, |
| 1382 | &inChain, |
| 1383 | &refNum); |
| 1384 | { |
| 1385 | OSErr _err = ResError(); |
| 1386 | if (_err != noErr) return PyMac_Error(_err); |
| 1387 | } |
| 1388 | _res = Py_BuildValue("bbh", |
| 1389 | _rv, |
| 1390 | inChain, |
| 1391 | refNum); |
| 1392 | return _res; |
| 1393 | } |
Jack Jansen | 043732e | 2001-03-02 16:32:03 +0000 | [diff] [blame] | 1394 | #endif |
Jack Jansen | 723ad8a | 2000-12-12 22:10:21 +0000 | [diff] [blame] | 1395 | |
| 1396 | #if TARGET_API_MAC_CARBON |
| 1397 | |
| 1398 | static PyObject *Res_FSpOpenOrphanResFile(_self, _args) |
| 1399 | PyObject *_self; |
| 1400 | PyObject *_args; |
| 1401 | { |
| 1402 | PyObject *_res = NULL; |
| 1403 | OSErr _rv; |
| 1404 | FSSpec spec; |
| 1405 | SignedByte permission; |
| 1406 | SInt16 refNum; |
| 1407 | if (!PyArg_ParseTuple(_args, "O&b", |
| 1408 | PyMac_GetFSSpec, &spec, |
| 1409 | &permission)) |
| 1410 | return NULL; |
| 1411 | _rv = FSpOpenOrphanResFile(&spec, |
| 1412 | permission, |
| 1413 | &refNum); |
| 1414 | { |
| 1415 | OSErr _err = ResError(); |
| 1416 | if (_err != noErr) return PyMac_Error(_err); |
| 1417 | } |
| 1418 | _res = Py_BuildValue("hh", |
| 1419 | _rv, |
| 1420 | refNum); |
| 1421 | return _res; |
| 1422 | } |
| 1423 | #endif |
| 1424 | |
| 1425 | #if TARGET_API_MAC_CARBON |
| 1426 | |
| 1427 | static PyObject *Res_GetTopResourceFile(_self, _args) |
| 1428 | PyObject *_self; |
| 1429 | PyObject *_args; |
| 1430 | { |
| 1431 | PyObject *_res = NULL; |
| 1432 | OSErr _rv; |
| 1433 | SInt16 refNum; |
| 1434 | if (!PyArg_ParseTuple(_args, "")) |
| 1435 | return NULL; |
| 1436 | _rv = GetTopResourceFile(&refNum); |
| 1437 | { |
| 1438 | OSErr _err = ResError(); |
| 1439 | if (_err != noErr) return PyMac_Error(_err); |
| 1440 | } |
| 1441 | _res = Py_BuildValue("hh", |
| 1442 | _rv, |
| 1443 | refNum); |
| 1444 | return _res; |
| 1445 | } |
| 1446 | #endif |
| 1447 | |
| 1448 | #if TARGET_API_MAC_CARBON |
| 1449 | |
| 1450 | static PyObject *Res_GetNextResourceFile(_self, _args) |
| 1451 | PyObject *_self; |
| 1452 | PyObject *_args; |
| 1453 | { |
| 1454 | PyObject *_res = NULL; |
| 1455 | OSErr _rv; |
| 1456 | SInt16 curRefNum; |
| 1457 | SInt16 nextRefNum; |
| 1458 | if (!PyArg_ParseTuple(_args, "h", |
| 1459 | &curRefNum)) |
| 1460 | return NULL; |
| 1461 | _rv = GetNextResourceFile(curRefNum, |
| 1462 | &nextRefNum); |
| 1463 | { |
| 1464 | OSErr _err = ResError(); |
| 1465 | if (_err != noErr) return PyMac_Error(_err); |
| 1466 | } |
| 1467 | _res = Py_BuildValue("hh", |
| 1468 | _rv, |
| 1469 | nextRefNum); |
| 1470 | return _res; |
| 1471 | } |
| 1472 | #endif |
| 1473 | |
Guido van Rossum | 9bcb641 | 1995-02-05 16:54:27 +0000 | [diff] [blame] | 1474 | static PyObject *Res_Resource(_self, _args) |
| 1475 | PyObject *_self; |
| 1476 | PyObject *_args; |
| 1477 | { |
| 1478 | PyObject *_res = NULL; |
| 1479 | |
| 1480 | char *buf; |
| 1481 | int len; |
| 1482 | Handle h; |
| 1483 | |
| 1484 | if (!PyArg_ParseTuple(_args, "s#", &buf, &len)) |
| 1485 | return NULL; |
| 1486 | h = NewHandle(len); |
| 1487 | if ( h == NULL ) { |
| 1488 | PyErr_NoMemory(); |
| 1489 | return NULL; |
| 1490 | } |
| 1491 | HLock(h); |
| 1492 | memcpy(*h, buf, len); |
| 1493 | HUnlock(h); |
Jack Jansen | add03b6 | 2000-03-08 16:58:15 +0000 | [diff] [blame] | 1494 | return ResObj_New(h); |
| 1495 | |
| 1496 | } |
| 1497 | |
| 1498 | static PyObject *Res_Handle(_self, _args) |
| 1499 | PyObject *_self; |
| 1500 | PyObject *_args; |
| 1501 | { |
| 1502 | PyObject *_res = NULL; |
| 1503 | |
| 1504 | char *buf; |
| 1505 | int len; |
| 1506 | Handle h; |
| 1507 | ResourceObject *rv; |
| 1508 | |
| 1509 | if (!PyArg_ParseTuple(_args, "s#", &buf, &len)) |
| 1510 | return NULL; |
| 1511 | h = NewHandle(len); |
| 1512 | if ( h == NULL ) { |
| 1513 | PyErr_NoMemory(); |
| 1514 | return NULL; |
| 1515 | } |
| 1516 | HLock(h); |
| 1517 | memcpy(*h, buf, len); |
| 1518 | HUnlock(h); |
| 1519 | rv = (ResourceObject *)ResObj_New(h); |
| 1520 | rv->ob_freeit = PyMac_AutoDisposeHandle; |
| 1521 | return (PyObject *)rv; |
Guido van Rossum | 9bcb641 | 1995-02-05 16:54:27 +0000 | [diff] [blame] | 1522 | |
| 1523 | } |
| 1524 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1525 | static PyMethodDef Res_methods[] = { |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 1526 | |
Jack Jansen | 74a1e63 | 2000-07-14 22:37:27 +0000 | [diff] [blame] | 1527 | #if !TARGET_API_MAC_CARBON |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1528 | {"InitResources", (PyCFunction)Res_InitResources, 1, |
| 1529 | "() -> (short _rv)"}, |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 1530 | #endif |
| 1531 | |
Jack Jansen | 74a1e63 | 2000-07-14 22:37:27 +0000 | [diff] [blame] | 1532 | #if !TARGET_API_MAC_CARBON |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1533 | {"RsrcZoneInit", (PyCFunction)Res_RsrcZoneInit, 1, |
| 1534 | "() -> None"}, |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 1535 | #endif |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1536 | {"CloseResFile", (PyCFunction)Res_CloseResFile, 1, |
| 1537 | "(short refNum) -> None"}, |
| 1538 | {"ResError", (PyCFunction)Res_ResError, 1, |
Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 1539 | "() -> (OSErr _rv)"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1540 | {"CurResFile", (PyCFunction)Res_CurResFile, 1, |
| 1541 | "() -> (short _rv)"}, |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 1542 | |
Jack Jansen | 74a1e63 | 2000-07-14 22:37:27 +0000 | [diff] [blame] | 1543 | #if !TARGET_API_MAC_CARBON |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1544 | {"CreateResFile", (PyCFunction)Res_CreateResFile, 1, |
| 1545 | "(Str255 fileName) -> None"}, |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 1546 | #endif |
| 1547 | |
Jack Jansen | 74a1e63 | 2000-07-14 22:37:27 +0000 | [diff] [blame] | 1548 | #if !TARGET_API_MAC_CARBON |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1549 | {"OpenResFile", (PyCFunction)Res_OpenResFile, 1, |
| 1550 | "(Str255 fileName) -> (short _rv)"}, |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 1551 | #endif |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1552 | {"UseResFile", (PyCFunction)Res_UseResFile, 1, |
| 1553 | "(short refNum) -> None"}, |
| 1554 | {"CountTypes", (PyCFunction)Res_CountTypes, 1, |
| 1555 | "() -> (short _rv)"}, |
| 1556 | {"Count1Types", (PyCFunction)Res_Count1Types, 1, |
| 1557 | "() -> (short _rv)"}, |
| 1558 | {"GetIndType", (PyCFunction)Res_GetIndType, 1, |
| 1559 | "(short index) -> (ResType theType)"}, |
| 1560 | {"Get1IndType", (PyCFunction)Res_Get1IndType, 1, |
| 1561 | "(short index) -> (ResType theType)"}, |
| 1562 | {"SetResLoad", (PyCFunction)Res_SetResLoad, 1, |
| 1563 | "(Boolean load) -> None"}, |
| 1564 | {"CountResources", (PyCFunction)Res_CountResources, 1, |
| 1565 | "(ResType theType) -> (short _rv)"}, |
| 1566 | {"Count1Resources", (PyCFunction)Res_Count1Resources, 1, |
| 1567 | "(ResType theType) -> (short _rv)"}, |
| 1568 | {"GetIndResource", (PyCFunction)Res_GetIndResource, 1, |
| 1569 | "(ResType theType, short index) -> (Handle _rv)"}, |
| 1570 | {"Get1IndResource", (PyCFunction)Res_Get1IndResource, 1, |
| 1571 | "(ResType theType, short index) -> (Handle _rv)"}, |
| 1572 | {"GetResource", (PyCFunction)Res_GetResource, 1, |
| 1573 | "(ResType theType, short theID) -> (Handle _rv)"}, |
| 1574 | {"Get1Resource", (PyCFunction)Res_Get1Resource, 1, |
| 1575 | "(ResType theType, short theID) -> (Handle _rv)"}, |
| 1576 | {"GetNamedResource", (PyCFunction)Res_GetNamedResource, 1, |
| 1577 | "(ResType theType, Str255 name) -> (Handle _rv)"}, |
| 1578 | {"Get1NamedResource", (PyCFunction)Res_Get1NamedResource, 1, |
| 1579 | "(ResType theType, Str255 name) -> (Handle _rv)"}, |
| 1580 | {"UniqueID", (PyCFunction)Res_UniqueID, 1, |
| 1581 | "(ResType theType) -> (short _rv)"}, |
| 1582 | {"Unique1ID", (PyCFunction)Res_Unique1ID, 1, |
| 1583 | "(ResType theType) -> (short _rv)"}, |
| 1584 | {"UpdateResFile", (PyCFunction)Res_UpdateResFile, 1, |
| 1585 | "(short refNum) -> None"}, |
| 1586 | {"SetResPurge", (PyCFunction)Res_SetResPurge, 1, |
| 1587 | "(Boolean install) -> None"}, |
| 1588 | {"GetResFileAttrs", (PyCFunction)Res_GetResFileAttrs, 1, |
| 1589 | "(short refNum) -> (short _rv)"}, |
| 1590 | {"SetResFileAttrs", (PyCFunction)Res_SetResFileAttrs, 1, |
| 1591 | "(short refNum, short attrs) -> None"}, |
| 1592 | {"OpenRFPerm", (PyCFunction)Res_OpenRFPerm, 1, |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 1593 | "(Str255 fileName, short vRefNum, SignedByte permission) -> (short _rv)"}, |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 1594 | |
Jack Jansen | 74a1e63 | 2000-07-14 22:37:27 +0000 | [diff] [blame] | 1595 | #if !TARGET_API_MAC_CARBON |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1596 | {"RGetResource", (PyCFunction)Res_RGetResource, 1, |
| 1597 | "(ResType theType, short theID) -> (Handle _rv)"}, |
Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 1598 | #endif |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1599 | {"HOpenResFile", (PyCFunction)Res_HOpenResFile, 1, |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 1600 | "(short vRefNum, long dirID, Str255 fileName, SignedByte permission) -> (short _rv)"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1601 | {"HCreateResFile", (PyCFunction)Res_HCreateResFile, 1, |
| 1602 | "(short vRefNum, long dirID, Str255 fileName) -> None"}, |
| 1603 | {"FSpOpenResFile", (PyCFunction)Res_FSpOpenResFile, 1, |
| 1604 | "(FSSpec spec, SignedByte permission) -> (short _rv)"}, |
| 1605 | {"FSpCreateResFile", (PyCFunction)Res_FSpCreateResFile, 1, |
| 1606 | "(FSSpec spec, OSType creator, OSType fileType, ScriptCode scriptTag) -> None"}, |
Jack Jansen | 723ad8a | 2000-12-12 22:10:21 +0000 | [diff] [blame] | 1607 | |
| 1608 | #if TARGET_API_MAC_CARBON |
| 1609 | {"InsertResourceFile", (PyCFunction)Res_InsertResourceFile, 1, |
| 1610 | "(SInt16 refNum, RsrcChainLocation where) -> (OSErr _rv)"}, |
| 1611 | #endif |
| 1612 | |
| 1613 | #if TARGET_API_MAC_CARBON |
| 1614 | {"DetachResourceFile", (PyCFunction)Res_DetachResourceFile, 1, |
| 1615 | "(SInt16 refNum) -> (OSErr _rv)"}, |
| 1616 | #endif |
Jack Jansen | 043732e | 2001-03-02 16:32:03 +0000 | [diff] [blame] | 1617 | |
| 1618 | #if TARGET_API_MAC_CARBON |
Jack Jansen | 723ad8a | 2000-12-12 22:10:21 +0000 | [diff] [blame] | 1619 | {"FSpResourceFileAlreadyOpen", (PyCFunction)Res_FSpResourceFileAlreadyOpen, 1, |
| 1620 | "(FSSpec resourceFile) -> (Boolean _rv, Boolean inChain, SInt16 refNum)"}, |
Jack Jansen | 043732e | 2001-03-02 16:32:03 +0000 | [diff] [blame] | 1621 | #endif |
Jack Jansen | 723ad8a | 2000-12-12 22:10:21 +0000 | [diff] [blame] | 1622 | |
| 1623 | #if TARGET_API_MAC_CARBON |
| 1624 | {"FSpOpenOrphanResFile", (PyCFunction)Res_FSpOpenOrphanResFile, 1, |
| 1625 | "(FSSpec spec, SignedByte permission) -> (OSErr _rv, SInt16 refNum)"}, |
| 1626 | #endif |
| 1627 | |
| 1628 | #if TARGET_API_MAC_CARBON |
| 1629 | {"GetTopResourceFile", (PyCFunction)Res_GetTopResourceFile, 1, |
| 1630 | "() -> (OSErr _rv, SInt16 refNum)"}, |
| 1631 | #endif |
| 1632 | |
| 1633 | #if TARGET_API_MAC_CARBON |
| 1634 | {"GetNextResourceFile", (PyCFunction)Res_GetNextResourceFile, 1, |
| 1635 | "(SInt16 curRefNum) -> (OSErr _rv, SInt16 nextRefNum)"}, |
| 1636 | #endif |
Guido van Rossum | 9bcb641 | 1995-02-05 16:54:27 +0000 | [diff] [blame] | 1637 | {"Resource", (PyCFunction)Res_Resource, 1, |
Jack Jansen | add03b6 | 2000-03-08 16:58:15 +0000 | [diff] [blame] | 1638 | "Convert a string to a resource object.\n\nThe created resource object is actually just a handle,\napply AddResource() to write it to a resource file.\nSee also the Handle() docstring.\n"}, |
| 1639 | {"Handle", (PyCFunction)Res_Handle, 1, |
| 1640 | "Convert a string to a Handle object.\n\nResource() and Handle() are very similar, but objects created with Handle() are\nby default automatically DisposeHandle()d upon object cleanup. Use AutoDispose()\nto change this.\n"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1641 | {NULL, NULL, 0} |
| 1642 | }; |
| 1643 | |
| 1644 | |
| 1645 | |
| 1646 | |
Jack Jansen | d4c2646 | 1995-08-17 14:35:56 +0000 | [diff] [blame] | 1647 | /* Alternative version of ResObj_New, which returns None for null argument */ |
Jack Jansen | 425e9eb | 1995-12-12 15:02:03 +0000 | [diff] [blame] | 1648 | PyObject *OptResObj_New(itself) |
Jack Jansen | d4c2646 | 1995-08-17 14:35:56 +0000 | [diff] [blame] | 1649 | Handle itself; |
| 1650 | { |
Jack Jansen | d4c2646 | 1995-08-17 14:35:56 +0000 | [diff] [blame] | 1651 | if (itself == NULL) { |
| 1652 | Py_INCREF(Py_None); |
| 1653 | return Py_None; |
| 1654 | } |
| 1655 | return ResObj_New(itself); |
| 1656 | } |
| 1657 | |
Jack Jansen | 425e9eb | 1995-12-12 15:02:03 +0000 | [diff] [blame] | 1658 | OptResObj_Convert(v, p_itself) |
| 1659 | PyObject *v; |
| 1660 | Handle *p_itself; |
| 1661 | { |
Jack Jansen | 2d76c25 | 1999-12-12 22:57:29 +0000 | [diff] [blame] | 1662 | PyObject *tmp; |
| 1663 | |
Jack Jansen | 425e9eb | 1995-12-12 15:02:03 +0000 | [diff] [blame] | 1664 | if ( v == Py_None ) { |
| 1665 | *p_itself = NULL; |
| 1666 | return 1; |
| 1667 | } |
Jack Jansen | 2d76c25 | 1999-12-12 22:57:29 +0000 | [diff] [blame] | 1668 | if (ResObj_Check(v)) |
Jack Jansen | 425e9eb | 1995-12-12 15:02:03 +0000 | [diff] [blame] | 1669 | { |
Jack Jansen | 2d76c25 | 1999-12-12 22:57:29 +0000 | [diff] [blame] | 1670 | *p_itself = ((ResourceObject *)v)->ob_itself; |
| 1671 | return 1; |
Jack Jansen | 425e9eb | 1995-12-12 15:02:03 +0000 | [diff] [blame] | 1672 | } |
Jack Jansen | 2d76c25 | 1999-12-12 22:57:29 +0000 | [diff] [blame] | 1673 | /* If it isn't a resource yet see whether it is convertible */ |
| 1674 | if ( (tmp=PyObject_CallMethod(v, "as_Resource", "")) ) { |
| 1675 | *p_itself = ((ResourceObject *)tmp)->ob_itself; |
| 1676 | Py_DECREF(tmp); |
| 1677 | return 1; |
| 1678 | } |
| 1679 | PyErr_Clear(); |
| 1680 | PyErr_SetString(PyExc_TypeError, "Resource required"); |
| 1681 | return 0; |
Jack Jansen | 425e9eb | 1995-12-12 15:02:03 +0000 | [diff] [blame] | 1682 | } |
| 1683 | |
Jack Jansen | d4c2646 | 1995-08-17 14:35:56 +0000 | [diff] [blame] | 1684 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1685 | void initRes() |
| 1686 | { |
| 1687 | PyObject *m; |
| 1688 | PyObject *d; |
| 1689 | |
| 1690 | |
| 1691 | |
Jack Jansen | 0e04eec | 2001-05-17 21:58:34 +0000 | [diff] [blame] | 1692 | PyMac_INIT_TOOLBOX_OBJECT_NEW(ResObj_New); |
| 1693 | PyMac_INIT_TOOLBOX_OBJECT_CONVERT(ResObj_Convert); |
| 1694 | PyMac_INIT_TOOLBOX_OBJECT_NEW(OptResObj_New); |
| 1695 | PyMac_INIT_TOOLBOX_OBJECT_CONVERT(OptResObj_Convert); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1696 | |
| 1697 | |
| 1698 | m = Py_InitModule("Res", Res_methods); |
| 1699 | d = PyModule_GetDict(m); |
| 1700 | Res_Error = PyMac_GetOSErrException(); |
| 1701 | if (Res_Error == NULL || |
| 1702 | PyDict_SetItemString(d, "Error", Res_Error) != 0) |
Jack Jansen | 723ad8a | 2000-12-12 22:10:21 +0000 | [diff] [blame] | 1703 | return; |
Jack Jansen | a755e68 | 1997-09-20 17:40:22 +0000 | [diff] [blame] | 1704 | Resource_Type.ob_type = &PyType_Type; |
| 1705 | Py_INCREF(&Resource_Type); |
| 1706 | if (PyDict_SetItemString(d, "ResourceType", (PyObject *)&Resource_Type) != 0) |
| 1707 | Py_FatalError("can't initialize ResourceType"); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1708 | } |
| 1709 | |
| 1710 | /* ========================= End module Res ========================= */ |
| 1711 | |