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