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