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 | |
| 8 | #define SystemSevenOrLater 1 |
| 9 | |
| 10 | #include "macglue.h" |
| 11 | #include <Memory.h> |
| 12 | #include <Dialogs.h> |
| 13 | #include <Menus.h> |
| 14 | #include <Controls.h> |
| 15 | |
| 16 | extern PyObject *ResObj_New(Handle); |
| 17 | extern int ResObj_Convert(PyObject *, Handle *); |
| 18 | |
| 19 | extern PyObject *WinObj_New(WindowPtr); |
| 20 | extern int WinObj_Convert(PyObject *, WindowPtr *); |
| 21 | |
| 22 | extern PyObject *DlgObj_New(DialogPtr); |
| 23 | extern int DlgObj_Convert(PyObject *, DialogPtr *); |
| 24 | extern PyTypeObject Dialog_Type; |
| 25 | #define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type) |
| 26 | |
| 27 | extern PyObject *MenuObj_New(MenuHandle); |
| 28 | extern int MenuObj_Convert(PyObject *, MenuHandle *); |
| 29 | |
| 30 | extern PyObject *CtlObj_New(ControlHandle); |
| 31 | extern int CtlObj_Convert(PyObject *, ControlHandle *); |
| 32 | |
Guido van Rossum | 9bcb641 | 1995-02-05 16:54:27 +0000 | [diff] [blame] | 33 | extern PyObject *WinObj_WhichWindow(WindowPtr); |
| 34 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 35 | #include <Resources.h> |
| 36 | |
| 37 | #define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */ |
| 38 | |
| 39 | static PyObject *Res_Error; |
| 40 | |
| 41 | /* ---------------------- Object type Resource ---------------------- */ |
| 42 | |
| 43 | PyTypeObject Resource_Type; |
| 44 | |
| 45 | #define ResObj_Check(x) ((x)->ob_type == &Resource_Type) |
| 46 | |
| 47 | typedef struct ResourceObject { |
| 48 | PyObject_HEAD |
| 49 | Handle ob_itself; |
| 50 | } ResourceObject; |
| 51 | |
| 52 | PyObject *ResObj_New(itself) |
Guido van Rossum | 227a423 | 1995-03-10 14:42:57 +0000 | [diff] [blame] | 53 | Handle itself; |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 54 | { |
| 55 | ResourceObject *it; |
| 56 | if (itself == NULL) return PyMac_Error(resNotFound); |
| 57 | it = PyObject_NEW(ResourceObject, &Resource_Type); |
| 58 | if (it == NULL) return NULL; |
| 59 | it->ob_itself = itself; |
| 60 | return (PyObject *)it; |
| 61 | } |
| 62 | ResObj_Convert(v, p_itself) |
| 63 | PyObject *v; |
| 64 | Handle *p_itself; |
| 65 | { |
| 66 | if (!ResObj_Check(v)) |
| 67 | { |
| 68 | PyErr_SetString(PyExc_TypeError, "Resource required"); |
| 69 | return 0; |
| 70 | } |
| 71 | *p_itself = ((ResourceObject *)v)->ob_itself; |
| 72 | return 1; |
| 73 | } |
| 74 | |
| 75 | static void ResObj_dealloc(self) |
| 76 | ResourceObject *self; |
| 77 | { |
| 78 | /* Cleanup of self->ob_itself goes here */ |
| 79 | PyMem_DEL(self); |
| 80 | } |
| 81 | |
| 82 | static PyObject *ResObj_HomeResFile(_self, _args) |
| 83 | ResourceObject *_self; |
| 84 | PyObject *_args; |
| 85 | { |
| 86 | PyObject *_res = NULL; |
| 87 | short _rv; |
| 88 | if (!PyArg_ParseTuple(_args, "")) |
| 89 | return NULL; |
| 90 | _rv = HomeResFile(_self->ob_itself); |
| 91 | { |
| 92 | OSErr _err = ResError(); |
| 93 | if (_err != noErr) return PyMac_Error(_err); |
| 94 | } |
| 95 | _res = Py_BuildValue("h", |
| 96 | _rv); |
| 97 | return _res; |
| 98 | } |
| 99 | |
| 100 | static PyObject *ResObj_LoadResource(_self, _args) |
| 101 | ResourceObject *_self; |
| 102 | PyObject *_args; |
| 103 | { |
| 104 | PyObject *_res = NULL; |
| 105 | if (!PyArg_ParseTuple(_args, "")) |
| 106 | return NULL; |
| 107 | LoadResource(_self->ob_itself); |
| 108 | { |
| 109 | OSErr _err = ResError(); |
| 110 | if (_err != noErr) return PyMac_Error(_err); |
| 111 | } |
| 112 | Py_INCREF(Py_None); |
| 113 | _res = Py_None; |
| 114 | return _res; |
| 115 | } |
| 116 | |
| 117 | static PyObject *ResObj_ReleaseResource(_self, _args) |
| 118 | ResourceObject *_self; |
| 119 | PyObject *_args; |
| 120 | { |
| 121 | PyObject *_res = NULL; |
| 122 | if (!PyArg_ParseTuple(_args, "")) |
| 123 | return NULL; |
| 124 | ReleaseResource(_self->ob_itself); |
| 125 | { |
| 126 | OSErr _err = ResError(); |
| 127 | if (_err != noErr) return PyMac_Error(_err); |
| 128 | } |
| 129 | Py_INCREF(Py_None); |
| 130 | _res = Py_None; |
| 131 | return _res; |
| 132 | } |
| 133 | |
| 134 | static PyObject *ResObj_DetachResource(_self, _args) |
| 135 | ResourceObject *_self; |
| 136 | PyObject *_args; |
| 137 | { |
| 138 | PyObject *_res = NULL; |
| 139 | if (!PyArg_ParseTuple(_args, "")) |
| 140 | return NULL; |
| 141 | DetachResource(_self->ob_itself); |
| 142 | { |
| 143 | OSErr _err = ResError(); |
| 144 | if (_err != noErr) return PyMac_Error(_err); |
| 145 | } |
| 146 | Py_INCREF(Py_None); |
| 147 | _res = Py_None; |
| 148 | return _res; |
| 149 | } |
| 150 | |
| 151 | static PyObject *ResObj_GetResAttrs(_self, _args) |
| 152 | ResourceObject *_self; |
| 153 | PyObject *_args; |
| 154 | { |
| 155 | PyObject *_res = NULL; |
| 156 | short _rv; |
| 157 | if (!PyArg_ParseTuple(_args, "")) |
| 158 | return NULL; |
| 159 | _rv = GetResAttrs(_self->ob_itself); |
| 160 | { |
| 161 | OSErr _err = ResError(); |
| 162 | if (_err != noErr) return PyMac_Error(_err); |
| 163 | } |
| 164 | _res = Py_BuildValue("h", |
| 165 | _rv); |
| 166 | return _res; |
| 167 | } |
| 168 | |
| 169 | static PyObject *ResObj_GetResInfo(_self, _args) |
| 170 | ResourceObject *_self; |
| 171 | PyObject *_args; |
| 172 | { |
| 173 | PyObject *_res = NULL; |
| 174 | short theID; |
| 175 | ResType theType; |
| 176 | Str255 name; |
| 177 | if (!PyArg_ParseTuple(_args, "")) |
| 178 | return NULL; |
| 179 | GetResInfo(_self->ob_itself, |
| 180 | &theID, |
| 181 | &theType, |
| 182 | name); |
| 183 | { |
| 184 | OSErr _err = ResError(); |
| 185 | if (_err != noErr) return PyMac_Error(_err); |
| 186 | } |
| 187 | _res = Py_BuildValue("hO&O&", |
| 188 | theID, |
| 189 | PyMac_BuildOSType, theType, |
| 190 | PyMac_BuildStr255, name); |
| 191 | return _res; |
| 192 | } |
| 193 | |
| 194 | static PyObject *ResObj_SetResInfo(_self, _args) |
| 195 | ResourceObject *_self; |
| 196 | PyObject *_args; |
| 197 | { |
| 198 | PyObject *_res = NULL; |
| 199 | short theID; |
| 200 | Str255 name; |
| 201 | if (!PyArg_ParseTuple(_args, "hO&", |
| 202 | &theID, |
| 203 | PyMac_GetStr255, name)) |
| 204 | return NULL; |
| 205 | SetResInfo(_self->ob_itself, |
| 206 | theID, |
| 207 | name); |
| 208 | { |
| 209 | OSErr _err = ResError(); |
| 210 | if (_err != noErr) return PyMac_Error(_err); |
| 211 | } |
| 212 | Py_INCREF(Py_None); |
| 213 | _res = Py_None; |
| 214 | return _res; |
| 215 | } |
| 216 | |
| 217 | static PyObject *ResObj_AddResource(_self, _args) |
| 218 | ResourceObject *_self; |
| 219 | PyObject *_args; |
| 220 | { |
| 221 | PyObject *_res = NULL; |
| 222 | ResType theType; |
| 223 | short theID; |
| 224 | Str255 name; |
| 225 | if (!PyArg_ParseTuple(_args, "O&hO&", |
| 226 | PyMac_GetOSType, &theType, |
| 227 | &theID, |
| 228 | PyMac_GetStr255, name)) |
| 229 | return NULL; |
| 230 | AddResource(_self->ob_itself, |
| 231 | theType, |
| 232 | theID, |
| 233 | name); |
| 234 | { |
| 235 | OSErr _err = ResError(); |
| 236 | if (_err != noErr) return PyMac_Error(_err); |
| 237 | } |
| 238 | Py_INCREF(Py_None); |
| 239 | _res = Py_None; |
| 240 | return _res; |
| 241 | } |
| 242 | |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 243 | static PyObject *ResObj_GetResourceSizeOnDisk(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 244 | ResourceObject *_self; |
| 245 | PyObject *_args; |
| 246 | { |
| 247 | PyObject *_res = NULL; |
| 248 | long _rv; |
| 249 | if (!PyArg_ParseTuple(_args, "")) |
| 250 | return NULL; |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 251 | _rv = GetResourceSizeOnDisk(_self->ob_itself); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 252 | { |
| 253 | OSErr _err = ResError(); |
| 254 | if (_err != noErr) return PyMac_Error(_err); |
| 255 | } |
| 256 | _res = Py_BuildValue("l", |
| 257 | _rv); |
| 258 | return _res; |
| 259 | } |
| 260 | |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 261 | static PyObject *ResObj_GetMaxResourceSize(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 262 | ResourceObject *_self; |
| 263 | PyObject *_args; |
| 264 | { |
| 265 | PyObject *_res = NULL; |
| 266 | long _rv; |
| 267 | if (!PyArg_ParseTuple(_args, "")) |
| 268 | return NULL; |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 269 | _rv = GetMaxResourceSize(_self->ob_itself); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 270 | { |
| 271 | OSErr _err = ResError(); |
| 272 | if (_err != noErr) return PyMac_Error(_err); |
| 273 | } |
| 274 | _res = Py_BuildValue("l", |
| 275 | _rv); |
| 276 | return _res; |
| 277 | } |
| 278 | |
| 279 | static PyObject *ResObj_RsrcMapEntry(_self, _args) |
| 280 | ResourceObject *_self; |
| 281 | PyObject *_args; |
| 282 | { |
| 283 | PyObject *_res = NULL; |
| 284 | long _rv; |
| 285 | if (!PyArg_ParseTuple(_args, "")) |
| 286 | return NULL; |
| 287 | _rv = RsrcMapEntry(_self->ob_itself); |
| 288 | { |
| 289 | OSErr _err = ResError(); |
| 290 | if (_err != noErr) return PyMac_Error(_err); |
| 291 | } |
| 292 | _res = Py_BuildValue("l", |
| 293 | _rv); |
| 294 | return _res; |
| 295 | } |
| 296 | |
| 297 | static PyObject *ResObj_SetResAttrs(_self, _args) |
| 298 | ResourceObject *_self; |
| 299 | PyObject *_args; |
| 300 | { |
| 301 | PyObject *_res = NULL; |
| 302 | short attrs; |
| 303 | if (!PyArg_ParseTuple(_args, "h", |
| 304 | &attrs)) |
| 305 | return NULL; |
| 306 | SetResAttrs(_self->ob_itself, |
| 307 | attrs); |
| 308 | { |
| 309 | OSErr _err = ResError(); |
| 310 | if (_err != noErr) return PyMac_Error(_err); |
| 311 | } |
| 312 | Py_INCREF(Py_None); |
| 313 | _res = Py_None; |
| 314 | return _res; |
| 315 | } |
| 316 | |
| 317 | static PyObject *ResObj_ChangedResource(_self, _args) |
| 318 | ResourceObject *_self; |
| 319 | PyObject *_args; |
| 320 | { |
| 321 | PyObject *_res = NULL; |
| 322 | if (!PyArg_ParseTuple(_args, "")) |
| 323 | return NULL; |
| 324 | ChangedResource(_self->ob_itself); |
| 325 | { |
| 326 | OSErr _err = ResError(); |
| 327 | if (_err != noErr) return PyMac_Error(_err); |
| 328 | } |
| 329 | Py_INCREF(Py_None); |
| 330 | _res = Py_None; |
| 331 | return _res; |
| 332 | } |
| 333 | |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 334 | static PyObject *ResObj_RemoveResource(_self, _args) |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 335 | ResourceObject *_self; |
| 336 | PyObject *_args; |
| 337 | { |
| 338 | PyObject *_res = NULL; |
| 339 | if (!PyArg_ParseTuple(_args, "")) |
| 340 | return NULL; |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 341 | RemoveResource(_self->ob_itself); |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 342 | { |
| 343 | OSErr _err = ResError(); |
| 344 | if (_err != noErr) return PyMac_Error(_err); |
| 345 | } |
| 346 | Py_INCREF(Py_None); |
| 347 | _res = Py_None; |
| 348 | return _res; |
| 349 | } |
| 350 | |
| 351 | static PyObject *ResObj_WriteResource(_self, _args) |
| 352 | ResourceObject *_self; |
| 353 | PyObject *_args; |
| 354 | { |
| 355 | PyObject *_res = NULL; |
| 356 | if (!PyArg_ParseTuple(_args, "")) |
| 357 | return NULL; |
| 358 | WriteResource(_self->ob_itself); |
| 359 | { |
| 360 | OSErr _err = ResError(); |
| 361 | if (_err != noErr) return PyMac_Error(_err); |
| 362 | } |
| 363 | Py_INCREF(Py_None); |
| 364 | _res = Py_None; |
| 365 | return _res; |
| 366 | } |
| 367 | |
| 368 | static PyObject *ResObj_SetResourceSize(_self, _args) |
| 369 | ResourceObject *_self; |
| 370 | PyObject *_args; |
| 371 | { |
| 372 | PyObject *_res = NULL; |
| 373 | long newSize; |
| 374 | if (!PyArg_ParseTuple(_args, "l", |
| 375 | &newSize)) |
| 376 | return NULL; |
| 377 | SetResourceSize(_self->ob_itself, |
| 378 | newSize); |
| 379 | { |
| 380 | OSErr _err = ResError(); |
| 381 | if (_err != noErr) return PyMac_Error(_err); |
| 382 | } |
| 383 | Py_INCREF(Py_None); |
| 384 | _res = Py_None; |
| 385 | return _res; |
| 386 | } |
| 387 | |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 388 | static PyObject *ResObj_GetNextFOND(_self, _args) |
| 389 | ResourceObject *_self; |
| 390 | PyObject *_args; |
| 391 | { |
| 392 | PyObject *_res = NULL; |
| 393 | Handle _rv; |
| 394 | if (!PyArg_ParseTuple(_args, "")) |
| 395 | return NULL; |
| 396 | _rv = GetNextFOND(_self->ob_itself); |
| 397 | { |
| 398 | OSErr _err = ResError(); |
| 399 | if (_err != noErr) return PyMac_Error(_err); |
| 400 | } |
| 401 | _res = Py_BuildValue("O&", |
| 402 | ResObj_New, _rv); |
| 403 | return _res; |
| 404 | } |
| 405 | |
Jack Jansen | 1e05402 | 1995-06-18 20:20:27 +0000 | [diff] [blame] | 406 | static PyObject *ResObj_as_Control(_self, _args) |
| 407 | ResourceObject *_self; |
| 408 | PyObject *_args; |
| 409 | { |
| 410 | PyObject *_res = NULL; |
| 411 | |
| 412 | return CtlObj_New((ControlHandle)_self->ob_itself); |
| 413 | |
| 414 | } |
| 415 | |
| 416 | static PyObject *ResObj_as_Menu(_self, _args) |
| 417 | ResourceObject *_self; |
| 418 | PyObject *_args; |
| 419 | { |
| 420 | PyObject *_res = NULL; |
| 421 | |
| 422 | return MenuObj_New((MenuHandle)_self->ob_itself); |
| 423 | |
| 424 | } |
| 425 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 426 | static PyMethodDef ResObj_methods[] = { |
| 427 | {"HomeResFile", (PyCFunction)ResObj_HomeResFile, 1, |
| 428 | "() -> (short _rv)"}, |
| 429 | {"LoadResource", (PyCFunction)ResObj_LoadResource, 1, |
| 430 | "() -> None"}, |
| 431 | {"ReleaseResource", (PyCFunction)ResObj_ReleaseResource, 1, |
| 432 | "() -> None"}, |
| 433 | {"DetachResource", (PyCFunction)ResObj_DetachResource, 1, |
| 434 | "() -> None"}, |
| 435 | {"GetResAttrs", (PyCFunction)ResObj_GetResAttrs, 1, |
| 436 | "() -> (short _rv)"}, |
| 437 | {"GetResInfo", (PyCFunction)ResObj_GetResInfo, 1, |
| 438 | "() -> (short theID, ResType theType, Str255 name)"}, |
| 439 | {"SetResInfo", (PyCFunction)ResObj_SetResInfo, 1, |
| 440 | "(short theID, Str255 name) -> None"}, |
| 441 | {"AddResource", (PyCFunction)ResObj_AddResource, 1, |
| 442 | "(ResType theType, short theID, Str255 name) -> None"}, |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 443 | {"GetResourceSizeOnDisk", (PyCFunction)ResObj_GetResourceSizeOnDisk, 1, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 444 | "() -> (long _rv)"}, |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 445 | {"GetMaxResourceSize", (PyCFunction)ResObj_GetMaxResourceSize, 1, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 446 | "() -> (long _rv)"}, |
| 447 | {"RsrcMapEntry", (PyCFunction)ResObj_RsrcMapEntry, 1, |
| 448 | "() -> (long _rv)"}, |
| 449 | {"SetResAttrs", (PyCFunction)ResObj_SetResAttrs, 1, |
| 450 | "(short attrs) -> None"}, |
| 451 | {"ChangedResource", (PyCFunction)ResObj_ChangedResource, 1, |
| 452 | "() -> None"}, |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 453 | {"RemoveResource", (PyCFunction)ResObj_RemoveResource, 1, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 454 | "() -> None"}, |
| 455 | {"WriteResource", (PyCFunction)ResObj_WriteResource, 1, |
| 456 | "() -> None"}, |
| 457 | {"SetResourceSize", (PyCFunction)ResObj_SetResourceSize, 1, |
| 458 | "(long newSize) -> None"}, |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 459 | {"GetNextFOND", (PyCFunction)ResObj_GetNextFOND, 1, |
| 460 | "() -> (Handle _rv)"}, |
Jack Jansen | 1e05402 | 1995-06-18 20:20:27 +0000 | [diff] [blame] | 461 | {"as_Control", (PyCFunction)ResObj_as_Control, 1, |
| 462 | "Return this resource/handle as a Control"}, |
| 463 | {"as_Menu", (PyCFunction)ResObj_as_Menu, 1, |
| 464 | "Return this resource/handle as a Menu"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 465 | {NULL, NULL, 0} |
| 466 | }; |
| 467 | |
| 468 | PyMethodChain ResObj_chain = { ResObj_methods, NULL }; |
| 469 | |
| 470 | static PyObject *ResObj_getattr(self, name) |
| 471 | ResourceObject *self; |
| 472 | char *name; |
| 473 | { |
| 474 | |
| 475 | if (strcmp(name, "size") == 0) |
| 476 | return PyInt_FromLong(GetHandleSize(self->ob_itself)); |
| 477 | if (strcmp(name, "data") == 0) { |
| 478 | PyObject *res; |
| 479 | char state; |
| 480 | state = HGetState(self->ob_itself); |
| 481 | HLock(self->ob_itself); |
| 482 | res = PyString_FromStringAndSize( |
| 483 | *self->ob_itself, |
| 484 | GetHandleSize(self->ob_itself)); |
| 485 | HUnlock(self->ob_itself); |
| 486 | HSetState(self->ob_itself, state); |
| 487 | return res; |
| 488 | } |
| 489 | if (strcmp(name, "__members__") == 0) |
| 490 | return Py_BuildValue("[ss]", "data", "size"); |
| 491 | |
| 492 | return Py_FindMethodInChain(&ResObj_chain, (PyObject *)self, name); |
| 493 | } |
| 494 | |
Jack Jansen | 1e05402 | 1995-06-18 20:20:27 +0000 | [diff] [blame] | 495 | static int |
| 496 | ResObj_setattr(self, name, value) |
| 497 | ResourceObject *self; |
| 498 | char *name; |
| 499 | PyObject *value; |
| 500 | { |
| 501 | char *data; |
| 502 | long size; |
| 503 | |
| 504 | if (strcmp(name, "data") != 0 || value == NULL ) |
| 505 | return -1; |
| 506 | if ( !PyString_Check(value) ) |
| 507 | return -1; |
| 508 | size = PyString_Size(value); |
| 509 | data = PyString_AsString(value); |
| 510 | /* XXXX Do I need the GetState/SetState calls? */ |
| 511 | SetHandleSize(self->ob_itself, size); |
| 512 | if ( MemError()) |
| 513 | return -1; |
| 514 | HLock(self->ob_itself); |
| 515 | memcpy((char *)*self->ob_itself, data, size); |
| 516 | HUnlock(self->ob_itself); |
| 517 | /* XXXX Should I do the Changed call immedeately? */ |
| 518 | return 0; |
| 519 | } |
| 520 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 521 | |
| 522 | PyTypeObject Resource_Type = { |
| 523 | PyObject_HEAD_INIT(&PyType_Type) |
| 524 | 0, /*ob_size*/ |
| 525 | "Resource", /*tp_name*/ |
| 526 | sizeof(ResourceObject), /*tp_basicsize*/ |
| 527 | 0, /*tp_itemsize*/ |
| 528 | /* methods */ |
| 529 | (destructor) ResObj_dealloc, /*tp_dealloc*/ |
| 530 | 0, /*tp_print*/ |
| 531 | (getattrfunc) ResObj_getattr, /*tp_getattr*/ |
| 532 | (setattrfunc) ResObj_setattr, /*tp_setattr*/ |
| 533 | }; |
| 534 | |
| 535 | /* -------------------- End object type Resource -------------------- */ |
| 536 | |
| 537 | |
| 538 | static PyObject *Res_InitResources(_self, _args) |
| 539 | PyObject *_self; |
| 540 | PyObject *_args; |
| 541 | { |
| 542 | PyObject *_res = NULL; |
| 543 | short _rv; |
| 544 | if (!PyArg_ParseTuple(_args, "")) |
| 545 | return NULL; |
| 546 | _rv = InitResources(); |
| 547 | { |
| 548 | OSErr _err = ResError(); |
| 549 | if (_err != noErr) return PyMac_Error(_err); |
| 550 | } |
| 551 | _res = Py_BuildValue("h", |
| 552 | _rv); |
| 553 | return _res; |
| 554 | } |
| 555 | |
| 556 | static PyObject *Res_RsrcZoneInit(_self, _args) |
| 557 | PyObject *_self; |
| 558 | PyObject *_args; |
| 559 | { |
| 560 | PyObject *_res = NULL; |
| 561 | if (!PyArg_ParseTuple(_args, "")) |
| 562 | return NULL; |
| 563 | RsrcZoneInit(); |
| 564 | { |
| 565 | OSErr _err = ResError(); |
| 566 | if (_err != noErr) return PyMac_Error(_err); |
| 567 | } |
| 568 | Py_INCREF(Py_None); |
| 569 | _res = Py_None; |
| 570 | return _res; |
| 571 | } |
| 572 | |
| 573 | static PyObject *Res_CloseResFile(_self, _args) |
| 574 | PyObject *_self; |
| 575 | PyObject *_args; |
| 576 | { |
| 577 | PyObject *_res = NULL; |
| 578 | short refNum; |
| 579 | if (!PyArg_ParseTuple(_args, "h", |
| 580 | &refNum)) |
| 581 | return NULL; |
| 582 | CloseResFile(refNum); |
| 583 | { |
| 584 | OSErr _err = ResError(); |
| 585 | if (_err != noErr) return PyMac_Error(_err); |
| 586 | } |
| 587 | Py_INCREF(Py_None); |
| 588 | _res = Py_None; |
| 589 | return _res; |
| 590 | } |
| 591 | |
| 592 | static PyObject *Res_ResError(_self, _args) |
| 593 | PyObject *_self; |
| 594 | PyObject *_args; |
| 595 | { |
| 596 | PyObject *_res = NULL; |
| 597 | short _rv; |
| 598 | if (!PyArg_ParseTuple(_args, "")) |
| 599 | return NULL; |
| 600 | _rv = ResError(); |
| 601 | { |
| 602 | OSErr _err = ResError(); |
| 603 | if (_err != noErr) return PyMac_Error(_err); |
| 604 | } |
| 605 | _res = Py_BuildValue("h", |
| 606 | _rv); |
| 607 | return _res; |
| 608 | } |
| 609 | |
| 610 | static PyObject *Res_CurResFile(_self, _args) |
| 611 | PyObject *_self; |
| 612 | PyObject *_args; |
| 613 | { |
| 614 | PyObject *_res = NULL; |
| 615 | short _rv; |
| 616 | if (!PyArg_ParseTuple(_args, "")) |
| 617 | return NULL; |
| 618 | _rv = CurResFile(); |
| 619 | { |
| 620 | OSErr _err = ResError(); |
| 621 | if (_err != noErr) return PyMac_Error(_err); |
| 622 | } |
| 623 | _res = Py_BuildValue("h", |
| 624 | _rv); |
| 625 | return _res; |
| 626 | } |
| 627 | |
| 628 | static PyObject *Res_CreateResFile(_self, _args) |
| 629 | PyObject *_self; |
| 630 | PyObject *_args; |
| 631 | { |
| 632 | PyObject *_res = NULL; |
| 633 | Str255 fileName; |
| 634 | if (!PyArg_ParseTuple(_args, "O&", |
| 635 | PyMac_GetStr255, fileName)) |
| 636 | return NULL; |
| 637 | CreateResFile(fileName); |
| 638 | { |
| 639 | OSErr _err = ResError(); |
| 640 | if (_err != noErr) return PyMac_Error(_err); |
| 641 | } |
| 642 | Py_INCREF(Py_None); |
| 643 | _res = Py_None; |
| 644 | return _res; |
| 645 | } |
| 646 | |
| 647 | static PyObject *Res_OpenResFile(_self, _args) |
| 648 | PyObject *_self; |
| 649 | PyObject *_args; |
| 650 | { |
| 651 | PyObject *_res = NULL; |
| 652 | short _rv; |
| 653 | Str255 fileName; |
| 654 | if (!PyArg_ParseTuple(_args, "O&", |
| 655 | PyMac_GetStr255, fileName)) |
| 656 | return NULL; |
| 657 | _rv = OpenResFile(fileName); |
| 658 | { |
| 659 | OSErr _err = ResError(); |
| 660 | if (_err != noErr) return PyMac_Error(_err); |
| 661 | } |
| 662 | _res = Py_BuildValue("h", |
| 663 | _rv); |
| 664 | return _res; |
| 665 | } |
| 666 | |
| 667 | static PyObject *Res_UseResFile(_self, _args) |
| 668 | PyObject *_self; |
| 669 | PyObject *_args; |
| 670 | { |
| 671 | PyObject *_res = NULL; |
| 672 | short refNum; |
| 673 | if (!PyArg_ParseTuple(_args, "h", |
| 674 | &refNum)) |
| 675 | return NULL; |
| 676 | UseResFile(refNum); |
| 677 | { |
| 678 | OSErr _err = ResError(); |
| 679 | if (_err != noErr) return PyMac_Error(_err); |
| 680 | } |
| 681 | Py_INCREF(Py_None); |
| 682 | _res = Py_None; |
| 683 | return _res; |
| 684 | } |
| 685 | |
| 686 | static PyObject *Res_CountTypes(_self, _args) |
| 687 | PyObject *_self; |
| 688 | PyObject *_args; |
| 689 | { |
| 690 | PyObject *_res = NULL; |
| 691 | short _rv; |
| 692 | if (!PyArg_ParseTuple(_args, "")) |
| 693 | return NULL; |
| 694 | _rv = CountTypes(); |
| 695 | { |
| 696 | OSErr _err = ResError(); |
| 697 | if (_err != noErr) return PyMac_Error(_err); |
| 698 | } |
| 699 | _res = Py_BuildValue("h", |
| 700 | _rv); |
| 701 | return _res; |
| 702 | } |
| 703 | |
| 704 | static PyObject *Res_Count1Types(_self, _args) |
| 705 | PyObject *_self; |
| 706 | PyObject *_args; |
| 707 | { |
| 708 | PyObject *_res = NULL; |
| 709 | short _rv; |
| 710 | if (!PyArg_ParseTuple(_args, "")) |
| 711 | return NULL; |
| 712 | _rv = Count1Types(); |
| 713 | { |
| 714 | OSErr _err = ResError(); |
| 715 | if (_err != noErr) return PyMac_Error(_err); |
| 716 | } |
| 717 | _res = Py_BuildValue("h", |
| 718 | _rv); |
| 719 | return _res; |
| 720 | } |
| 721 | |
| 722 | static PyObject *Res_GetIndType(_self, _args) |
| 723 | PyObject *_self; |
| 724 | PyObject *_args; |
| 725 | { |
| 726 | PyObject *_res = NULL; |
| 727 | ResType theType; |
| 728 | short index; |
| 729 | if (!PyArg_ParseTuple(_args, "h", |
| 730 | &index)) |
| 731 | return NULL; |
| 732 | GetIndType(&theType, |
| 733 | index); |
| 734 | { |
| 735 | OSErr _err = ResError(); |
| 736 | if (_err != noErr) return PyMac_Error(_err); |
| 737 | } |
| 738 | _res = Py_BuildValue("O&", |
| 739 | PyMac_BuildOSType, theType); |
| 740 | return _res; |
| 741 | } |
| 742 | |
| 743 | static PyObject *Res_Get1IndType(_self, _args) |
| 744 | PyObject *_self; |
| 745 | PyObject *_args; |
| 746 | { |
| 747 | PyObject *_res = NULL; |
| 748 | ResType theType; |
| 749 | short index; |
| 750 | if (!PyArg_ParseTuple(_args, "h", |
| 751 | &index)) |
| 752 | return NULL; |
| 753 | Get1IndType(&theType, |
| 754 | index); |
| 755 | { |
| 756 | OSErr _err = ResError(); |
| 757 | if (_err != noErr) return PyMac_Error(_err); |
| 758 | } |
| 759 | _res = Py_BuildValue("O&", |
| 760 | PyMac_BuildOSType, theType); |
| 761 | return _res; |
| 762 | } |
| 763 | |
| 764 | static PyObject *Res_SetResLoad(_self, _args) |
| 765 | PyObject *_self; |
| 766 | PyObject *_args; |
| 767 | { |
| 768 | PyObject *_res = NULL; |
| 769 | Boolean load; |
| 770 | if (!PyArg_ParseTuple(_args, "b", |
| 771 | &load)) |
| 772 | return NULL; |
| 773 | SetResLoad(load); |
| 774 | { |
| 775 | OSErr _err = ResError(); |
| 776 | if (_err != noErr) return PyMac_Error(_err); |
| 777 | } |
| 778 | Py_INCREF(Py_None); |
| 779 | _res = Py_None; |
| 780 | return _res; |
| 781 | } |
| 782 | |
| 783 | static PyObject *Res_CountResources(_self, _args) |
| 784 | PyObject *_self; |
| 785 | PyObject *_args; |
| 786 | { |
| 787 | PyObject *_res = NULL; |
| 788 | short _rv; |
| 789 | ResType theType; |
| 790 | if (!PyArg_ParseTuple(_args, "O&", |
| 791 | PyMac_GetOSType, &theType)) |
| 792 | return NULL; |
| 793 | _rv = CountResources(theType); |
| 794 | { |
| 795 | OSErr _err = ResError(); |
| 796 | if (_err != noErr) return PyMac_Error(_err); |
| 797 | } |
| 798 | _res = Py_BuildValue("h", |
| 799 | _rv); |
| 800 | return _res; |
| 801 | } |
| 802 | |
| 803 | static PyObject *Res_Count1Resources(_self, _args) |
| 804 | PyObject *_self; |
| 805 | PyObject *_args; |
| 806 | { |
| 807 | PyObject *_res = NULL; |
| 808 | short _rv; |
| 809 | ResType theType; |
| 810 | if (!PyArg_ParseTuple(_args, "O&", |
| 811 | PyMac_GetOSType, &theType)) |
| 812 | return NULL; |
| 813 | _rv = Count1Resources(theType); |
| 814 | { |
| 815 | OSErr _err = ResError(); |
| 816 | if (_err != noErr) return PyMac_Error(_err); |
| 817 | } |
| 818 | _res = Py_BuildValue("h", |
| 819 | _rv); |
| 820 | return _res; |
| 821 | } |
| 822 | |
| 823 | static PyObject *Res_GetIndResource(_self, _args) |
| 824 | PyObject *_self; |
| 825 | PyObject *_args; |
| 826 | { |
| 827 | PyObject *_res = NULL; |
| 828 | Handle _rv; |
| 829 | ResType theType; |
| 830 | short index; |
| 831 | if (!PyArg_ParseTuple(_args, "O&h", |
| 832 | PyMac_GetOSType, &theType, |
| 833 | &index)) |
| 834 | return NULL; |
| 835 | _rv = GetIndResource(theType, |
| 836 | index); |
| 837 | { |
| 838 | OSErr _err = ResError(); |
| 839 | if (_err != noErr) return PyMac_Error(_err); |
| 840 | } |
| 841 | _res = Py_BuildValue("O&", |
| 842 | ResObj_New, _rv); |
| 843 | return _res; |
| 844 | } |
| 845 | |
| 846 | static PyObject *Res_Get1IndResource(_self, _args) |
| 847 | PyObject *_self; |
| 848 | PyObject *_args; |
| 849 | { |
| 850 | PyObject *_res = NULL; |
| 851 | Handle _rv; |
| 852 | ResType theType; |
| 853 | short index; |
| 854 | if (!PyArg_ParseTuple(_args, "O&h", |
| 855 | PyMac_GetOSType, &theType, |
| 856 | &index)) |
| 857 | return NULL; |
| 858 | _rv = Get1IndResource(theType, |
| 859 | index); |
| 860 | { |
| 861 | OSErr _err = ResError(); |
| 862 | if (_err != noErr) return PyMac_Error(_err); |
| 863 | } |
| 864 | _res = Py_BuildValue("O&", |
| 865 | ResObj_New, _rv); |
| 866 | return _res; |
| 867 | } |
| 868 | |
| 869 | static PyObject *Res_GetResource(_self, _args) |
| 870 | PyObject *_self; |
| 871 | PyObject *_args; |
| 872 | { |
| 873 | PyObject *_res = NULL; |
| 874 | Handle _rv; |
| 875 | ResType theType; |
| 876 | short theID; |
| 877 | if (!PyArg_ParseTuple(_args, "O&h", |
| 878 | PyMac_GetOSType, &theType, |
| 879 | &theID)) |
| 880 | return NULL; |
| 881 | _rv = GetResource(theType, |
| 882 | theID); |
| 883 | { |
| 884 | OSErr _err = ResError(); |
| 885 | if (_err != noErr) return PyMac_Error(_err); |
| 886 | } |
| 887 | _res = Py_BuildValue("O&", |
| 888 | ResObj_New, _rv); |
| 889 | return _res; |
| 890 | } |
| 891 | |
| 892 | static PyObject *Res_Get1Resource(_self, _args) |
| 893 | PyObject *_self; |
| 894 | PyObject *_args; |
| 895 | { |
| 896 | PyObject *_res = NULL; |
| 897 | Handle _rv; |
| 898 | ResType theType; |
| 899 | short theID; |
| 900 | if (!PyArg_ParseTuple(_args, "O&h", |
| 901 | PyMac_GetOSType, &theType, |
| 902 | &theID)) |
| 903 | return NULL; |
| 904 | _rv = Get1Resource(theType, |
| 905 | theID); |
| 906 | { |
| 907 | OSErr _err = ResError(); |
| 908 | if (_err != noErr) return PyMac_Error(_err); |
| 909 | } |
| 910 | _res = Py_BuildValue("O&", |
| 911 | ResObj_New, _rv); |
| 912 | return _res; |
| 913 | } |
| 914 | |
| 915 | static PyObject *Res_GetNamedResource(_self, _args) |
| 916 | PyObject *_self; |
| 917 | PyObject *_args; |
| 918 | { |
| 919 | PyObject *_res = NULL; |
| 920 | Handle _rv; |
| 921 | ResType theType; |
| 922 | Str255 name; |
| 923 | if (!PyArg_ParseTuple(_args, "O&O&", |
| 924 | PyMac_GetOSType, &theType, |
| 925 | PyMac_GetStr255, name)) |
| 926 | return NULL; |
| 927 | _rv = GetNamedResource(theType, |
| 928 | name); |
| 929 | { |
| 930 | OSErr _err = ResError(); |
| 931 | if (_err != noErr) return PyMac_Error(_err); |
| 932 | } |
| 933 | _res = Py_BuildValue("O&", |
| 934 | ResObj_New, _rv); |
| 935 | return _res; |
| 936 | } |
| 937 | |
| 938 | static PyObject *Res_Get1NamedResource(_self, _args) |
| 939 | PyObject *_self; |
| 940 | PyObject *_args; |
| 941 | { |
| 942 | PyObject *_res = NULL; |
| 943 | Handle _rv; |
| 944 | ResType theType; |
| 945 | Str255 name; |
| 946 | if (!PyArg_ParseTuple(_args, "O&O&", |
| 947 | PyMac_GetOSType, &theType, |
| 948 | PyMac_GetStr255, name)) |
| 949 | return NULL; |
| 950 | _rv = Get1NamedResource(theType, |
| 951 | name); |
| 952 | { |
| 953 | OSErr _err = ResError(); |
| 954 | if (_err != noErr) return PyMac_Error(_err); |
| 955 | } |
| 956 | _res = Py_BuildValue("O&", |
| 957 | ResObj_New, _rv); |
| 958 | return _res; |
| 959 | } |
| 960 | |
| 961 | static PyObject *Res_UniqueID(_self, _args) |
| 962 | PyObject *_self; |
| 963 | PyObject *_args; |
| 964 | { |
| 965 | PyObject *_res = NULL; |
| 966 | short _rv; |
| 967 | ResType theType; |
| 968 | if (!PyArg_ParseTuple(_args, "O&", |
| 969 | PyMac_GetOSType, &theType)) |
| 970 | return NULL; |
| 971 | _rv = UniqueID(theType); |
| 972 | { |
| 973 | OSErr _err = ResError(); |
| 974 | if (_err != noErr) return PyMac_Error(_err); |
| 975 | } |
| 976 | _res = Py_BuildValue("h", |
| 977 | _rv); |
| 978 | return _res; |
| 979 | } |
| 980 | |
| 981 | static PyObject *Res_Unique1ID(_self, _args) |
| 982 | PyObject *_self; |
| 983 | PyObject *_args; |
| 984 | { |
| 985 | PyObject *_res = NULL; |
| 986 | short _rv; |
| 987 | ResType theType; |
| 988 | if (!PyArg_ParseTuple(_args, "O&", |
| 989 | PyMac_GetOSType, &theType)) |
| 990 | return NULL; |
| 991 | _rv = Unique1ID(theType); |
| 992 | { |
| 993 | OSErr _err = ResError(); |
| 994 | if (_err != noErr) return PyMac_Error(_err); |
| 995 | } |
| 996 | _res = Py_BuildValue("h", |
| 997 | _rv); |
| 998 | return _res; |
| 999 | } |
| 1000 | |
| 1001 | static PyObject *Res_UpdateResFile(_self, _args) |
| 1002 | PyObject *_self; |
| 1003 | PyObject *_args; |
| 1004 | { |
| 1005 | PyObject *_res = NULL; |
| 1006 | short refNum; |
| 1007 | if (!PyArg_ParseTuple(_args, "h", |
| 1008 | &refNum)) |
| 1009 | return NULL; |
| 1010 | UpdateResFile(refNum); |
| 1011 | { |
| 1012 | OSErr _err = ResError(); |
| 1013 | if (_err != noErr) return PyMac_Error(_err); |
| 1014 | } |
| 1015 | Py_INCREF(Py_None); |
| 1016 | _res = Py_None; |
| 1017 | return _res; |
| 1018 | } |
| 1019 | |
| 1020 | static PyObject *Res_SetResPurge(_self, _args) |
| 1021 | PyObject *_self; |
| 1022 | PyObject *_args; |
| 1023 | { |
| 1024 | PyObject *_res = NULL; |
| 1025 | Boolean install; |
| 1026 | if (!PyArg_ParseTuple(_args, "b", |
| 1027 | &install)) |
| 1028 | return NULL; |
| 1029 | SetResPurge(install); |
| 1030 | { |
| 1031 | OSErr _err = ResError(); |
| 1032 | if (_err != noErr) return PyMac_Error(_err); |
| 1033 | } |
| 1034 | Py_INCREF(Py_None); |
| 1035 | _res = Py_None; |
| 1036 | return _res; |
| 1037 | } |
| 1038 | |
| 1039 | static PyObject *Res_GetResFileAttrs(_self, _args) |
| 1040 | PyObject *_self; |
| 1041 | PyObject *_args; |
| 1042 | { |
| 1043 | PyObject *_res = NULL; |
| 1044 | short _rv; |
| 1045 | short refNum; |
| 1046 | if (!PyArg_ParseTuple(_args, "h", |
| 1047 | &refNum)) |
| 1048 | return NULL; |
| 1049 | _rv = GetResFileAttrs(refNum); |
| 1050 | { |
| 1051 | OSErr _err = ResError(); |
| 1052 | if (_err != noErr) return PyMac_Error(_err); |
| 1053 | } |
| 1054 | _res = Py_BuildValue("h", |
| 1055 | _rv); |
| 1056 | return _res; |
| 1057 | } |
| 1058 | |
| 1059 | static PyObject *Res_SetResFileAttrs(_self, _args) |
| 1060 | PyObject *_self; |
| 1061 | PyObject *_args; |
| 1062 | { |
| 1063 | PyObject *_res = NULL; |
| 1064 | short refNum; |
| 1065 | short attrs; |
| 1066 | if (!PyArg_ParseTuple(_args, "hh", |
| 1067 | &refNum, |
| 1068 | &attrs)) |
| 1069 | return NULL; |
| 1070 | SetResFileAttrs(refNum, |
| 1071 | attrs); |
| 1072 | { |
| 1073 | OSErr _err = ResError(); |
| 1074 | if (_err != noErr) return PyMac_Error(_err); |
| 1075 | } |
| 1076 | Py_INCREF(Py_None); |
| 1077 | _res = Py_None; |
| 1078 | return _res; |
| 1079 | } |
| 1080 | |
| 1081 | static PyObject *Res_OpenRFPerm(_self, _args) |
| 1082 | PyObject *_self; |
| 1083 | PyObject *_args; |
| 1084 | { |
| 1085 | PyObject *_res = NULL; |
| 1086 | short _rv; |
| 1087 | Str255 fileName; |
| 1088 | short vRefNum; |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 1089 | SignedByte permission; |
| 1090 | if (!PyArg_ParseTuple(_args, "O&hb", |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1091 | PyMac_GetStr255, fileName, |
| 1092 | &vRefNum, |
| 1093 | &permission)) |
| 1094 | return NULL; |
| 1095 | _rv = OpenRFPerm(fileName, |
| 1096 | vRefNum, |
| 1097 | permission); |
| 1098 | { |
| 1099 | OSErr _err = ResError(); |
| 1100 | if (_err != noErr) return PyMac_Error(_err); |
| 1101 | } |
| 1102 | _res = Py_BuildValue("h", |
| 1103 | _rv); |
| 1104 | return _res; |
| 1105 | } |
| 1106 | |
| 1107 | static PyObject *Res_RGetResource(_self, _args) |
| 1108 | PyObject *_self; |
| 1109 | PyObject *_args; |
| 1110 | { |
| 1111 | PyObject *_res = NULL; |
| 1112 | Handle _rv; |
| 1113 | ResType theType; |
| 1114 | short theID; |
| 1115 | if (!PyArg_ParseTuple(_args, "O&h", |
| 1116 | PyMac_GetOSType, &theType, |
| 1117 | &theID)) |
| 1118 | return NULL; |
| 1119 | _rv = RGetResource(theType, |
| 1120 | theID); |
| 1121 | { |
| 1122 | OSErr _err = ResError(); |
| 1123 | if (_err != noErr) return PyMac_Error(_err); |
| 1124 | } |
| 1125 | _res = Py_BuildValue("O&", |
| 1126 | ResObj_New, _rv); |
| 1127 | return _res; |
| 1128 | } |
| 1129 | |
| 1130 | static PyObject *Res_HOpenResFile(_self, _args) |
| 1131 | PyObject *_self; |
| 1132 | PyObject *_args; |
| 1133 | { |
| 1134 | PyObject *_res = NULL; |
| 1135 | short _rv; |
| 1136 | short vRefNum; |
| 1137 | long dirID; |
| 1138 | Str255 fileName; |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 1139 | SignedByte permission; |
| 1140 | if (!PyArg_ParseTuple(_args, "hlO&b", |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1141 | &vRefNum, |
| 1142 | &dirID, |
| 1143 | PyMac_GetStr255, fileName, |
| 1144 | &permission)) |
| 1145 | return NULL; |
| 1146 | _rv = HOpenResFile(vRefNum, |
| 1147 | dirID, |
| 1148 | fileName, |
| 1149 | permission); |
| 1150 | { |
| 1151 | OSErr _err = ResError(); |
| 1152 | if (_err != noErr) return PyMac_Error(_err); |
| 1153 | } |
| 1154 | _res = Py_BuildValue("h", |
| 1155 | _rv); |
| 1156 | return _res; |
| 1157 | } |
| 1158 | |
| 1159 | static PyObject *Res_HCreateResFile(_self, _args) |
| 1160 | PyObject *_self; |
| 1161 | PyObject *_args; |
| 1162 | { |
| 1163 | PyObject *_res = NULL; |
| 1164 | short vRefNum; |
| 1165 | long dirID; |
| 1166 | Str255 fileName; |
| 1167 | if (!PyArg_ParseTuple(_args, "hlO&", |
| 1168 | &vRefNum, |
| 1169 | &dirID, |
| 1170 | PyMac_GetStr255, fileName)) |
| 1171 | return NULL; |
| 1172 | HCreateResFile(vRefNum, |
| 1173 | dirID, |
| 1174 | fileName); |
| 1175 | { |
| 1176 | OSErr _err = ResError(); |
| 1177 | if (_err != noErr) return PyMac_Error(_err); |
| 1178 | } |
| 1179 | Py_INCREF(Py_None); |
| 1180 | _res = Py_None; |
| 1181 | return _res; |
| 1182 | } |
| 1183 | |
| 1184 | static PyObject *Res_FSpOpenResFile(_self, _args) |
| 1185 | PyObject *_self; |
| 1186 | PyObject *_args; |
| 1187 | { |
| 1188 | PyObject *_res = NULL; |
| 1189 | short _rv; |
| 1190 | FSSpec spec; |
| 1191 | SignedByte permission; |
| 1192 | if (!PyArg_ParseTuple(_args, "O&b", |
| 1193 | PyMac_GetFSSpec, &spec, |
| 1194 | &permission)) |
| 1195 | return NULL; |
| 1196 | _rv = FSpOpenResFile(&spec, |
| 1197 | permission); |
| 1198 | { |
| 1199 | OSErr _err = ResError(); |
| 1200 | if (_err != noErr) return PyMac_Error(_err); |
| 1201 | } |
| 1202 | _res = Py_BuildValue("h", |
| 1203 | _rv); |
| 1204 | return _res; |
| 1205 | } |
| 1206 | |
| 1207 | static PyObject *Res_FSpCreateResFile(_self, _args) |
| 1208 | PyObject *_self; |
| 1209 | PyObject *_args; |
| 1210 | { |
| 1211 | PyObject *_res = NULL; |
| 1212 | FSSpec spec; |
| 1213 | OSType creator; |
| 1214 | OSType fileType; |
| 1215 | ScriptCode scriptTag; |
| 1216 | if (!PyArg_ParseTuple(_args, "O&O&O&h", |
| 1217 | PyMac_GetFSSpec, &spec, |
| 1218 | PyMac_GetOSType, &creator, |
| 1219 | PyMac_GetOSType, &fileType, |
| 1220 | &scriptTag)) |
| 1221 | return NULL; |
| 1222 | FSpCreateResFile(&spec, |
| 1223 | creator, |
| 1224 | fileType, |
| 1225 | scriptTag); |
| 1226 | { |
| 1227 | OSErr _err = ResError(); |
| 1228 | if (_err != noErr) return PyMac_Error(_err); |
| 1229 | } |
| 1230 | Py_INCREF(Py_None); |
| 1231 | _res = Py_None; |
| 1232 | return _res; |
| 1233 | } |
| 1234 | |
Guido van Rossum | 9bcb641 | 1995-02-05 16:54:27 +0000 | [diff] [blame] | 1235 | static PyObject *Res_Resource(_self, _args) |
| 1236 | PyObject *_self; |
| 1237 | PyObject *_args; |
| 1238 | { |
| 1239 | PyObject *_res = NULL; |
| 1240 | |
| 1241 | char *buf; |
| 1242 | int len; |
| 1243 | Handle h; |
| 1244 | |
| 1245 | if (!PyArg_ParseTuple(_args, "s#", &buf, &len)) |
| 1246 | return NULL; |
| 1247 | h = NewHandle(len); |
| 1248 | if ( h == NULL ) { |
| 1249 | PyErr_NoMemory(); |
| 1250 | return NULL; |
| 1251 | } |
| 1252 | HLock(h); |
| 1253 | memcpy(*h, buf, len); |
| 1254 | HUnlock(h); |
| 1255 | return (PyObject *)ResObj_New(h); |
| 1256 | |
| 1257 | } |
| 1258 | |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1259 | static PyMethodDef Res_methods[] = { |
| 1260 | {"InitResources", (PyCFunction)Res_InitResources, 1, |
| 1261 | "() -> (short _rv)"}, |
| 1262 | {"RsrcZoneInit", (PyCFunction)Res_RsrcZoneInit, 1, |
| 1263 | "() -> None"}, |
| 1264 | {"CloseResFile", (PyCFunction)Res_CloseResFile, 1, |
| 1265 | "(short refNum) -> None"}, |
| 1266 | {"ResError", (PyCFunction)Res_ResError, 1, |
| 1267 | "() -> (short _rv)"}, |
| 1268 | {"CurResFile", (PyCFunction)Res_CurResFile, 1, |
| 1269 | "() -> (short _rv)"}, |
| 1270 | {"CreateResFile", (PyCFunction)Res_CreateResFile, 1, |
| 1271 | "(Str255 fileName) -> None"}, |
| 1272 | {"OpenResFile", (PyCFunction)Res_OpenResFile, 1, |
| 1273 | "(Str255 fileName) -> (short _rv)"}, |
| 1274 | {"UseResFile", (PyCFunction)Res_UseResFile, 1, |
| 1275 | "(short refNum) -> None"}, |
| 1276 | {"CountTypes", (PyCFunction)Res_CountTypes, 1, |
| 1277 | "() -> (short _rv)"}, |
| 1278 | {"Count1Types", (PyCFunction)Res_Count1Types, 1, |
| 1279 | "() -> (short _rv)"}, |
| 1280 | {"GetIndType", (PyCFunction)Res_GetIndType, 1, |
| 1281 | "(short index) -> (ResType theType)"}, |
| 1282 | {"Get1IndType", (PyCFunction)Res_Get1IndType, 1, |
| 1283 | "(short index) -> (ResType theType)"}, |
| 1284 | {"SetResLoad", (PyCFunction)Res_SetResLoad, 1, |
| 1285 | "(Boolean load) -> None"}, |
| 1286 | {"CountResources", (PyCFunction)Res_CountResources, 1, |
| 1287 | "(ResType theType) -> (short _rv)"}, |
| 1288 | {"Count1Resources", (PyCFunction)Res_Count1Resources, 1, |
| 1289 | "(ResType theType) -> (short _rv)"}, |
| 1290 | {"GetIndResource", (PyCFunction)Res_GetIndResource, 1, |
| 1291 | "(ResType theType, short index) -> (Handle _rv)"}, |
| 1292 | {"Get1IndResource", (PyCFunction)Res_Get1IndResource, 1, |
| 1293 | "(ResType theType, short index) -> (Handle _rv)"}, |
| 1294 | {"GetResource", (PyCFunction)Res_GetResource, 1, |
| 1295 | "(ResType theType, short theID) -> (Handle _rv)"}, |
| 1296 | {"Get1Resource", (PyCFunction)Res_Get1Resource, 1, |
| 1297 | "(ResType theType, short theID) -> (Handle _rv)"}, |
| 1298 | {"GetNamedResource", (PyCFunction)Res_GetNamedResource, 1, |
| 1299 | "(ResType theType, Str255 name) -> (Handle _rv)"}, |
| 1300 | {"Get1NamedResource", (PyCFunction)Res_Get1NamedResource, 1, |
| 1301 | "(ResType theType, Str255 name) -> (Handle _rv)"}, |
| 1302 | {"UniqueID", (PyCFunction)Res_UniqueID, 1, |
| 1303 | "(ResType theType) -> (short _rv)"}, |
| 1304 | {"Unique1ID", (PyCFunction)Res_Unique1ID, 1, |
| 1305 | "(ResType theType) -> (short _rv)"}, |
| 1306 | {"UpdateResFile", (PyCFunction)Res_UpdateResFile, 1, |
| 1307 | "(short refNum) -> None"}, |
| 1308 | {"SetResPurge", (PyCFunction)Res_SetResPurge, 1, |
| 1309 | "(Boolean install) -> None"}, |
| 1310 | {"GetResFileAttrs", (PyCFunction)Res_GetResFileAttrs, 1, |
| 1311 | "(short refNum) -> (short _rv)"}, |
| 1312 | {"SetResFileAttrs", (PyCFunction)Res_SetResFileAttrs, 1, |
| 1313 | "(short refNum, short attrs) -> None"}, |
| 1314 | {"OpenRFPerm", (PyCFunction)Res_OpenRFPerm, 1, |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 1315 | "(Str255 fileName, short vRefNum, SignedByte permission) -> (short _rv)"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1316 | {"RGetResource", (PyCFunction)Res_RGetResource, 1, |
| 1317 | "(ResType theType, short theID) -> (Handle _rv)"}, |
| 1318 | {"HOpenResFile", (PyCFunction)Res_HOpenResFile, 1, |
Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame] | 1319 | "(short vRefNum, long dirID, Str255 fileName, SignedByte permission) -> (short _rv)"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1320 | {"HCreateResFile", (PyCFunction)Res_HCreateResFile, 1, |
| 1321 | "(short vRefNum, long dirID, Str255 fileName) -> None"}, |
| 1322 | {"FSpOpenResFile", (PyCFunction)Res_FSpOpenResFile, 1, |
| 1323 | "(FSSpec spec, SignedByte permission) -> (short _rv)"}, |
| 1324 | {"FSpCreateResFile", (PyCFunction)Res_FSpCreateResFile, 1, |
| 1325 | "(FSSpec spec, OSType creator, OSType fileType, ScriptCode scriptTag) -> None"}, |
Guido van Rossum | 9bcb641 | 1995-02-05 16:54:27 +0000 | [diff] [blame] | 1326 | {"Resource", (PyCFunction)Res_Resource, 1, |
| 1327 | "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.\n"}, |
Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1328 | {NULL, NULL, 0} |
| 1329 | }; |
| 1330 | |
| 1331 | |
| 1332 | |
| 1333 | |
| 1334 | |
| 1335 | void initRes() |
| 1336 | { |
| 1337 | PyObject *m; |
| 1338 | PyObject *d; |
| 1339 | |
| 1340 | |
| 1341 | |
| 1342 | |
| 1343 | |
| 1344 | m = Py_InitModule("Res", Res_methods); |
| 1345 | d = PyModule_GetDict(m); |
| 1346 | Res_Error = PyMac_GetOSErrException(); |
| 1347 | if (Res_Error == NULL || |
| 1348 | PyDict_SetItemString(d, "Error", Res_Error) != 0) |
| 1349 | Py_FatalError("can't initialize Res.Error"); |
| 1350 | } |
| 1351 | |
| 1352 | /* ========================= End module Res ========================= */ |
| 1353 | |