/Mac/Modules/ae/_AEmodule.c

http://unladen-swallow.googlecode.com/ · C · 1459 lines · 1347 code · 105 blank · 7 comment · 174 complexity · 23acde0705d78c73740fd71901d15e76 MD5 · raw file

  1. /* =========================== Module _AE =========================== */
  2. #include "Python.h"
  3. #include "pymactoolbox.h"
  4. #ifndef HAVE_OSX105_SDK
  5. typedef SInt32 SRefCon;
  6. #endif
  7. /* Macro to test whether a weak-loaded CFM function exists */
  8. #define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
  9. PyErr_SetString(PyExc_NotImplementedError, \
  10. "Not available in this shared library/OS version"); \
  11. return NULL; \
  12. }} while(0)
  13. #include <Carbon/Carbon.h>
  14. #ifdef USE_TOOLBOX_OBJECT_GLUE
  15. extern PyObject *_AEDesc_New(AEDesc *);
  16. extern int _AEDesc_Convert(PyObject *, AEDesc *);
  17. #define AEDesc_New _AEDesc_New
  18. #define AEDesc_NewBorrowed _AEDesc_NewBorrowed
  19. #define AEDesc_Convert _AEDesc_Convert
  20. #endif
  21. typedef long refcontype;
  22. static pascal OSErr GenericEventHandler(const AppleEvent *request, AppleEvent *reply, refcontype refcon); /* Forward */
  23. AEEventHandlerUPP upp_GenericEventHandler;
  24. static pascal Boolean AEIdleProc(EventRecord *theEvent, long *sleepTime, RgnHandle *mouseRgn)
  25. {
  26. if ( PyOS_InterruptOccurred() )
  27. return 1;
  28. return 0;
  29. }
  30. AEIdleUPP upp_AEIdleProc;
  31. static PyObject *AE_Error;
  32. /* ----------------------- Object type AEDesc ----------------------- */
  33. PyTypeObject AEDesc_Type;
  34. #define AEDesc_Check(x) ((x)->ob_type == &AEDesc_Type || PyObject_TypeCheck((x), &AEDesc_Type))
  35. typedef struct AEDescObject {
  36. PyObject_HEAD
  37. AEDesc ob_itself;
  38. int ob_owned;
  39. } AEDescObject;
  40. PyObject *AEDesc_New(AEDesc *itself)
  41. {
  42. AEDescObject *it;
  43. it = PyObject_NEW(AEDescObject, &AEDesc_Type);
  44. if (it == NULL) return NULL;
  45. it->ob_itself = *itself;
  46. it->ob_owned = 1;
  47. return (PyObject *)it;
  48. }
  49. int AEDesc_Convert(PyObject *v, AEDesc *p_itself)
  50. {
  51. if (!AEDesc_Check(v))
  52. {
  53. PyErr_SetString(PyExc_TypeError, "AEDesc required");
  54. return 0;
  55. }
  56. *p_itself = ((AEDescObject *)v)->ob_itself;
  57. return 1;
  58. }
  59. static void AEDesc_dealloc(AEDescObject *self)
  60. {
  61. if (self->ob_owned) AEDisposeDesc(&self->ob_itself);
  62. self->ob_type->tp_free((PyObject *)self);
  63. }
  64. static PyObject *AEDesc_AECoerceDesc(AEDescObject *_self, PyObject *_args)
  65. {
  66. PyObject *_res = NULL;
  67. OSErr _err;
  68. DescType toType;
  69. AEDesc result;
  70. #ifndef AECoerceDesc
  71. PyMac_PRECHECK(AECoerceDesc);
  72. #endif
  73. if (!PyArg_ParseTuple(_args, "O&",
  74. PyMac_GetOSType, &toType))
  75. return NULL;
  76. _err = AECoerceDesc(&_self->ob_itself,
  77. toType,
  78. &result);
  79. if (_err != noErr) return PyMac_Error(_err);
  80. _res = Py_BuildValue("O&",
  81. AEDesc_New, &result);
  82. return _res;
  83. }
  84. static PyObject *AEDesc_AEDuplicateDesc(AEDescObject *_self, PyObject *_args)
  85. {
  86. PyObject *_res = NULL;
  87. OSErr _err;
  88. AEDesc result;
  89. #ifndef AEDuplicateDesc
  90. PyMac_PRECHECK(AEDuplicateDesc);
  91. #endif
  92. if (!PyArg_ParseTuple(_args, ""))
  93. return NULL;
  94. _err = AEDuplicateDesc(&_self->ob_itself,
  95. &result);
  96. if (_err != noErr) return PyMac_Error(_err);
  97. _res = Py_BuildValue("O&",
  98. AEDesc_New, &result);
  99. return _res;
  100. }
  101. static PyObject *AEDesc_AECountItems(AEDescObject *_self, PyObject *_args)
  102. {
  103. PyObject *_res = NULL;
  104. OSErr _err;
  105. long theCount;
  106. #ifndef AECountItems
  107. PyMac_PRECHECK(AECountItems);
  108. #endif
  109. if (!PyArg_ParseTuple(_args, ""))
  110. return NULL;
  111. _err = AECountItems(&_self->ob_itself,
  112. &theCount);
  113. if (_err != noErr) return PyMac_Error(_err);
  114. _res = Py_BuildValue("l",
  115. theCount);
  116. return _res;
  117. }
  118. static PyObject *AEDesc_AEPutPtr(AEDescObject *_self, PyObject *_args)
  119. {
  120. PyObject *_res = NULL;
  121. OSErr _err;
  122. long index;
  123. DescType typeCode;
  124. char *dataPtr__in__;
  125. long dataPtr__len__;
  126. int dataPtr__in_len__;
  127. #ifndef AEPutPtr
  128. PyMac_PRECHECK(AEPutPtr);
  129. #endif
  130. if (!PyArg_ParseTuple(_args, "lO&s#",
  131. &index,
  132. PyMac_GetOSType, &typeCode,
  133. &dataPtr__in__, &dataPtr__in_len__))
  134. return NULL;
  135. dataPtr__len__ = dataPtr__in_len__;
  136. _err = AEPutPtr(&_self->ob_itself,
  137. index,
  138. typeCode,
  139. dataPtr__in__, dataPtr__len__);
  140. if (_err != noErr) return PyMac_Error(_err);
  141. Py_INCREF(Py_None);
  142. _res = Py_None;
  143. return _res;
  144. }
  145. static PyObject *AEDesc_AEPutDesc(AEDescObject *_self, PyObject *_args)
  146. {
  147. PyObject *_res = NULL;
  148. OSErr _err;
  149. long index;
  150. AEDesc theAEDesc;
  151. #ifndef AEPutDesc
  152. PyMac_PRECHECK(AEPutDesc);
  153. #endif
  154. if (!PyArg_ParseTuple(_args, "lO&",
  155. &index,
  156. AEDesc_Convert, &theAEDesc))
  157. return NULL;
  158. _err = AEPutDesc(&_self->ob_itself,
  159. index,
  160. &theAEDesc);
  161. if (_err != noErr) return PyMac_Error(_err);
  162. Py_INCREF(Py_None);
  163. _res = Py_None;
  164. return _res;
  165. }
  166. static PyObject *AEDesc_AEGetNthPtr(AEDescObject *_self, PyObject *_args)
  167. {
  168. PyObject *_res = NULL;
  169. OSErr _err;
  170. long index;
  171. DescType desiredType;
  172. AEKeyword theAEKeyword;
  173. DescType typeCode;
  174. char *dataPtr__out__;
  175. long dataPtr__len__;
  176. int dataPtr__in_len__;
  177. #ifndef AEGetNthPtr
  178. PyMac_PRECHECK(AEGetNthPtr);
  179. #endif
  180. if (!PyArg_ParseTuple(_args, "lO&i",
  181. &index,
  182. PyMac_GetOSType, &desiredType,
  183. &dataPtr__in_len__))
  184. return NULL;
  185. if ((dataPtr__out__ = malloc(dataPtr__in_len__)) == NULL)
  186. {
  187. PyErr_NoMemory();
  188. goto dataPtr__error__;
  189. }
  190. dataPtr__len__ = dataPtr__in_len__;
  191. _err = AEGetNthPtr(&_self->ob_itself,
  192. index,
  193. desiredType,
  194. &theAEKeyword,
  195. &typeCode,
  196. dataPtr__out__, dataPtr__len__, &dataPtr__len__);
  197. if (_err != noErr) return PyMac_Error(_err);
  198. _res = Py_BuildValue("O&O&s#",
  199. PyMac_BuildOSType, theAEKeyword,
  200. PyMac_BuildOSType, typeCode,
  201. dataPtr__out__, (int)dataPtr__len__);
  202. free(dataPtr__out__);
  203. dataPtr__error__: ;
  204. return _res;
  205. }
  206. static PyObject *AEDesc_AEGetNthDesc(AEDescObject *_self, PyObject *_args)
  207. {
  208. PyObject *_res = NULL;
  209. OSErr _err;
  210. long index;
  211. DescType desiredType;
  212. AEKeyword theAEKeyword;
  213. AEDesc result;
  214. #ifndef AEGetNthDesc
  215. PyMac_PRECHECK(AEGetNthDesc);
  216. #endif
  217. if (!PyArg_ParseTuple(_args, "lO&",
  218. &index,
  219. PyMac_GetOSType, &desiredType))
  220. return NULL;
  221. _err = AEGetNthDesc(&_self->ob_itself,
  222. index,
  223. desiredType,
  224. &theAEKeyword,
  225. &result);
  226. if (_err != noErr) return PyMac_Error(_err);
  227. _res = Py_BuildValue("O&O&",
  228. PyMac_BuildOSType, theAEKeyword,
  229. AEDesc_New, &result);
  230. return _res;
  231. }
  232. static PyObject *AEDesc_AESizeOfNthItem(AEDescObject *_self, PyObject *_args)
  233. {
  234. PyObject *_res = NULL;
  235. OSErr _err;
  236. long index;
  237. DescType typeCode;
  238. Size dataSize;
  239. #ifndef AESizeOfNthItem
  240. PyMac_PRECHECK(AESizeOfNthItem);
  241. #endif
  242. if (!PyArg_ParseTuple(_args, "l",
  243. &index))
  244. return NULL;
  245. _err = AESizeOfNthItem(&_self->ob_itself,
  246. index,
  247. &typeCode,
  248. &dataSize);
  249. if (_err != noErr) return PyMac_Error(_err);
  250. _res = Py_BuildValue("O&l",
  251. PyMac_BuildOSType, typeCode,
  252. dataSize);
  253. return _res;
  254. }
  255. static PyObject *AEDesc_AEDeleteItem(AEDescObject *_self, PyObject *_args)
  256. {
  257. PyObject *_res = NULL;
  258. OSErr _err;
  259. long index;
  260. #ifndef AEDeleteItem
  261. PyMac_PRECHECK(AEDeleteItem);
  262. #endif
  263. if (!PyArg_ParseTuple(_args, "l",
  264. &index))
  265. return NULL;
  266. _err = AEDeleteItem(&_self->ob_itself,
  267. index);
  268. if (_err != noErr) return PyMac_Error(_err);
  269. Py_INCREF(Py_None);
  270. _res = Py_None;
  271. return _res;
  272. }
  273. static PyObject *AEDesc_AEPutParamPtr(AEDescObject *_self, PyObject *_args)
  274. {
  275. PyObject *_res = NULL;
  276. OSErr _err;
  277. AEKeyword theAEKeyword;
  278. DescType typeCode;
  279. char *dataPtr__in__;
  280. long dataPtr__len__;
  281. int dataPtr__in_len__;
  282. #ifndef AEPutParamPtr
  283. PyMac_PRECHECK(AEPutParamPtr);
  284. #endif
  285. if (!PyArg_ParseTuple(_args, "O&O&s#",
  286. PyMac_GetOSType, &theAEKeyword,
  287. PyMac_GetOSType, &typeCode,
  288. &dataPtr__in__, &dataPtr__in_len__))
  289. return NULL;
  290. dataPtr__len__ = dataPtr__in_len__;
  291. _err = AEPutParamPtr(&_self->ob_itself,
  292. theAEKeyword,
  293. typeCode,
  294. dataPtr__in__, dataPtr__len__);
  295. if (_err != noErr) return PyMac_Error(_err);
  296. Py_INCREF(Py_None);
  297. _res = Py_None;
  298. return _res;
  299. }
  300. static PyObject *AEDesc_AEPutParamDesc(AEDescObject *_self, PyObject *_args)
  301. {
  302. PyObject *_res = NULL;
  303. OSErr _err;
  304. AEKeyword theAEKeyword;
  305. AEDesc theAEDesc;
  306. #ifndef AEPutParamDesc
  307. PyMac_PRECHECK(AEPutParamDesc);
  308. #endif
  309. if (!PyArg_ParseTuple(_args, "O&O&",
  310. PyMac_GetOSType, &theAEKeyword,
  311. AEDesc_Convert, &theAEDesc))
  312. return NULL;
  313. _err = AEPutParamDesc(&_self->ob_itself,
  314. theAEKeyword,
  315. &theAEDesc);
  316. if (_err != noErr) return PyMac_Error(_err);
  317. Py_INCREF(Py_None);
  318. _res = Py_None;
  319. return _res;
  320. }
  321. static PyObject *AEDesc_AEGetParamPtr(AEDescObject *_self, PyObject *_args)
  322. {
  323. PyObject *_res = NULL;
  324. OSErr _err;
  325. AEKeyword theAEKeyword;
  326. DescType desiredType;
  327. DescType typeCode;
  328. char *dataPtr__out__;
  329. long dataPtr__len__;
  330. int dataPtr__in_len__;
  331. #ifndef AEGetParamPtr
  332. PyMac_PRECHECK(AEGetParamPtr);
  333. #endif
  334. if (!PyArg_ParseTuple(_args, "O&O&i",
  335. PyMac_GetOSType, &theAEKeyword,
  336. PyMac_GetOSType, &desiredType,
  337. &dataPtr__in_len__))
  338. return NULL;
  339. if ((dataPtr__out__ = malloc(dataPtr__in_len__)) == NULL)
  340. {
  341. PyErr_NoMemory();
  342. goto dataPtr__error__;
  343. }
  344. dataPtr__len__ = dataPtr__in_len__;
  345. _err = AEGetParamPtr(&_self->ob_itself,
  346. theAEKeyword,
  347. desiredType,
  348. &typeCode,
  349. dataPtr__out__, dataPtr__len__, &dataPtr__len__);
  350. if (_err != noErr) return PyMac_Error(_err);
  351. _res = Py_BuildValue("O&s#",
  352. PyMac_BuildOSType, typeCode,
  353. dataPtr__out__, (int)dataPtr__len__);
  354. free(dataPtr__out__);
  355. dataPtr__error__: ;
  356. return _res;
  357. }
  358. static PyObject *AEDesc_AEGetParamDesc(AEDescObject *_self, PyObject *_args)
  359. {
  360. PyObject *_res = NULL;
  361. OSErr _err;
  362. AEKeyword theAEKeyword;
  363. DescType desiredType;
  364. AEDesc result;
  365. #ifndef AEGetParamDesc
  366. PyMac_PRECHECK(AEGetParamDesc);
  367. #endif
  368. if (!PyArg_ParseTuple(_args, "O&O&",
  369. PyMac_GetOSType, &theAEKeyword,
  370. PyMac_GetOSType, &desiredType))
  371. return NULL;
  372. _err = AEGetParamDesc(&_self->ob_itself,
  373. theAEKeyword,
  374. desiredType,
  375. &result);
  376. if (_err != noErr) return PyMac_Error(_err);
  377. _res = Py_BuildValue("O&",
  378. AEDesc_New, &result);
  379. return _res;
  380. }
  381. static PyObject *AEDesc_AESizeOfParam(AEDescObject *_self, PyObject *_args)
  382. {
  383. PyObject *_res = NULL;
  384. OSErr _err;
  385. AEKeyword theAEKeyword;
  386. DescType typeCode;
  387. Size dataSize;
  388. #ifndef AESizeOfParam
  389. PyMac_PRECHECK(AESizeOfParam);
  390. #endif
  391. if (!PyArg_ParseTuple(_args, "O&",
  392. PyMac_GetOSType, &theAEKeyword))
  393. return NULL;
  394. _err = AESizeOfParam(&_self->ob_itself,
  395. theAEKeyword,
  396. &typeCode,
  397. &dataSize);
  398. if (_err != noErr) return PyMac_Error(_err);
  399. _res = Py_BuildValue("O&l",
  400. PyMac_BuildOSType, typeCode,
  401. dataSize);
  402. return _res;
  403. }
  404. static PyObject *AEDesc_AEDeleteParam(AEDescObject *_self, PyObject *_args)
  405. {
  406. PyObject *_res = NULL;
  407. OSErr _err;
  408. AEKeyword theAEKeyword;
  409. #ifndef AEDeleteParam
  410. PyMac_PRECHECK(AEDeleteParam);
  411. #endif
  412. if (!PyArg_ParseTuple(_args, "O&",
  413. PyMac_GetOSType, &theAEKeyword))
  414. return NULL;
  415. _err = AEDeleteParam(&_self->ob_itself,
  416. theAEKeyword);
  417. if (_err != noErr) return PyMac_Error(_err);
  418. Py_INCREF(Py_None);
  419. _res = Py_None;
  420. return _res;
  421. }
  422. static PyObject *AEDesc_AEGetAttributePtr(AEDescObject *_self, PyObject *_args)
  423. {
  424. PyObject *_res = NULL;
  425. OSErr _err;
  426. AEKeyword theAEKeyword;
  427. DescType desiredType;
  428. DescType typeCode;
  429. char *dataPtr__out__;
  430. long dataPtr__len__;
  431. int dataPtr__in_len__;
  432. #ifndef AEGetAttributePtr
  433. PyMac_PRECHECK(AEGetAttributePtr);
  434. #endif
  435. if (!PyArg_ParseTuple(_args, "O&O&i",
  436. PyMac_GetOSType, &theAEKeyword,
  437. PyMac_GetOSType, &desiredType,
  438. &dataPtr__in_len__))
  439. return NULL;
  440. if ((dataPtr__out__ = malloc(dataPtr__in_len__)) == NULL)
  441. {
  442. PyErr_NoMemory();
  443. goto dataPtr__error__;
  444. }
  445. dataPtr__len__ = dataPtr__in_len__;
  446. _err = AEGetAttributePtr(&_self->ob_itself,
  447. theAEKeyword,
  448. desiredType,
  449. &typeCode,
  450. dataPtr__out__, dataPtr__len__, &dataPtr__len__);
  451. if (_err != noErr) return PyMac_Error(_err);
  452. _res = Py_BuildValue("O&s#",
  453. PyMac_BuildOSType, typeCode,
  454. dataPtr__out__, (int)dataPtr__len__);
  455. free(dataPtr__out__);
  456. dataPtr__error__: ;
  457. return _res;
  458. }
  459. static PyObject *AEDesc_AEGetAttributeDesc(AEDescObject *_self, PyObject *_args)
  460. {
  461. PyObject *_res = NULL;
  462. OSErr _err;
  463. AEKeyword theAEKeyword;
  464. DescType desiredType;
  465. AEDesc result;
  466. #ifndef AEGetAttributeDesc
  467. PyMac_PRECHECK(AEGetAttributeDesc);
  468. #endif
  469. if (!PyArg_ParseTuple(_args, "O&O&",
  470. PyMac_GetOSType, &theAEKeyword,
  471. PyMac_GetOSType, &desiredType))
  472. return NULL;
  473. _err = AEGetAttributeDesc(&_self->ob_itself,
  474. theAEKeyword,
  475. desiredType,
  476. &result);
  477. if (_err != noErr) return PyMac_Error(_err);
  478. _res = Py_BuildValue("O&",
  479. AEDesc_New, &result);
  480. return _res;
  481. }
  482. static PyObject *AEDesc_AESizeOfAttribute(AEDescObject *_self, PyObject *_args)
  483. {
  484. PyObject *_res = NULL;
  485. OSErr _err;
  486. AEKeyword theAEKeyword;
  487. DescType typeCode;
  488. Size dataSize;
  489. #ifndef AESizeOfAttribute
  490. PyMac_PRECHECK(AESizeOfAttribute);
  491. #endif
  492. if (!PyArg_ParseTuple(_args, "O&",
  493. PyMac_GetOSType, &theAEKeyword))
  494. return NULL;
  495. _err = AESizeOfAttribute(&_self->ob_itself,
  496. theAEKeyword,
  497. &typeCode,
  498. &dataSize);
  499. if (_err != noErr) return PyMac_Error(_err);
  500. _res = Py_BuildValue("O&l",
  501. PyMac_BuildOSType, typeCode,
  502. dataSize);
  503. return _res;
  504. }
  505. static PyObject *AEDesc_AEPutAttributePtr(AEDescObject *_self, PyObject *_args)
  506. {
  507. PyObject *_res = NULL;
  508. OSErr _err;
  509. AEKeyword theAEKeyword;
  510. DescType typeCode;
  511. char *dataPtr__in__;
  512. long dataPtr__len__;
  513. int dataPtr__in_len__;
  514. #ifndef AEPutAttributePtr
  515. PyMac_PRECHECK(AEPutAttributePtr);
  516. #endif
  517. if (!PyArg_ParseTuple(_args, "O&O&s#",
  518. PyMac_GetOSType, &theAEKeyword,
  519. PyMac_GetOSType, &typeCode,
  520. &dataPtr__in__, &dataPtr__in_len__))
  521. return NULL;
  522. dataPtr__len__ = dataPtr__in_len__;
  523. _err = AEPutAttributePtr(&_self->ob_itself,
  524. theAEKeyword,
  525. typeCode,
  526. dataPtr__in__, dataPtr__len__);
  527. if (_err != noErr) return PyMac_Error(_err);
  528. Py_INCREF(Py_None);
  529. _res = Py_None;
  530. return _res;
  531. }
  532. static PyObject *AEDesc_AEPutAttributeDesc(AEDescObject *_self, PyObject *_args)
  533. {
  534. PyObject *_res = NULL;
  535. OSErr _err;
  536. AEKeyword theAEKeyword;
  537. AEDesc theAEDesc;
  538. #ifndef AEPutAttributeDesc
  539. PyMac_PRECHECK(AEPutAttributeDesc);
  540. #endif
  541. if (!PyArg_ParseTuple(_args, "O&O&",
  542. PyMac_GetOSType, &theAEKeyword,
  543. AEDesc_Convert, &theAEDesc))
  544. return NULL;
  545. _err = AEPutAttributeDesc(&_self->ob_itself,
  546. theAEKeyword,
  547. &theAEDesc);
  548. if (_err != noErr) return PyMac_Error(_err);
  549. Py_INCREF(Py_None);
  550. _res = Py_None;
  551. return _res;
  552. }
  553. static PyObject *AEDesc_AEGetDescDataSize(AEDescObject *_self, PyObject *_args)
  554. {
  555. PyObject *_res = NULL;
  556. Size _rv;
  557. #ifndef AEGetDescDataSize
  558. PyMac_PRECHECK(AEGetDescDataSize);
  559. #endif
  560. if (!PyArg_ParseTuple(_args, ""))
  561. return NULL;
  562. _rv = AEGetDescDataSize(&_self->ob_itself);
  563. _res = Py_BuildValue("l",
  564. _rv);
  565. return _res;
  566. }
  567. static PyObject *AEDesc_AESend(AEDescObject *_self, PyObject *_args)
  568. {
  569. PyObject *_res = NULL;
  570. OSErr _err;
  571. AppleEvent reply;
  572. AESendMode sendMode;
  573. AESendPriority sendPriority;
  574. long timeOutInTicks;
  575. #ifndef AESend
  576. PyMac_PRECHECK(AESend);
  577. #endif
  578. if (!PyArg_ParseTuple(_args, "lhl",
  579. &sendMode,
  580. &sendPriority,
  581. &timeOutInTicks))
  582. return NULL;
  583. _err = AESend(&_self->ob_itself,
  584. &reply,
  585. sendMode,
  586. sendPriority,
  587. timeOutInTicks,
  588. upp_AEIdleProc,
  589. (AEFilterUPP)0);
  590. if (_err != noErr) return PyMac_Error(_err);
  591. _res = Py_BuildValue("O&",
  592. AEDesc_New, &reply);
  593. return _res;
  594. }
  595. static PyObject *AEDesc_AEResetTimer(AEDescObject *_self, PyObject *_args)
  596. {
  597. PyObject *_res = NULL;
  598. OSErr _err;
  599. #ifndef AEResetTimer
  600. PyMac_PRECHECK(AEResetTimer);
  601. #endif
  602. if (!PyArg_ParseTuple(_args, ""))
  603. return NULL;
  604. _err = AEResetTimer(&_self->ob_itself);
  605. if (_err != noErr) return PyMac_Error(_err);
  606. Py_INCREF(Py_None);
  607. _res = Py_None;
  608. return _res;
  609. }
  610. static PyObject *AEDesc_AESuspendTheCurrentEvent(AEDescObject *_self, PyObject *_args)
  611. {
  612. PyObject *_res = NULL;
  613. OSErr _err;
  614. #ifndef AESuspendTheCurrentEvent
  615. PyMac_PRECHECK(AESuspendTheCurrentEvent);
  616. #endif
  617. if (!PyArg_ParseTuple(_args, ""))
  618. return NULL;
  619. _err = AESuspendTheCurrentEvent(&_self->ob_itself);
  620. if (_err != noErr) return PyMac_Error(_err);
  621. Py_INCREF(Py_None);
  622. _res = Py_None;
  623. return _res;
  624. }
  625. static PyObject *AEDesc_AEResumeTheCurrentEvent(AEDescObject *_self, PyObject *_args)
  626. {
  627. PyObject *_res = NULL;
  628. OSErr _err;
  629. AppleEvent reply;
  630. AEEventHandlerUPP dispatcher__proc__ = upp_GenericEventHandler;
  631. PyObject *dispatcher;
  632. #ifndef AEResumeTheCurrentEvent
  633. PyMac_PRECHECK(AEResumeTheCurrentEvent);
  634. #endif
  635. if (!PyArg_ParseTuple(_args, "O&O",
  636. AEDesc_Convert, &reply,
  637. &dispatcher))
  638. return NULL;
  639. _err = AEResumeTheCurrentEvent(&_self->ob_itself,
  640. &reply,
  641. dispatcher__proc__,
  642. (SRefCon)dispatcher);
  643. if (_err != noErr) return PyMac_Error(_err);
  644. Py_INCREF(Py_None);
  645. _res = Py_None;
  646. Py_INCREF(dispatcher); /* XXX leak, but needed */
  647. return _res;
  648. }
  649. static PyObject *AEDesc_AEGetTheCurrentEvent(AEDescObject *_self, PyObject *_args)
  650. {
  651. PyObject *_res = NULL;
  652. OSErr _err;
  653. #ifndef AEGetTheCurrentEvent
  654. PyMac_PRECHECK(AEGetTheCurrentEvent);
  655. #endif
  656. if (!PyArg_ParseTuple(_args, ""))
  657. return NULL;
  658. _err = AEGetTheCurrentEvent(&_self->ob_itself);
  659. if (_err != noErr) return PyMac_Error(_err);
  660. Py_INCREF(Py_None);
  661. _res = Py_None;
  662. return _res;
  663. }
  664. static PyObject *AEDesc_AESetTheCurrentEvent(AEDescObject *_self, PyObject *_args)
  665. {
  666. PyObject *_res = NULL;
  667. OSErr _err;
  668. #ifndef AESetTheCurrentEvent
  669. PyMac_PRECHECK(AESetTheCurrentEvent);
  670. #endif
  671. if (!PyArg_ParseTuple(_args, ""))
  672. return NULL;
  673. _err = AESetTheCurrentEvent(&_self->ob_itself);
  674. if (_err != noErr) return PyMac_Error(_err);
  675. Py_INCREF(Py_None);
  676. _res = Py_None;
  677. return _res;
  678. }
  679. static PyObject *AEDesc_AEResolve(AEDescObject *_self, PyObject *_args)
  680. {
  681. PyObject *_res = NULL;
  682. OSErr _err;
  683. short callbackFlags;
  684. AEDesc theToken;
  685. #ifndef AEResolve
  686. PyMac_PRECHECK(AEResolve);
  687. #endif
  688. if (!PyArg_ParseTuple(_args, "h",
  689. &callbackFlags))
  690. return NULL;
  691. _err = AEResolve(&_self->ob_itself,
  692. callbackFlags,
  693. &theToken);
  694. if (_err != noErr) return PyMac_Error(_err);
  695. _res = Py_BuildValue("O&",
  696. AEDesc_New, &theToken);
  697. return _res;
  698. }
  699. static PyObject *AEDesc_AutoDispose(AEDescObject *_self, PyObject *_args)
  700. {
  701. PyObject *_res = NULL;
  702. int onoff, old;
  703. if (!PyArg_ParseTuple(_args, "i", &onoff))
  704. return NULL;
  705. old = _self->ob_owned;
  706. _self->ob_owned = onoff;
  707. _res = Py_BuildValue("i", old);
  708. return _res;
  709. }
  710. static PyMethodDef AEDesc_methods[] = {
  711. {"AECoerceDesc", (PyCFunction)AEDesc_AECoerceDesc, 1,
  712. PyDoc_STR("(DescType toType) -> (AEDesc result)")},
  713. {"AEDuplicateDesc", (PyCFunction)AEDesc_AEDuplicateDesc, 1,
  714. PyDoc_STR("() -> (AEDesc result)")},
  715. {"AECountItems", (PyCFunction)AEDesc_AECountItems, 1,
  716. PyDoc_STR("() -> (long theCount)")},
  717. {"AEPutPtr", (PyCFunction)AEDesc_AEPutPtr, 1,
  718. PyDoc_STR("(long index, DescType typeCode, Buffer dataPtr) -> None")},
  719. {"AEPutDesc", (PyCFunction)AEDesc_AEPutDesc, 1,
  720. PyDoc_STR("(long index, AEDesc theAEDesc) -> None")},
  721. {"AEGetNthPtr", (PyCFunction)AEDesc_AEGetNthPtr, 1,
  722. PyDoc_STR("(long index, DescType desiredType, Buffer dataPtr) -> (AEKeyword theAEKeyword, DescType typeCode, Buffer dataPtr)")},
  723. {"AEGetNthDesc", (PyCFunction)AEDesc_AEGetNthDesc, 1,
  724. PyDoc_STR("(long index, DescType desiredType) -> (AEKeyword theAEKeyword, AEDesc result)")},
  725. {"AESizeOfNthItem", (PyCFunction)AEDesc_AESizeOfNthItem, 1,
  726. PyDoc_STR("(long index) -> (DescType typeCode, Size dataSize)")},
  727. {"AEDeleteItem", (PyCFunction)AEDesc_AEDeleteItem, 1,
  728. PyDoc_STR("(long index) -> None")},
  729. {"AEPutParamPtr", (PyCFunction)AEDesc_AEPutParamPtr, 1,
  730. PyDoc_STR("(AEKeyword theAEKeyword, DescType typeCode, Buffer dataPtr) -> None")},
  731. {"AEPutParamDesc", (PyCFunction)AEDesc_AEPutParamDesc, 1,
  732. PyDoc_STR("(AEKeyword theAEKeyword, AEDesc theAEDesc) -> None")},
  733. {"AEGetParamPtr", (PyCFunction)AEDesc_AEGetParamPtr, 1,
  734. PyDoc_STR("(AEKeyword theAEKeyword, DescType desiredType, Buffer dataPtr) -> (DescType typeCode, Buffer dataPtr)")},
  735. {"AEGetParamDesc", (PyCFunction)AEDesc_AEGetParamDesc, 1,
  736. PyDoc_STR("(AEKeyword theAEKeyword, DescType desiredType) -> (AEDesc result)")},
  737. {"AESizeOfParam", (PyCFunction)AEDesc_AESizeOfParam, 1,
  738. PyDoc_STR("(AEKeyword theAEKeyword) -> (DescType typeCode, Size dataSize)")},
  739. {"AEDeleteParam", (PyCFunction)AEDesc_AEDeleteParam, 1,
  740. PyDoc_STR("(AEKeyword theAEKeyword) -> None")},
  741. {"AEGetAttributePtr", (PyCFunction)AEDesc_AEGetAttributePtr, 1,
  742. PyDoc_STR("(AEKeyword theAEKeyword, DescType desiredType, Buffer dataPtr) -> (DescType typeCode, Buffer dataPtr)")},
  743. {"AEGetAttributeDesc", (PyCFunction)AEDesc_AEGetAttributeDesc, 1,
  744. PyDoc_STR("(AEKeyword theAEKeyword, DescType desiredType) -> (AEDesc result)")},
  745. {"AESizeOfAttribute", (PyCFunction)AEDesc_AESizeOfAttribute, 1,
  746. PyDoc_STR("(AEKeyword theAEKeyword) -> (DescType typeCode, Size dataSize)")},
  747. {"AEPutAttributePtr", (PyCFunction)AEDesc_AEPutAttributePtr, 1,
  748. PyDoc_STR("(AEKeyword theAEKeyword, DescType typeCode, Buffer dataPtr) -> None")},
  749. {"AEPutAttributeDesc", (PyCFunction)AEDesc_AEPutAttributeDesc, 1,
  750. PyDoc_STR("(AEKeyword theAEKeyword, AEDesc theAEDesc) -> None")},
  751. {"AEGetDescDataSize", (PyCFunction)AEDesc_AEGetDescDataSize, 1,
  752. PyDoc_STR("() -> (Size _rv)")},
  753. {"AESend", (PyCFunction)AEDesc_AESend, 1,
  754. PyDoc_STR("(AESendMode sendMode, AESendPriority sendPriority, long timeOutInTicks) -> (AppleEvent reply)")},
  755. {"AEResetTimer", (PyCFunction)AEDesc_AEResetTimer, 1,
  756. PyDoc_STR("() -> None")},
  757. {"AESuspendTheCurrentEvent", (PyCFunction)AEDesc_AESuspendTheCurrentEvent, 1,
  758. PyDoc_STR("() -> None")},
  759. {"AEResumeTheCurrentEvent", (PyCFunction)AEDesc_AEResumeTheCurrentEvent, 1,
  760. PyDoc_STR("(AppleEvent reply, EventHandler dispatcher) -> None")},
  761. {"AEGetTheCurrentEvent", (PyCFunction)AEDesc_AEGetTheCurrentEvent, 1,
  762. PyDoc_STR("() -> None")},
  763. {"AESetTheCurrentEvent", (PyCFunction)AEDesc_AESetTheCurrentEvent, 1,
  764. PyDoc_STR("() -> None")},
  765. {"AEResolve", (PyCFunction)AEDesc_AEResolve, 1,
  766. PyDoc_STR("(short callbackFlags) -> (AEDesc theToken)")},
  767. {"AutoDispose", (PyCFunction)AEDesc_AutoDispose, 1,
  768. PyDoc_STR("(int)->int. Automatically AEDisposeDesc the object on Python object cleanup")},
  769. {NULL, NULL, 0}
  770. };
  771. static PyObject *AEDesc_get_type(AEDescObject *self, void *closure)
  772. {
  773. return PyMac_BuildOSType(self->ob_itself.descriptorType);
  774. }
  775. #define AEDesc_set_type NULL
  776. static PyObject *AEDesc_get_data(AEDescObject *self, void *closure)
  777. {
  778. PyObject *res;
  779. Size size;
  780. char *ptr;
  781. OSErr err;
  782. size = AEGetDescDataSize(&self->ob_itself);
  783. if ( (res = PyString_FromStringAndSize(NULL, size)) == NULL )
  784. return NULL;
  785. if ( (ptr = PyString_AsString(res)) == NULL )
  786. return NULL;
  787. if ( (err=AEGetDescData(&self->ob_itself, ptr, size)) < 0 )
  788. return PyMac_Error(err);
  789. return res;
  790. }
  791. #define AEDesc_set_data NULL
  792. static PyGetSetDef AEDesc_getsetlist[] = {
  793. {"type", (getter)AEDesc_get_type, (setter)AEDesc_set_type, "Type of this AEDesc"},
  794. {"data", (getter)AEDesc_get_data, (setter)AEDesc_set_data, "The raw data in this AEDesc"},
  795. {NULL, NULL, NULL, NULL},
  796. };
  797. #define AEDesc_compare NULL
  798. #define AEDesc_repr NULL
  799. #define AEDesc_hash NULL
  800. #define AEDesc_tp_init 0
  801. #define AEDesc_tp_alloc PyType_GenericAlloc
  802. static PyObject *AEDesc_tp_new(PyTypeObject *type, PyObject *_args, PyObject *_kwds)
  803. {
  804. PyObject *_self;
  805. AEDesc itself;
  806. char *kw[] = {"itself", 0};
  807. if (!PyArg_ParseTupleAndKeywords(_args, _kwds, "O&", kw, AEDesc_Convert, &itself)) return NULL;
  808. if ((_self = type->tp_alloc(type, 0)) == NULL) return NULL;
  809. ((AEDescObject *)_self)->ob_itself = itself;
  810. return _self;
  811. }
  812. #define AEDesc_tp_free PyObject_Del
  813. PyTypeObject AEDesc_Type = {
  814. PyObject_HEAD_INIT(NULL)
  815. 0, /*ob_size*/
  816. "_AE.AEDesc", /*tp_name*/
  817. sizeof(AEDescObject), /*tp_basicsize*/
  818. 0, /*tp_itemsize*/
  819. /* methods */
  820. (destructor) AEDesc_dealloc, /*tp_dealloc*/
  821. 0, /*tp_print*/
  822. (getattrfunc)0, /*tp_getattr*/
  823. (setattrfunc)0, /*tp_setattr*/
  824. (cmpfunc) AEDesc_compare, /*tp_compare*/
  825. (reprfunc) AEDesc_repr, /*tp_repr*/
  826. (PyNumberMethods *)0, /* tp_as_number */
  827. (PySequenceMethods *)0, /* tp_as_sequence */
  828. (PyMappingMethods *)0, /* tp_as_mapping */
  829. (hashfunc) AEDesc_hash, /*tp_hash*/
  830. 0, /*tp_call*/
  831. 0, /*tp_str*/
  832. PyObject_GenericGetAttr, /*tp_getattro*/
  833. PyObject_GenericSetAttr, /*tp_setattro */
  834. 0, /*tp_as_buffer*/
  835. Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
  836. 0, /*tp_doc*/
  837. 0, /*tp_traverse*/
  838. 0, /*tp_clear*/
  839. 0, /*tp_richcompare*/
  840. 0, /*tp_weaklistoffset*/
  841. 0, /*tp_iter*/
  842. 0, /*tp_iternext*/
  843. AEDesc_methods, /* tp_methods */
  844. 0, /*tp_members*/
  845. AEDesc_getsetlist, /*tp_getset*/
  846. 0, /*tp_base*/
  847. 0, /*tp_dict*/
  848. 0, /*tp_descr_get*/
  849. 0, /*tp_descr_set*/
  850. 0, /*tp_dictoffset*/
  851. AEDesc_tp_init, /* tp_init */
  852. AEDesc_tp_alloc, /* tp_alloc */
  853. AEDesc_tp_new, /* tp_new */
  854. AEDesc_tp_free, /* tp_free */
  855. };
  856. /* --------------------- End object type AEDesc --------------------- */
  857. static PyObject *AE_AECoercePtr(PyObject *_self, PyObject *_args)
  858. {
  859. PyObject *_res = NULL;
  860. OSErr _err;
  861. DescType typeCode;
  862. char *dataPtr__in__;
  863. long dataPtr__len__;
  864. int dataPtr__in_len__;
  865. DescType toType;
  866. AEDesc result;
  867. #ifndef AECoercePtr
  868. PyMac_PRECHECK(AECoercePtr);
  869. #endif
  870. if (!PyArg_ParseTuple(_args, "O&s#O&",
  871. PyMac_GetOSType, &typeCode,
  872. &dataPtr__in__, &dataPtr__in_len__,
  873. PyMac_GetOSType, &toType))
  874. return NULL;
  875. dataPtr__len__ = dataPtr__in_len__;
  876. _err = AECoercePtr(typeCode,
  877. dataPtr__in__, dataPtr__len__,
  878. toType,
  879. &result);
  880. if (_err != noErr) return PyMac_Error(_err);
  881. _res = Py_BuildValue("O&",
  882. AEDesc_New, &result);
  883. return _res;
  884. }
  885. static PyObject *AE_AECreateDesc(PyObject *_self, PyObject *_args)
  886. {
  887. PyObject *_res = NULL;
  888. OSErr _err;
  889. DescType typeCode;
  890. char *dataPtr__in__;
  891. long dataPtr__len__;
  892. int dataPtr__in_len__;
  893. AEDesc result;
  894. #ifndef AECreateDesc
  895. PyMac_PRECHECK(AECreateDesc);
  896. #endif
  897. if (!PyArg_ParseTuple(_args, "O&s#",
  898. PyMac_GetOSType, &typeCode,
  899. &dataPtr__in__, &dataPtr__in_len__))
  900. return NULL;
  901. dataPtr__len__ = dataPtr__in_len__;
  902. _err = AECreateDesc(typeCode,
  903. dataPtr__in__, dataPtr__len__,
  904. &result);
  905. if (_err != noErr) return PyMac_Error(_err);
  906. _res = Py_BuildValue("O&",
  907. AEDesc_New, &result);
  908. return _res;
  909. }
  910. static PyObject *AE_AECreateList(PyObject *_self, PyObject *_args)
  911. {
  912. PyObject *_res = NULL;
  913. OSErr _err;
  914. char *factoringPtr__in__;
  915. long factoringPtr__len__;
  916. int factoringPtr__in_len__;
  917. Boolean isRecord;
  918. AEDescList resultList;
  919. #ifndef AECreateList
  920. PyMac_PRECHECK(AECreateList);
  921. #endif
  922. if (!PyArg_ParseTuple(_args, "s#b",
  923. &factoringPtr__in__, &factoringPtr__in_len__,
  924. &isRecord))
  925. return NULL;
  926. factoringPtr__len__ = factoringPtr__in_len__;
  927. _err = AECreateList(factoringPtr__in__, factoringPtr__len__,
  928. isRecord,
  929. &resultList);
  930. if (_err != noErr) return PyMac_Error(_err);
  931. _res = Py_BuildValue("O&",
  932. AEDesc_New, &resultList);
  933. return _res;
  934. }
  935. static PyObject *AE_AECreateAppleEvent(PyObject *_self, PyObject *_args)
  936. {
  937. PyObject *_res = NULL;
  938. OSErr _err;
  939. AEEventClass theAEEventClass;
  940. AEEventID theAEEventID;
  941. AEAddressDesc target;
  942. AEReturnID returnID;
  943. AETransactionID transactionID;
  944. AppleEvent result;
  945. #ifndef AECreateAppleEvent
  946. PyMac_PRECHECK(AECreateAppleEvent);
  947. #endif
  948. if (!PyArg_ParseTuple(_args, "O&O&O&hl",
  949. PyMac_GetOSType, &theAEEventClass,
  950. PyMac_GetOSType, &theAEEventID,
  951. AEDesc_Convert, &target,
  952. &returnID,
  953. &transactionID))
  954. return NULL;
  955. _err = AECreateAppleEvent(theAEEventClass,
  956. theAEEventID,
  957. &target,
  958. returnID,
  959. transactionID,
  960. &result);
  961. if (_err != noErr) return PyMac_Error(_err);
  962. _res = Py_BuildValue("O&",
  963. AEDesc_New, &result);
  964. return _res;
  965. }
  966. static PyObject *AE_AEReplaceDescData(PyObject *_self, PyObject *_args)
  967. {
  968. PyObject *_res = NULL;
  969. OSErr _err;
  970. DescType typeCode;
  971. char *dataPtr__in__;
  972. long dataPtr__len__;
  973. int dataPtr__in_len__;
  974. AEDesc theAEDesc;
  975. #ifndef AEReplaceDescData
  976. PyMac_PRECHECK(AEReplaceDescData);
  977. #endif
  978. if (!PyArg_ParseTuple(_args, "O&s#",
  979. PyMac_GetOSType, &typeCode,
  980. &dataPtr__in__, &dataPtr__in_len__))
  981. return NULL;
  982. dataPtr__len__ = dataPtr__in_len__;
  983. _err = AEReplaceDescData(typeCode,
  984. dataPtr__in__, dataPtr__len__,
  985. &theAEDesc);
  986. if (_err != noErr) return PyMac_Error(_err);
  987. _res = Py_BuildValue("O&",
  988. AEDesc_New, &theAEDesc);
  989. return _res;
  990. }
  991. static PyObject *AE_AEProcessAppleEvent(PyObject *_self, PyObject *_args)
  992. {
  993. PyObject *_res = NULL;
  994. OSErr _err;
  995. EventRecord theEventRecord;
  996. #ifndef AEProcessAppleEvent
  997. PyMac_PRECHECK(AEProcessAppleEvent);
  998. #endif
  999. if (!PyArg_ParseTuple(_args, "O&",
  1000. PyMac_GetEventRecord, &theEventRecord))
  1001. return NULL;
  1002. _err = AEProcessAppleEvent(&theEventRecord);
  1003. if (_err != noErr) return PyMac_Error(_err);
  1004. Py_INCREF(Py_None);
  1005. _res = Py_None;
  1006. return _res;
  1007. }
  1008. static PyObject *AE_AEGetInteractionAllowed(PyObject *_self, PyObject *_args)
  1009. {
  1010. PyObject *_res = NULL;
  1011. OSErr _err;
  1012. AEInteractAllowed level;
  1013. #ifndef AEGetInteractionAllowed
  1014. PyMac_PRECHECK(AEGetInteractionAllowed);
  1015. #endif
  1016. if (!PyArg_ParseTuple(_args, ""))
  1017. return NULL;
  1018. _err = AEGetInteractionAllowed(&level);
  1019. if (_err != noErr) return PyMac_Error(_err);
  1020. _res = Py_BuildValue("b",
  1021. level);
  1022. return _res;
  1023. }
  1024. static PyObject *AE_AESetInteractionAllowed(PyObject *_self, PyObject *_args)
  1025. {
  1026. PyObject *_res = NULL;
  1027. OSErr _err;
  1028. AEInteractAllowed level;
  1029. #ifndef AESetInteractionAllowed
  1030. PyMac_PRECHECK(AESetInteractionAllowed);
  1031. #endif
  1032. if (!PyArg_ParseTuple(_args, "b",
  1033. &level))
  1034. return NULL;
  1035. _err = AESetInteractionAllowed(level);
  1036. if (_err != noErr) return PyMac_Error(_err);
  1037. Py_INCREF(Py_None);
  1038. _res = Py_None;
  1039. return _res;
  1040. }
  1041. static PyObject *AE_AEInteractWithUser(PyObject *_self, PyObject *_args)
  1042. {
  1043. PyObject *_res = NULL;
  1044. OSErr _err;
  1045. long timeOutInTicks;
  1046. #ifndef AEInteractWithUser
  1047. PyMac_PRECHECK(AEInteractWithUser);
  1048. #endif
  1049. if (!PyArg_ParseTuple(_args, "l",
  1050. &timeOutInTicks))
  1051. return NULL;
  1052. _err = AEInteractWithUser(timeOutInTicks,
  1053. (NMRecPtr)0,
  1054. upp_AEIdleProc);
  1055. if (_err != noErr) return PyMac_Error(_err);
  1056. Py_INCREF(Py_None);
  1057. _res = Py_None;
  1058. return _res;
  1059. }
  1060. static PyObject *AE_AEInstallEventHandler(PyObject *_self, PyObject *_args)
  1061. {
  1062. PyObject *_res = NULL;
  1063. OSErr _err;
  1064. AEEventClass theAEEventClass;
  1065. AEEventID theAEEventID;
  1066. AEEventHandlerUPP handler__proc__ = upp_GenericEventHandler;
  1067. PyObject *handler;
  1068. #ifndef AEInstallEventHandler
  1069. PyMac_PRECHECK(AEInstallEventHandler);
  1070. #endif
  1071. if (!PyArg_ParseTuple(_args, "O&O&O",
  1072. PyMac_GetOSType, &theAEEventClass,
  1073. PyMac_GetOSType, &theAEEventID,
  1074. &handler))
  1075. return NULL;
  1076. _err = AEInstallEventHandler(theAEEventClass,
  1077. theAEEventID,
  1078. handler__proc__, (SRefCon)handler,
  1079. 0);
  1080. if (_err != noErr) return PyMac_Error(_err);
  1081. Py_INCREF(Py_None);
  1082. _res = Py_None;
  1083. Py_INCREF(handler); /* XXX leak, but needed */
  1084. return _res;
  1085. }
  1086. static PyObject *AE_AERemoveEventHandler(PyObject *_self, PyObject *_args)
  1087. {
  1088. PyObject *_res = NULL;
  1089. OSErr _err;
  1090. AEEventClass theAEEventClass;
  1091. AEEventID theAEEventID;
  1092. #ifndef AERemoveEventHandler
  1093. PyMac_PRECHECK(AERemoveEventHandler);
  1094. #endif
  1095. if (!PyArg_ParseTuple(_args, "O&O&",
  1096. PyMac_GetOSType, &theAEEventClass,
  1097. PyMac_GetOSType, &theAEEventID))
  1098. return NULL;
  1099. _err = AERemoveEventHandler(theAEEventClass,
  1100. theAEEventID,
  1101. upp_GenericEventHandler,
  1102. 0);
  1103. if (_err != noErr) return PyMac_Error(_err);
  1104. Py_INCREF(Py_None);
  1105. _res = Py_None;
  1106. return _res;
  1107. }
  1108. static PyObject *AE_AEGetEventHandler(PyObject *_self, PyObject *_args)
  1109. {
  1110. PyObject *_res = NULL;
  1111. OSErr _err;
  1112. AEEventClass theAEEventClass;
  1113. AEEventID theAEEventID;
  1114. AEEventHandlerUPP handler__proc__ = upp_GenericEventHandler;
  1115. PyObject *handler;
  1116. #ifndef AEGetEventHandler
  1117. PyMac_PRECHECK(AEGetEventHandler);
  1118. #endif
  1119. if (!PyArg_ParseTuple(_args, "O&O&",
  1120. PyMac_GetOSType, &theAEEventClass,
  1121. PyMac_GetOSType, &theAEEventID))
  1122. return NULL;
  1123. _err = AEGetEventHandler(theAEEventClass,
  1124. theAEEventID,
  1125. &handler__proc__, (SRefCon *)&handler,
  1126. 0);
  1127. if (_err != noErr) return PyMac_Error(_err);
  1128. _res = Py_BuildValue("O",
  1129. handler);
  1130. Py_INCREF(handler); /* XXX leak, but needed */
  1131. return _res;
  1132. }
  1133. static PyObject *AE_AEInstallSpecialHandler(PyObject *_self, PyObject *_args)
  1134. {
  1135. PyObject *_res = NULL;
  1136. OSErr _err;
  1137. AEKeyword functionClass;
  1138. #ifndef AEInstallSpecialHandler
  1139. PyMac_PRECHECK(AEInstallSpecialHandler);
  1140. #endif
  1141. if (!PyArg_ParseTuple(_args, "O&",
  1142. PyMac_GetOSType, &functionClass))
  1143. return NULL;
  1144. _err = AEInstallSpecialHandler(functionClass,
  1145. upp_GenericEventHandler,
  1146. 0);
  1147. if (_err != noErr) return PyMac_Error(_err);
  1148. Py_INCREF(Py_None);
  1149. _res = Py_None;
  1150. return _res;
  1151. }
  1152. static PyObject *AE_AERemoveSpecialHandler(PyObject *_self, PyObject *_args)
  1153. {
  1154. PyObject *_res = NULL;
  1155. OSErr _err;
  1156. AEKeyword functionClass;
  1157. #ifndef AERemoveSpecialHandler
  1158. PyMac_PRECHECK(AERemoveSpecialHandler);
  1159. #endif
  1160. if (!PyArg_ParseTuple(_args, "O&",
  1161. PyMac_GetOSType, &functionClass))
  1162. return NULL;
  1163. _err = AERemoveSpecialHandler(functionClass,
  1164. upp_GenericEventHandler,
  1165. 0);
  1166. if (_err != noErr) return PyMac_Error(_err);
  1167. Py_INCREF(Py_None);
  1168. _res = Py_None;
  1169. return _res;
  1170. }
  1171. static PyObject *AE_AEManagerInfo(PyObject *_self, PyObject *_args)
  1172. {
  1173. PyObject *_res = NULL;
  1174. OSErr _err;
  1175. AEKeyword keyWord;
  1176. long result;
  1177. #ifndef AEManagerInfo
  1178. PyMac_PRECHECK(AEManagerInfo);
  1179. #endif
  1180. if (!PyArg_ParseTuple(_args, "O&",
  1181. PyMac_GetOSType, &keyWord))
  1182. return NULL;
  1183. _err = AEManagerInfo(keyWord,
  1184. &result);
  1185. if (_err != noErr) return PyMac_Error(_err);
  1186. _res = Py_BuildValue("l",
  1187. result);
  1188. return _res;
  1189. }
  1190. static PyObject *AE_AEObjectInit(PyObject *_self, PyObject *_args)
  1191. {
  1192. PyObject *_res = NULL;
  1193. OSErr _err;
  1194. #ifndef AEObjectInit
  1195. PyMac_PRECHECK(AEObjectInit);
  1196. #endif
  1197. if (!PyArg_ParseTuple(_args, ""))
  1198. return NULL;
  1199. _err = AEObjectInit();
  1200. if (_err != noErr) return PyMac_Error(_err);
  1201. Py_INCREF(Py_None);
  1202. _res = Py_None;
  1203. return _res;
  1204. }
  1205. static PyObject *AE_AEDisposeToken(PyObject *_self, PyObject *_args)
  1206. {
  1207. PyObject *_res = NULL;
  1208. OSErr _err;
  1209. AEDesc theToken;
  1210. #ifndef AEDisposeToken
  1211. PyMac_PRECHECK(AEDisposeToken);
  1212. #endif
  1213. if (!PyArg_ParseTuple(_args, ""))
  1214. return NULL;
  1215. _err = AEDisposeToken(&theToken);
  1216. if (_err != noErr) return PyMac_Error(_err);
  1217. _res = Py_BuildValue("O&",
  1218. AEDesc_New, &theToken);
  1219. return _res;
  1220. }
  1221. static PyObject *AE_AECallObjectAccessor(PyObject *_self, PyObject *_args)
  1222. {
  1223. PyObject *_res = NULL;
  1224. OSErr _err;
  1225. DescType desiredClass;
  1226. AEDesc containerToken;
  1227. DescType containerClass;
  1228. DescType keyForm;
  1229. AEDesc keyData;
  1230. AEDesc token;
  1231. #ifndef AECallObjectAccessor
  1232. PyMac_PRECHECK(AECallObjectAccessor);
  1233. #endif
  1234. if (!PyArg_ParseTuple(_args, "O&O&O&O&O&",
  1235. PyMac_GetOSType, &desiredClass,
  1236. AEDesc_Convert, &containerToken,
  1237. PyMac_GetOSType, &containerClass,
  1238. PyMac_GetOSType, &keyForm,
  1239. AEDesc_Convert, &keyData))
  1240. return NULL;
  1241. _err = AECallObjectAccessor(desiredClass,
  1242. &containerToken,
  1243. containerClass,
  1244. keyForm,
  1245. &keyData,
  1246. &token);
  1247. if (_err != noErr) return PyMac_Error(_err);
  1248. _res = Py_BuildValue("O&",
  1249. AEDesc_New, &token);
  1250. return _res;
  1251. }
  1252. static PyMethodDef AE_methods[] = {
  1253. {"AECoercePtr", (PyCFunction)AE_AECoercePtr, 1,
  1254. PyDoc_STR("(DescType typeCode, Buffer dataPtr, DescType toType) -> (AEDesc result)")},
  1255. {"AECreateDesc", (PyCFunction)AE_AECreateDesc, 1,
  1256. PyDoc_STR("(DescType typeCode, Buffer dataPtr) -> (AEDesc result)")},
  1257. {"AECreateList", (PyCFunction)AE_AECreateList, 1,
  1258. PyDoc_STR("(Buffer factoringPtr, Boolean isRecord) -> (AEDescList resultList)")},
  1259. {"AECreateAppleEvent", (PyCFunction)AE_AECreateAppleEvent, 1,
  1260. PyDoc_STR("(AEEventClass theAEEventClass, AEEventID theAEEventID, AEAddressDesc target, AEReturnID returnID, AETransactionID transactionID) -> (AppleEvent result)")},
  1261. {"AEReplaceDescData", (PyCFunction)AE_AEReplaceDescData, 1,
  1262. PyDoc_STR("(DescType typeCode, Buffer dataPtr) -> (AEDesc theAEDesc)")},
  1263. {"AEProcessAppleEvent", (PyCFunction)AE_AEProcessAppleEvent, 1,
  1264. PyDoc_STR("(EventRecord theEventRecord) -> None")},
  1265. {"AEGetInteractionAllowed", (PyCFunction)AE_AEGetInteractionAllowed, 1,
  1266. PyDoc_STR("() -> (AEInteractAllowed level)")},
  1267. {"AESetInteractionAllowed", (PyCFunction)AE_AESetInteractionAllowed, 1,
  1268. PyDoc_STR("(AEInteractAllowed level) -> None")},
  1269. {"AEInteractWithUser", (PyCFunction)AE_AEInteractWithUser, 1,
  1270. PyDoc_STR("(long timeOutInTicks) -> None")},
  1271. {"AEInstallEventHandler", (PyCFunction)AE_AEInstallEventHandler, 1,
  1272. PyDoc_STR("(AEEventClass theAEEventClass, AEEventID theAEEventID, EventHandler handler) -> None")},
  1273. {"AERemoveEventHandler", (PyCFunction)AE_AERemoveEventHandler, 1,
  1274. PyDoc_STR("(AEEventClass theAEEventClass, AEEventID theAEEventID) -> None")},
  1275. {"AEGetEventHandler", (PyCFunction)AE_AEGetEventHandler, 1,
  1276. PyDoc_STR("(AEEventClass theAEEventClass, AEEventID theAEEventID) -> (EventHandler handler)")},
  1277. {"AEInstallSpecialHandler", (PyCFunction)AE_AEInstallSpecialHandler, 1,
  1278. PyDoc_STR("(AEKeyword functionClass) -> None")},
  1279. {"AERemoveSpecialHandler", (PyCFunction)AE_AERemoveSpecialHandler, 1,
  1280. PyDoc_STR("(AEKeyword functionClass) -> None")},
  1281. {"AEManagerInfo", (PyCFunction)AE_AEManagerInfo, 1,
  1282. PyDoc_STR("(AEKeyword keyWord) -> (long result)")},
  1283. {"AEObjectInit", (PyCFunction)AE_AEObjectInit, 1,
  1284. PyDoc_STR("() -> None")},
  1285. {"AEDisposeToken", (PyCFunction)AE_AEDisposeToken, 1,
  1286. PyDoc_STR("() -> (AEDesc theToken)")},
  1287. {"AECallObjectAccessor", (PyCFunction)AE_AECallObjectAccessor, 1,
  1288. PyDoc_STR("(DescType desiredClass, AEDesc containerToken, DescType containerClass, DescType keyForm, AEDesc keyData) -> (AEDesc token)")},
  1289. {NULL, NULL, 0}
  1290. };
  1291. static pascal OSErr
  1292. GenericEventHandler(const AppleEvent *request, AppleEvent *reply, refcontype refcon)
  1293. {
  1294. PyObject *handler = (PyObject *)refcon;
  1295. AEDescObject *requestObject, *replyObject;
  1296. PyObject *args, *res;
  1297. if ((requestObject = (AEDescObject *)AEDesc_New((AppleEvent *)request)) == NULL) {
  1298. return -1;
  1299. }
  1300. if ((replyObject = (AEDescObject *)AEDesc_New(reply)) == NULL) {
  1301. Py_DECREF(requestObject);
  1302. return -1;
  1303. }
  1304. if ((args = Py_BuildValue("OO", requestObject, replyObject)) == NULL) {
  1305. Py_DECREF(requestObject);
  1306. Py_DECREF(replyObject);
  1307. return -1;
  1308. }
  1309. res = PyEval_CallObject(handler, args);
  1310. requestObject->ob_itself.descriptorType = 'null';
  1311. requestObject->ob_itself.dataHandle = NULL;
  1312. replyObject->ob_itself.descriptorType = 'null';
  1313. replyObject->ob_itself.dataHandle = NULL;
  1314. Py_DECREF(args);
  1315. if (res == NULL) {
  1316. PySys_WriteStderr("Exception in AE event handler function\n");
  1317. PyErr_Print();
  1318. return -1;
  1319. }
  1320. Py_DECREF(res);
  1321. return noErr;
  1322. }
  1323. PyObject *AEDesc_NewBorrowed(AEDesc *itself)
  1324. {
  1325. PyObject *it;
  1326. it = AEDesc_New(itself);
  1327. if (it)
  1328. ((AEDescObject *)it)->ob_owned = 0;
  1329. return (PyObject *)it;
  1330. }
  1331. void init_AE(void)
  1332. {
  1333. PyObject *m;
  1334. PyObject *d;
  1335. upp_AEIdleProc = NewAEIdleUPP(AEIdleProc);
  1336. upp_GenericEventHandler = NewAEEventHandlerUPP(GenericEventHandler);
  1337. PyMac_INIT_TOOLBOX_OBJECT_NEW(AEDesc *, AEDesc_New);
  1338. PyMac_INIT_TOOLBOX_OBJECT_NEW(AEDesc *, AEDesc_NewBorrowed);
  1339. PyMac_INIT_TOOLBOX_OBJECT_CONVERT(AEDesc, AEDesc_Convert);
  1340. m = Py_InitModule("_AE", AE_methods);
  1341. d = PyModule_GetDict(m);
  1342. AE_Error = PyMac_GetOSErrException();
  1343. if (AE_Error == NULL ||
  1344. PyDict_SetItemString(d, "Error", AE_Error) != 0)
  1345. return;
  1346. AEDesc_Type.ob_type = &PyType_Type;
  1347. if (PyType_Ready(&AEDesc_Type) < 0) return;
  1348. Py_INCREF(&AEDesc_Type);
  1349. PyModule_AddObject(m, "AEDesc", (PyObject *)&AEDesc_Type);
  1350. /* Backward-compatible name */
  1351. Py_INCREF(&AEDesc_Type);
  1352. PyModule_AddObject(m, "AEDescType", (PyObject *)&AEDesc_Type);
  1353. }
  1354. /* ========================= End module _AE ========================= */