Changeset 391 for python/trunk/Mac/Modules/cm
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Mac/Modules/cm/_Cmmodule.c
r2 r391 10 10 /* Macro to test whether a weak-loaded CFM function exists */ 11 11 #define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\ 12 13 14 12 PyErr_SetString(PyExc_NotImplementedError, \ 13 "Not available in this shared library/OS version"); \ 14 return NULL; \ 15 15 }} while(0) 16 16 … … 37 37 { 38 38 39 40 41 42 43 39 return Py_BuildValue("O&O&O&ll", 40 PyMac_BuildOSType, itself->componentType, 41 PyMac_BuildOSType, itself->componentSubType, 42 PyMac_BuildOSType, itself->componentManufacturer, 43 itself->componentFlags, itself->componentFlagsMask); 44 44 } 45 45 … … 47 47 CmpDesc_Convert(PyObject *v, ComponentDescription *p_itself) 48 48 { 49 50 51 52 53 49 return PyArg_ParseTuple(v, "O&O&O&ll", 50 PyMac_GetOSType, &p_itself->componentType, 51 PyMac_GetOSType, &p_itself->componentSubType, 52 PyMac_GetOSType, &p_itself->componentManufacturer, 53 &p_itself->componentFlags, &p_itself->componentFlagsMask); 54 54 } 55 55 … … 64 64 65 65 typedef struct ComponentInstanceObject { 66 67 66 PyObject_HEAD 67 ComponentInstance ob_itself; 68 68 } ComponentInstanceObject; 69 69 70 70 PyObject *CmpInstObj_New(ComponentInstance itself) 71 71 { 72 73 74 75 76 77 78 79 80 72 ComponentInstanceObject *it; 73 if (itself == NULL) { 74 PyErr_SetString(Cm_Error,"NULL ComponentInstance"); 75 return NULL; 76 } 77 it = PyObject_NEW(ComponentInstanceObject, &ComponentInstance_Type); 78 if (it == NULL) return NULL; 79 it->ob_itself = itself; 80 return (PyObject *)it; 81 81 } 82 82 83 83 int CmpInstObj_Convert(PyObject *v, ComponentInstance *p_itself) 84 84 { 85 86 87 88 89 90 91 85 if (!CmpInstObj_Check(v)) 86 { 87 PyErr_SetString(PyExc_TypeError, "ComponentInstance required"); 88 return 0; 89 } 90 *p_itself = ((ComponentInstanceObject *)v)->ob_itself; 91 return 1; 92 92 } 93 93 94 94 static void CmpInstObj_dealloc(ComponentInstanceObject *self) 95 95 { 96 97 96 /* Cleanup of self->ob_itself goes here */ 97 self->ob_type->tp_free((PyObject *)self); 98 98 } 99 99 100 100 static PyObject *CmpInstObj_CloseComponent(ComponentInstanceObject *_self, PyObject *_args) 101 101 { 102 103 102 PyObject *_res = NULL; 103 OSErr _err; 104 104 #ifndef CloseComponent 105 106 #endif 107 108 109 110 111 112 113 105 PyMac_PRECHECK(CloseComponent); 106 #endif 107 if (!PyArg_ParseTuple(_args, "")) 108 return NULL; 109 _err = CloseComponent(_self->ob_itself); 110 if (_err != noErr) return PyMac_Error(_err); 111 Py_INCREF(Py_None); 112 _res = Py_None; 113 return _res; 114 114 } 115 115 116 116 static PyObject *CmpInstObj_GetComponentInstanceError(ComponentInstanceObject *_self, PyObject *_args) 117 117 { 118 119 118 PyObject *_res = NULL; 119 OSErr _err; 120 120 #ifndef GetComponentInstanceError 121 122 #endif 123 124 125 126 127 128 129 121 PyMac_PRECHECK(GetComponentInstanceError); 122 #endif 123 if (!PyArg_ParseTuple(_args, "")) 124 return NULL; 125 _err = GetComponentInstanceError(_self->ob_itself); 126 if (_err != noErr) return PyMac_Error(_err); 127 Py_INCREF(Py_None); 128 _res = Py_None; 129 return _res; 130 130 } 131 131 132 132 static PyObject *CmpInstObj_SetComponentInstanceError(ComponentInstanceObject *_self, PyObject *_args) 133 133 { 134 135 134 PyObject *_res = NULL; 135 OSErr theError; 136 136 #ifndef SetComponentInstanceError 137 138 #endif 139 140 141 142 143 144 145 146 137 PyMac_PRECHECK(SetComponentInstanceError); 138 #endif 139 if (!PyArg_ParseTuple(_args, "h", 140 &theError)) 141 return NULL; 142 SetComponentInstanceError(_self->ob_itself, 143 theError); 144 Py_INCREF(Py_None); 145 _res = Py_None; 146 return _res; 147 147 } 148 148 149 149 static PyObject *CmpInstObj_GetComponentInstanceStorage(ComponentInstanceObject *_self, PyObject *_args) 150 150 { 151 152 151 PyObject *_res = NULL; 152 Handle _rv; 153 153 #ifndef GetComponentInstanceStorage 154 155 #endif 156 157 158 159 160 161 154 PyMac_PRECHECK(GetComponentInstanceStorage); 155 #endif 156 if (!PyArg_ParseTuple(_args, "")) 157 return NULL; 158 _rv = GetComponentInstanceStorage(_self->ob_itself); 159 _res = Py_BuildValue("O&", 160 ResObj_New, _rv); 161 return _res; 162 162 } 163 163 164 164 static PyObject *CmpInstObj_SetComponentInstanceStorage(ComponentInstanceObject *_self, PyObject *_args) 165 165 { 166 167 166 PyObject *_res = NULL; 167 Handle theStorage; 168 168 #ifndef SetComponentInstanceStorage 169 170 #endif 171 172 173 174 175 176 177 178 169 PyMac_PRECHECK(SetComponentInstanceStorage); 170 #endif 171 if (!PyArg_ParseTuple(_args, "O&", 172 ResObj_Convert, &theStorage)) 173 return NULL; 174 SetComponentInstanceStorage(_self->ob_itself, 175 theStorage); 176 Py_INCREF(Py_None); 177 _res = Py_None; 178 return _res; 179 179 } 180 180 … … 182 182 static PyObject *CmpInstObj_ComponentFunctionImplemented(ComponentInstanceObject *_self, PyObject *_args) 183 183 { 184 185 186 184 PyObject *_res = NULL; 185 long _rv; 186 short ftnNumber; 187 187 #ifndef ComponentFunctionImplemented 188 189 #endif 190 191 192 193 194 195 196 197 188 PyMac_PRECHECK(ComponentFunctionImplemented); 189 #endif 190 if (!PyArg_ParseTuple(_args, "h", 191 &ftnNumber)) 192 return NULL; 193 _rv = ComponentFunctionImplemented(_self->ob_itself, 194 ftnNumber); 195 _res = Py_BuildValue("l", 196 _rv); 197 return _res; 198 198 } 199 199 200 200 static PyObject *CmpInstObj_GetComponentVersion(ComponentInstanceObject *_self, PyObject *_args) 201 201 { 202 203 202 PyObject *_res = NULL; 203 long _rv; 204 204 #ifndef GetComponentVersion 205 206 #endif 207 208 209 210 211 212 205 PyMac_PRECHECK(GetComponentVersion); 206 #endif 207 if (!PyArg_ParseTuple(_args, "")) 208 return NULL; 209 _rv = GetComponentVersion(_self->ob_itself); 210 _res = Py_BuildValue("l", 211 _rv); 212 return _res; 213 213 } 214 214 215 215 static PyObject *CmpInstObj_ComponentSetTarget(ComponentInstanceObject *_self, PyObject *_args) 216 216 { 217 218 219 217 PyObject *_res = NULL; 218 long _rv; 219 ComponentInstance target; 220 220 #ifndef ComponentSetTarget 221 222 #endif 223 224 225 226 227 228 229 230 221 PyMac_PRECHECK(ComponentSetTarget); 222 #endif 223 if (!PyArg_ParseTuple(_args, "O&", 224 CmpInstObj_Convert, &target)) 225 return NULL; 226 _rv = ComponentSetTarget(_self->ob_itself, 227 target); 228 _res = Py_BuildValue("l", 229 _rv); 230 return _res; 231 231 } 232 232 #endif /* !__LP64__*/ 233 233 234 234 static PyMethodDef CmpInstObj_methods[] = { 235 236 237 238 239 240 241 242 243 244 235 {"CloseComponent", (PyCFunction)CmpInstObj_CloseComponent, 1, 236 PyDoc_STR("() -> None")}, 237 {"GetComponentInstanceError", (PyCFunction)CmpInstObj_GetComponentInstanceError, 1, 238 PyDoc_STR("() -> None")}, 239 {"SetComponentInstanceError", (PyCFunction)CmpInstObj_SetComponentInstanceError, 1, 240 PyDoc_STR("(OSErr theError) -> None")}, 241 {"GetComponentInstanceStorage", (PyCFunction)CmpInstObj_GetComponentInstanceStorage, 1, 242 PyDoc_STR("() -> (Handle _rv)")}, 243 {"SetComponentInstanceStorage", (PyCFunction)CmpInstObj_SetComponentInstanceStorage, 1, 244 PyDoc_STR("(Handle theStorage) -> None")}, 245 245 #ifndef __LP64__ 246 247 248 249 250 251 246 {"ComponentFunctionImplemented", (PyCFunction)CmpInstObj_ComponentFunctionImplemented, 1, 247 PyDoc_STR("(short ftnNumber) -> (long _rv)")}, 248 {"GetComponentVersion", (PyCFunction)CmpInstObj_GetComponentVersion, 1, 249 PyDoc_STR("() -> (long _rv)")}, 250 {"ComponentSetTarget", (PyCFunction)CmpInstObj_ComponentSetTarget, 1, 251 PyDoc_STR("(ComponentInstance target) -> (long _rv)")}, 252 252 #endif /* !__LP64__ */ 253 253 {NULL, NULL, 0} 254 254 }; 255 255 … … 268 268 static PyObject *CmpInstObj_tp_new(PyTypeObject *type, PyObject *_args, PyObject *_kwds) 269 269 { 270 271 272 273 274 275 276 277 270 PyObject *_self; 271 ComponentInstance itself; 272 char *kw[] = {"itself", 0}; 273 274 if (!PyArg_ParseTupleAndKeywords(_args, _kwds, "O&", kw, CmpInstObj_Convert, &itself)) return NULL; 275 if ((_self = type->tp_alloc(type, 0)) == NULL) return NULL; 276 ((ComponentInstanceObject *)_self)->ob_itself = itself; 277 return _self; 278 278 } 279 279 … … 282 282 283 283 PyTypeObject ComponentInstance_Type = { 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 284 PyObject_HEAD_INIT(NULL) 285 0, /*ob_size*/ 286 "_Cm.ComponentInstance", /*tp_name*/ 287 sizeof(ComponentInstanceObject), /*tp_basicsize*/ 288 0, /*tp_itemsize*/ 289 /* methods */ 290 (destructor) CmpInstObj_dealloc, /*tp_dealloc*/ 291 0, /*tp_print*/ 292 (getattrfunc)0, /*tp_getattr*/ 293 (setattrfunc)0, /*tp_setattr*/ 294 (cmpfunc) CmpInstObj_compare, /*tp_compare*/ 295 (reprfunc) CmpInstObj_repr, /*tp_repr*/ 296 (PyNumberMethods *)0, /* tp_as_number */ 297 (PySequenceMethods *)0, /* tp_as_sequence */ 298 (PyMappingMethods *)0, /* tp_as_mapping */ 299 (hashfunc) CmpInstObj_hash, /*tp_hash*/ 300 0, /*tp_call*/ 301 0, /*tp_str*/ 302 PyObject_GenericGetAttr, /*tp_getattro*/ 303 PyObject_GenericSetAttr, /*tp_setattro */ 304 0, /*tp_as_buffer*/ 305 Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */ 306 0, /*tp_doc*/ 307 0, /*tp_traverse*/ 308 0, /*tp_clear*/ 309 0, /*tp_richcompare*/ 310 0, /*tp_weaklistoffset*/ 311 0, /*tp_iter*/ 312 0, /*tp_iternext*/ 313 CmpInstObj_methods, /* tp_methods */ 314 0, /*tp_members*/ 315 CmpInstObj_getsetlist, /*tp_getset*/ 316 0, /*tp_base*/ 317 0, /*tp_dict*/ 318 0, /*tp_descr_get*/ 319 0, /*tp_descr_set*/ 320 0, /*tp_dictoffset*/ 321 CmpInstObj_tp_init, /* tp_init */ 322 CmpInstObj_tp_alloc, /* tp_alloc */ 323 CmpInstObj_tp_new, /* tp_new */ 324 CmpInstObj_tp_free, /* tp_free */ 325 325 }; 326 326 … … 335 335 336 336 typedef struct ComponentObject { 337 338 337 PyObject_HEAD 338 Component ob_itself; 339 339 } ComponentObject; 340 340 341 341 PyObject *CmpObj_New(Component itself) 342 342 { 343 344 345 346 347 348 349 350 351 352 343 ComponentObject *it; 344 if (itself == NULL) { 345 /* XXXX Or should we return None? */ 346 PyErr_SetString(Cm_Error,"No such component"); 347 return NULL; 348 } 349 it = PyObject_NEW(ComponentObject, &Component_Type); 350 if (it == NULL) return NULL; 351 it->ob_itself = itself; 352 return (PyObject *)it; 353 353 } 354 354 355 355 int CmpObj_Convert(PyObject *v, Component *p_itself) 356 356 { 357 358 359 360 361 362 363 364 365 366 367 357 if ( v == Py_None ) { 358 *p_itself = 0; 359 return 1; 360 } 361 if (!CmpObj_Check(v)) 362 { 363 PyErr_SetString(PyExc_TypeError, "Component required"); 364 return 0; 365 } 366 *p_itself = ((ComponentObject *)v)->ob_itself; 367 return 1; 368 368 } 369 369 370 370 static void CmpObj_dealloc(ComponentObject *self) 371 371 { 372 373 372 /* Cleanup of self->ob_itself goes here */ 373 self->ob_type->tp_free((PyObject *)self); 374 374 } 375 375 376 376 static PyObject *CmpObj_UnregisterComponent(ComponentObject *_self, PyObject *_args) 377 377 { 378 379 378 PyObject *_res = NULL; 379 OSErr _err; 380 380 #ifndef UnregisterComponent 381 382 #endif 383 384 385 386 387 388 389 381 PyMac_PRECHECK(UnregisterComponent); 382 #endif 383 if (!PyArg_ParseTuple(_args, "")) 384 return NULL; 385 _err = UnregisterComponent(_self->ob_itself); 386 if (_err != noErr) return PyMac_Error(_err); 387 Py_INCREF(Py_None); 388 _res = Py_None; 389 return _res; 390 390 } 391 391 392 392 static PyObject *CmpObj_GetComponentInfo(ComponentObject *_self, PyObject *_args) 393 393 { 394 395 396 397 398 399 394 PyObject *_res = NULL; 395 OSErr _err; 396 ComponentDescription cd; 397 Handle componentName; 398 Handle componentInfo; 399 Handle componentIcon; 400 400 #ifndef GetComponentInfo 401 402 #endif 403 404 405 406 407 408 409 410 411 412 413 414 415 416 401 PyMac_PRECHECK(GetComponentInfo); 402 #endif 403 if (!PyArg_ParseTuple(_args, "O&O&O&", 404 ResObj_Convert, &componentName, 405 ResObj_Convert, &componentInfo, 406 ResObj_Convert, &componentIcon)) 407 return NULL; 408 _err = GetComponentInfo(_self->ob_itself, 409 &cd, 410 componentName, 411 componentInfo, 412 componentIcon); 413 if (_err != noErr) return PyMac_Error(_err); 414 _res = Py_BuildValue("O&", 415 CmpDesc_New, &cd); 416 return _res; 417 417 } 418 418 419 419 static PyObject *CmpObj_OpenComponent(ComponentObject *_self, PyObject *_args) 420 420 { 421 422 421 PyObject *_res = NULL; 422 ComponentInstance _rv; 423 423 #ifndef OpenComponent 424 425 #endif 426 427 428 429 430 431 424 PyMac_PRECHECK(OpenComponent); 425 #endif 426 if (!PyArg_ParseTuple(_args, "")) 427 return NULL; 428 _rv = OpenComponent(_self->ob_itself); 429 _res = Py_BuildValue("O&", 430 CmpInstObj_New, _rv); 431 return _res; 432 432 } 433 433 434 434 static PyObject *CmpObj_ResolveComponentAlias(ComponentObject *_self, PyObject *_args) 435 435 { 436 437 436 PyObject *_res = NULL; 437 Component _rv; 438 438 #ifndef ResolveComponentAlias 439 440 #endif 441 442 443 444 445 446 439 PyMac_PRECHECK(ResolveComponentAlias); 440 #endif 441 if (!PyArg_ParseTuple(_args, "")) 442 return NULL; 443 _rv = ResolveComponentAlias(_self->ob_itself); 444 _res = Py_BuildValue("O&", 445 CmpObj_New, _rv); 446 return _res; 447 447 } 448 448 449 449 static PyObject *CmpObj_GetComponentPublicIndString(ComponentObject *_self, PyObject *_args) 450 450 { 451 452 453 454 455 451 PyObject *_res = NULL; 452 OSErr _err; 453 Str255 theString; 454 short strListID; 455 short index; 456 456 #ifndef GetComponentPublicIndString 457 458 #endif 459 460 461 462 463 464 465 466 467 468 469 470 471 457 PyMac_PRECHECK(GetComponentPublicIndString); 458 #endif 459 if (!PyArg_ParseTuple(_args, "O&hh", 460 PyMac_GetStr255, theString, 461 &strListID, 462 &index)) 463 return NULL; 464 _err = GetComponentPublicIndString(_self->ob_itself, 465 theString, 466 strListID, 467 index); 468 if (_err != noErr) return PyMac_Error(_err); 469 Py_INCREF(Py_None); 470 _res = Py_None; 471 return _res; 472 472 } 473 473 474 474 static PyObject *CmpObj_GetComponentRefcon(ComponentObject *_self, PyObject *_args) 475 475 { 476 477 476 PyObject *_res = NULL; 477 long _rv; 478 478 #ifndef GetComponentRefcon 479 480 #endif 481 482 483 484 485 486 479 PyMac_PRECHECK(GetComponentRefcon); 480 #endif 481 if (!PyArg_ParseTuple(_args, "")) 482 return NULL; 483 _rv = GetComponentRefcon(_self->ob_itself); 484 _res = Py_BuildValue("l", 485 _rv); 486 return _res; 487 487 } 488 488 489 489 static PyObject *CmpObj_SetComponentRefcon(ComponentObject *_self, PyObject *_args) 490 490 { 491 492 491 PyObject *_res = NULL; 492 long theRefcon; 493 493 #ifndef SetComponentRefcon 494 495 #endif 496 497 498 499 500 501 502 503 494 PyMac_PRECHECK(SetComponentRefcon); 495 #endif 496 if (!PyArg_ParseTuple(_args, "l", 497 &theRefcon)) 498 return NULL; 499 SetComponentRefcon(_self->ob_itself, 500 theRefcon); 501 Py_INCREF(Py_None); 502 _res = Py_None; 503 return _res; 504 504 } 505 505 506 506 static PyObject *CmpObj_OpenComponentResFile(ComponentObject *_self, PyObject *_args) 507 507 { 508 509 508 PyObject *_res = NULL; 509 short _rv; 510 510 #ifndef OpenComponentResFile 511 512 #endif 513 514 515 516 517 518 511 PyMac_PRECHECK(OpenComponentResFile); 512 #endif 513 if (!PyArg_ParseTuple(_args, "")) 514 return NULL; 515 _rv = OpenComponentResFile(_self->ob_itself); 516 _res = Py_BuildValue("h", 517 _rv); 518 return _res; 519 519 } 520 520 521 521 static PyObject *CmpObj_GetComponentResource(ComponentObject *_self, PyObject *_args) 522 522 { 523 524 525 526 527 523 PyObject *_res = NULL; 524 OSErr _err; 525 OSType resType; 526 short resID; 527 Handle theResource; 528 528 #ifndef GetComponentResource 529 530 #endif 531 532 533 534 535 536 537 538 539 540 541 542 529 PyMac_PRECHECK(GetComponentResource); 530 #endif 531 if (!PyArg_ParseTuple(_args, "O&h", 532 PyMac_GetOSType, &resType, 533 &resID)) 534 return NULL; 535 _err = GetComponentResource(_self->ob_itself, 536 resType, 537 resID, 538 &theResource); 539 if (_err != noErr) return PyMac_Error(_err); 540 _res = Py_BuildValue("O&", 541 ResObj_New, theResource); 542 return _res; 543 543 } 544 544 545 545 static PyObject *CmpObj_GetComponentIndString(ComponentObject *_self, PyObject *_args) 546 546 { 547 548 549 550 551 547 PyObject *_res = NULL; 548 OSErr _err; 549 Str255 theString; 550 short strListID; 551 short index; 552 552 #ifndef GetComponentIndString 553 554 #endif 555 556 557 558 559 560 561 562 563 564 565 566 567 553 PyMac_PRECHECK(GetComponentIndString); 554 #endif 555 if (!PyArg_ParseTuple(_args, "O&hh", 556 PyMac_GetStr255, theString, 557 &strListID, 558 &index)) 559 return NULL; 560 _err = GetComponentIndString(_self->ob_itself, 561 theString, 562 strListID, 563 index); 564 if (_err != noErr) return PyMac_Error(_err); 565 Py_INCREF(Py_None); 566 _res = Py_None; 567 return _res; 568 568 } 569 569 570 570 static PyObject *CmpObj_CountComponentInstances(ComponentObject *_self, PyObject *_args) 571 571 { 572 573 572 PyObject *_res = NULL; 573 long _rv; 574 574 #ifndef CountComponentInstances 575 576 #endif 577 578 579 580 581 582 575 PyMac_PRECHECK(CountComponentInstances); 576 #endif 577 if (!PyArg_ParseTuple(_args, "")) 578 return NULL; 579 _rv = CountComponentInstances(_self->ob_itself); 580 _res = Py_BuildValue("l", 581 _rv); 582 return _res; 583 583 } 584 584 585 585 static PyObject *CmpObj_SetDefaultComponent(ComponentObject *_self, PyObject *_args) 586 586 { 587 588 589 587 PyObject *_res = NULL; 588 OSErr _err; 589 short flags; 590 590 #ifndef SetDefaultComponent 591 592 #endif 593 594 595 596 597 598 599 600 601 591 PyMac_PRECHECK(SetDefaultComponent); 592 #endif 593 if (!PyArg_ParseTuple(_args, "h", 594 &flags)) 595 return NULL; 596 _err = SetDefaultComponent(_self->ob_itself, 597 flags); 598 if (_err != noErr) return PyMac_Error(_err); 599 Py_INCREF(Py_None); 600 _res = Py_None; 601 return _res; 602 602 } 603 603 604 604 static PyObject *CmpObj_CaptureComponent(ComponentObject *_self, PyObject *_args) 605 605 { 606 607 608 606 PyObject *_res = NULL; 607 Component _rv; 608 Component capturingComponent; 609 609 #ifndef CaptureComponent 610 611 #endif 612 613 614 615 616 617 618 619 610 PyMac_PRECHECK(CaptureComponent); 611 #endif 612 if (!PyArg_ParseTuple(_args, "O&", 613 CmpObj_Convert, &capturingComponent)) 614 return NULL; 615 _rv = CaptureComponent(_self->ob_itself, 616 capturingComponent); 617 _res = Py_BuildValue("O&", 618 CmpObj_New, _rv); 619 return _res; 620 620 } 621 621 622 622 static PyObject *CmpObj_UncaptureComponent(ComponentObject *_self, PyObject *_args) 623 623 { 624 625 624 PyObject *_res = NULL; 625 OSErr _err; 626 626 #ifndef UncaptureComponent 627 628 #endif 629 630 631 632 633 634 635 627 PyMac_PRECHECK(UncaptureComponent); 628 #endif 629 if (!PyArg_ParseTuple(_args, "")) 630 return NULL; 631 _err = UncaptureComponent(_self->ob_itself); 632 if (_err != noErr) return PyMac_Error(_err); 633 Py_INCREF(Py_None); 634 _res = Py_None; 635 return _res; 636 636 } 637 637 … … 639 639 static PyObject *CmpObj_GetComponentIconSuite(ComponentObject *_self, PyObject *_args) 640 640 { 641 642 643 641 PyObject *_res = NULL; 642 OSErr _err; 643 Handle iconSuite; 644 644 #ifndef GetComponentIconSuite 645 646 #endif 647 648 649 650 651 652 653 654 645 PyMac_PRECHECK(GetComponentIconSuite); 646 #endif 647 if (!PyArg_ParseTuple(_args, "")) 648 return NULL; 649 _err = GetComponentIconSuite(_self->ob_itself, 650 &iconSuite); 651 if (_err != noErr) return PyMac_Error(_err); 652 _res = Py_BuildValue("O&", 653 ResObj_New, iconSuite); 654 return _res; 655 655 } 656 656 #endif /* !__LP64__ */ 657 657 658 658 static PyMethodDef CmpObj_methods[] = { 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 659 {"UnregisterComponent", (PyCFunction)CmpObj_UnregisterComponent, 1, 660 PyDoc_STR("() -> None")}, 661 {"GetComponentInfo", (PyCFunction)CmpObj_GetComponentInfo, 1, 662 PyDoc_STR("(Handle componentName, Handle componentInfo, Handle componentIcon) -> (ComponentDescription cd)")}, 663 {"OpenComponent", (PyCFunction)CmpObj_OpenComponent, 1, 664 PyDoc_STR("() -> (ComponentInstance _rv)")}, 665 {"ResolveComponentAlias", (PyCFunction)CmpObj_ResolveComponentAlias, 1, 666 PyDoc_STR("() -> (Component _rv)")}, 667 {"GetComponentPublicIndString", (PyCFunction)CmpObj_GetComponentPublicIndString, 1, 668 PyDoc_STR("(Str255 theString, short strListID, short index) -> None")}, 669 {"GetComponentRefcon", (PyCFunction)CmpObj_GetComponentRefcon, 1, 670 PyDoc_STR("() -> (long _rv)")}, 671 {"SetComponentRefcon", (PyCFunction)CmpObj_SetComponentRefcon, 1, 672 PyDoc_STR("(long theRefcon) -> None")}, 673 {"OpenComponentResFile", (PyCFunction)CmpObj_OpenComponentResFile, 1, 674 PyDoc_STR("() -> (short _rv)")}, 675 {"GetComponentResource", (PyCFunction)CmpObj_GetComponentResource, 1, 676 PyDoc_STR("(OSType resType, short resID) -> (Handle theResource)")}, 677 {"GetComponentIndString", (PyCFunction)CmpObj_GetComponentIndString, 1, 678 PyDoc_STR("(Str255 theString, short strListID, short index) -> None")}, 679 {"CountComponentInstances", (PyCFunction)CmpObj_CountComponentInstances, 1, 680 PyDoc_STR("() -> (long _rv)")}, 681 {"SetDefaultComponent", (PyCFunction)CmpObj_SetDefaultComponent, 1, 682 PyDoc_STR("(short flags) -> None")}, 683 {"CaptureComponent", (PyCFunction)CmpObj_CaptureComponent, 1, 684 PyDoc_STR("(Component capturingComponent) -> (Component _rv)")}, 685 {"UncaptureComponent", (PyCFunction)CmpObj_UncaptureComponent, 1, 686 PyDoc_STR("() -> None")}, 687 687 #ifndef __LP64__ 688 689 688 {"GetComponentIconSuite", (PyCFunction)CmpObj_GetComponentIconSuite, 1, 689 PyDoc_STR("() -> (Handle iconSuite)")}, 690 690 #endif /* !__LP64__ */ 691 691 {NULL, NULL, 0} 692 692 }; 693 693 … … 706 706 static PyObject *CmpObj_tp_new(PyTypeObject *type, PyObject *_args, PyObject *_kwds) 707 707 { 708 709 710 711 712 713 714 715 708 PyObject *_self; 709 Component itself; 710 char *kw[] = {"itself", 0}; 711 712 if (!PyArg_ParseTupleAndKeywords(_args, _kwds, "O&", kw, CmpObj_Convert, &itself)) return NULL; 713 if ((_self = type->tp_alloc(type, 0)) == NULL) return NULL; 714 ((ComponentObject *)_self)->ob_itself = itself; 715 return _self; 716 716 } 717 717 … … 720 720 721 721 PyTypeObject Component_Type = { 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 722 PyObject_HEAD_INIT(NULL) 723 0, /*ob_size*/ 724 "_Cm.Component", /*tp_name*/ 725 sizeof(ComponentObject), /*tp_basicsize*/ 726 0, /*tp_itemsize*/ 727 /* methods */ 728 (destructor) CmpObj_dealloc, /*tp_dealloc*/ 729 0, /*tp_print*/ 730 (getattrfunc)0, /*tp_getattr*/ 731 (setattrfunc)0, /*tp_setattr*/ 732 (cmpfunc) CmpObj_compare, /*tp_compare*/ 733 (reprfunc) CmpObj_repr, /*tp_repr*/ 734 (PyNumberMethods *)0, /* tp_as_number */ 735 (PySequenceMethods *)0, /* tp_as_sequence */ 736 (PyMappingMethods *)0, /* tp_as_mapping */ 737 (hashfunc) CmpObj_hash, /*tp_hash*/ 738 0, /*tp_call*/ 739 0, /*tp_str*/ 740 PyObject_GenericGetAttr, /*tp_getattro*/ 741 PyObject_GenericSetAttr, /*tp_setattro */ 742 0, /*tp_as_buffer*/ 743 Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */ 744 0, /*tp_doc*/ 745 0, /*tp_traverse*/ 746 0, /*tp_clear*/ 747 0, /*tp_richcompare*/ 748 0, /*tp_weaklistoffset*/ 749 0, /*tp_iter*/ 750 0, /*tp_iternext*/ 751 CmpObj_methods, /* tp_methods */ 752 0, /*tp_members*/ 753 CmpObj_getsetlist, /*tp_getset*/ 754 0, /*tp_base*/ 755 0, /*tp_dict*/ 756 0, /*tp_descr_get*/ 757 0, /*tp_descr_set*/ 758 0, /*tp_dictoffset*/ 759 CmpObj_tp_init, /* tp_init */ 760 CmpObj_tp_alloc, /* tp_alloc */ 761 CmpObj_tp_new, /* tp_new */ 762 CmpObj_tp_free, /* tp_free */ 763 763 }; 764 764 … … 768 768 static PyObject *Cm_RegisterComponentResource(PyObject *_self, PyObject *_args) 769 769 { 770 771 772 773 770 PyObject *_res = NULL; 771 Component _rv; 772 ComponentResourceHandle cr; 773 short global; 774 774 #ifndef RegisterComponentResource 775 776 #endif 777 778 779 780 781 782 783 784 785 775 PyMac_PRECHECK(RegisterComponentResource); 776 #endif 777 if (!PyArg_ParseTuple(_args, "O&h", 778 ResObj_Convert, &cr, 779 &global)) 780 return NULL; 781 _rv = RegisterComponentResource(cr, 782 global); 783 _res = Py_BuildValue("O&", 784 CmpObj_New, _rv); 785 return _res; 786 786 } 787 787 788 788 static PyObject *Cm_FindNextComponent(PyObject *_self, PyObject *_args) 789 789 { 790 791 792 793 790 PyObject *_res = NULL; 791 Component _rv; 792 Component aComponent; 793 ComponentDescription looking; 794 794 #ifndef FindNextComponent 795 796 #endif 797 798 799 800 801 802 803 804 805 795 PyMac_PRECHECK(FindNextComponent); 796 #endif 797 if (!PyArg_ParseTuple(_args, "O&O&", 798 CmpObj_Convert, &aComponent, 799 CmpDesc_Convert, &looking)) 800 return NULL; 801 _rv = FindNextComponent(aComponent, 802 &looking); 803 _res = Py_BuildValue("O&", 804 CmpObj_New, _rv); 805 return _res; 806 806 } 807 807 808 808 static PyObject *Cm_CountComponents(PyObject *_self, PyObject *_args) 809 809 { 810 811 812 810 PyObject *_res = NULL; 811 long _rv; 812 ComponentDescription looking; 813 813 #ifndef CountComponents 814 815 #endif 816 817 818 819 820 821 822 814 PyMac_PRECHECK(CountComponents); 815 #endif 816 if (!PyArg_ParseTuple(_args, "O&", 817 CmpDesc_Convert, &looking)) 818 return NULL; 819 _rv = CountComponents(&looking); 820 _res = Py_BuildValue("l", 821 _rv); 822 return _res; 823 823 } 824 824 825 825 static PyObject *Cm_GetComponentListModSeed(PyObject *_self, PyObject *_args) 826 826 { 827 828 827 PyObject *_res = NULL; 828 long _rv; 829 829 #ifndef GetComponentListModSeed 830 831 #endif 832 833 834 835 836 837 830 PyMac_PRECHECK(GetComponentListModSeed); 831 #endif 832 if (!PyArg_ParseTuple(_args, "")) 833 return NULL; 834 _rv = GetComponentListModSeed(); 835 _res = Py_BuildValue("l", 836 _rv); 837 return _res; 838 838 } 839 839 840 840 static PyObject *Cm_CloseComponentResFile(PyObject *_self, PyObject *_args) 841 841 { 842 843 844 842 PyObject *_res = NULL; 843 OSErr _err; 844 short refnum; 845 845 #ifndef CloseComponentResFile 846 847 #endif 848 849 850 851 852 853 854 855 846 PyMac_PRECHECK(CloseComponentResFile); 847 #endif 848 if (!PyArg_ParseTuple(_args, "h", 849 &refnum)) 850 return NULL; 851 _err = CloseComponentResFile(refnum); 852 if (_err != noErr) return PyMac_Error(_err); 853 Py_INCREF(Py_None); 854 _res = Py_None; 855 return _res; 856 856 } 857 857 858 858 static PyObject *Cm_OpenDefaultComponent(PyObject *_self, PyObject *_args) 859 859 { 860 861 862 863 860 PyObject *_res = NULL; 861 ComponentInstance _rv; 862 OSType componentType; 863 OSType componentSubType; 864 864 #ifndef OpenDefaultComponent 865 866 #endif 867 868 869 870 871 872 873 874 875 865 PyMac_PRECHECK(OpenDefaultComponent); 866 #endif 867 if (!PyArg_ParseTuple(_args, "O&O&", 868 PyMac_GetOSType, &componentType, 869 PyMac_GetOSType, &componentSubType)) 870 return NULL; 871 _rv = OpenDefaultComponent(componentType, 872 componentSubType); 873 _res = Py_BuildValue("O&", 874 CmpInstObj_New, _rv); 875 return _res; 876 876 } 877 877 878 878 static PyObject *Cm_RegisterComponentResourceFile(PyObject *_self, PyObject *_args) 879 879 { 880 881 882 883 880 PyObject *_res = NULL; 881 long _rv; 882 short resRefNum; 883 short global; 884 884 #ifndef RegisterComponentResourceFile 885 886 #endif 887 888 889 890 891 892 893 894 895 885 PyMac_PRECHECK(RegisterComponentResourceFile); 886 #endif 887 if (!PyArg_ParseTuple(_args, "hh", 888 &resRefNum, 889 &global)) 890 return NULL; 891 _rv = RegisterComponentResourceFile(resRefNum, 892 global); 893 _res = Py_BuildValue("l", 894 _rv); 895 return _res; 896 896 } 897 897 898 898 static PyMethodDef Cm_methods[] = { 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 899 {"RegisterComponentResource", (PyCFunction)Cm_RegisterComponentResource, 1, 900 PyDoc_STR("(ComponentResourceHandle cr, short global) -> (Component _rv)")}, 901 {"FindNextComponent", (PyCFunction)Cm_FindNextComponent, 1, 902 PyDoc_STR("(Component aComponent, ComponentDescription looking) -> (Component _rv)")}, 903 {"CountComponents", (PyCFunction)Cm_CountComponents, 1, 904 PyDoc_STR("(ComponentDescription looking) -> (long _rv)")}, 905 {"GetComponentListModSeed", (PyCFunction)Cm_GetComponentListModSeed, 1, 906 PyDoc_STR("() -> (long _rv)")}, 907 {"CloseComponentResFile", (PyCFunction)Cm_CloseComponentResFile, 1, 908 PyDoc_STR("(short refnum) -> None")}, 909 {"OpenDefaultComponent", (PyCFunction)Cm_OpenDefaultComponent, 1, 910 PyDoc_STR("(OSType componentType, OSType componentSubType) -> (ComponentInstance _rv)")}, 911 {"RegisterComponentResourceFile", (PyCFunction)Cm_RegisterComponentResourceFile, 1, 912 PyDoc_STR("(short resRefNum, short global) -> (long _rv)")}, 913 {NULL, NULL, 0} 914 914 }; 915 915 … … 919 919 void init_Cm(void) 920 920 { 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 921 PyObject *m; 922 PyObject *d; 923 924 925 926 PyMac_INIT_TOOLBOX_OBJECT_NEW(Component, CmpObj_New); 927 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(Component, CmpObj_Convert); 928 PyMac_INIT_TOOLBOX_OBJECT_NEW(ComponentInstance, CmpInstObj_New); 929 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(ComponentInstance, CmpInstObj_Convert); 930 931 932 m = Py_InitModule("_Cm", Cm_methods); 933 d = PyModule_GetDict(m); 934 Cm_Error = PyMac_GetOSErrException(); 935 if (Cm_Error == NULL || 936 PyDict_SetItemString(d, "Error", Cm_Error) != 0) 937 return; 938 ComponentInstance_Type.ob_type = &PyType_Type; 939 if (PyType_Ready(&ComponentInstance_Type) < 0) return; 940 Py_INCREF(&ComponentInstance_Type); 941 PyModule_AddObject(m, "ComponentInstance", (PyObject *)&ComponentInstance_Type); 942 /* Backward-compatible name */ 943 Py_INCREF(&ComponentInstance_Type); 944 PyModule_AddObject(m, "ComponentInstanceType", (PyObject *)&ComponentInstance_Type); 945 Component_Type.ob_type = &PyType_Type; 946 if (PyType_Ready(&Component_Type) < 0) return; 947 Py_INCREF(&Component_Type); 948 PyModule_AddObject(m, "Component", (PyObject *)&Component_Type); 949 /* Backward-compatible name */ 950 Py_INCREF(&Component_Type); 951 PyModule_AddObject(m, "ComponentType", (PyObject *)&Component_Type); 952 952 } 953 953
Note:
See TracChangeset
for help on using the changeset viewer.