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