home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Python 1.4 / Python 1.4 source / Mac / Modules / cm / Cmmodule.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-31  |  19.6 KB  |  768 lines  |  [TEXT/CWIE]

  1.  
  2. /* =========================== Module Cm ============================ */
  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 *);
  18. extern PyObject *OptResObj_New(Handle);
  19. extern int OptResObj_Convert(PyObject *, Handle *);
  20.  
  21. extern PyObject *WinObj_New(WindowPtr);
  22. extern int WinObj_Convert(PyObject *, WindowPtr *);
  23. extern PyTypeObject Window_Type;
  24. #define WinObj_Check(x) ((x)->ob_type == &Window_Type)
  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.  
  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.  
  43. extern PyObject *WinObj_WhichWindow(WindowPtr);
  44.  
  45. #include <Components.h>
  46.  
  47. /*
  48. ** Parse/generate ComponentDescriptor records
  49. */
  50. PyObject *CmpDesc_New(itself)
  51.     ComponentDescription *itself;
  52. {
  53.  
  54.     return Py_BuildValue("O&O&O&ll", 
  55.         PyMac_BuildOSType, itself->componentType,
  56.         PyMac_BuildOSType, itself->componentSubType,
  57.         PyMac_BuildOSType, itself->componentManufacturer,
  58.         itself->componentFlags, itself->componentFlagsMask);
  59. }
  60.  
  61. CmpDesc_Convert(v, p_itself)
  62.     PyObject *v;
  63.     ComponentDescription *p_itself;
  64. {
  65.     return PyArg_ParseTuple(v, "O&O&O&ll",
  66.         PyMac_GetOSType, &p_itself->componentType,
  67.         PyMac_GetOSType, &p_itself->componentSubType,
  68.         PyMac_GetOSType, &p_itself->componentManufacturer,
  69.         &p_itself->componentFlags, &p_itself->componentFlagsMask);
  70. }
  71.  
  72.  
  73. static PyObject *Cm_Error;
  74.  
  75. /* ----------------- Object type ComponentInstance ------------------ */
  76.  
  77. PyTypeObject ComponentInstance_Type;
  78.  
  79. #define CmpInstObj_Check(x) ((x)->ob_type == &ComponentInstance_Type)
  80.  
  81. typedef struct ComponentInstanceObject {
  82.     PyObject_HEAD
  83.     ComponentInstance ob_itself;
  84. } ComponentInstanceObject;
  85.  
  86. PyObject *CmpInstObj_New(itself)
  87.     ComponentInstance itself;
  88. {
  89.     ComponentInstanceObject *it;
  90.     if (itself == NULL) {
  91.                         PyErr_SetString(Cm_Error,"NULL ComponentInstance");
  92.                         return NULL;
  93.                     }
  94.     it = PyObject_NEW(ComponentInstanceObject, &ComponentInstance_Type);
  95.     if (it == NULL) return NULL;
  96.     it->ob_itself = itself;
  97.     return (PyObject *)it;
  98. }
  99. CmpInstObj_Convert(v, p_itself)
  100.     PyObject *v;
  101.     ComponentInstance *p_itself;
  102. {
  103.     if (!CmpInstObj_Check(v))
  104.     {
  105.         PyErr_SetString(PyExc_TypeError, "ComponentInstance required");
  106.         return 0;
  107.     }
  108.     *p_itself = ((ComponentInstanceObject *)v)->ob_itself;
  109.     return 1;
  110. }
  111.  
  112. static void CmpInstObj_dealloc(self)
  113.     ComponentInstanceObject *self;
  114. {
  115.     /* Cleanup of self->ob_itself goes here */
  116.     PyMem_DEL(self);
  117. }
  118.  
  119. static PyObject *CmpInstObj_CloseComponent(_self, _args)
  120.     ComponentInstanceObject *_self;
  121.     PyObject *_args;
  122. {
  123.     PyObject *_res = NULL;
  124.     OSErr _err;
  125.     if (!PyArg_ParseTuple(_args, ""))
  126.         return NULL;
  127.     _err = CloseComponent(_self->ob_itself);
  128.     if (_err != noErr) return PyMac_Error(_err);
  129.     Py_INCREF(Py_None);
  130.     _res = Py_None;
  131.     return _res;
  132. }
  133.  
  134. static PyObject *CmpInstObj_GetComponentInstanceError(_self, _args)
  135.     ComponentInstanceObject *_self;
  136.     PyObject *_args;
  137. {
  138.     PyObject *_res = NULL;
  139.     OSErr _err;
  140.     if (!PyArg_ParseTuple(_args, ""))
  141.         return NULL;
  142.     _err = GetComponentInstanceError(_self->ob_itself);
  143.     if (_err != noErr) return PyMac_Error(_err);
  144.     Py_INCREF(Py_None);
  145.     _res = Py_None;
  146.     return _res;
  147. }
  148.  
  149. static PyObject *CmpInstObj_ComponentFunctionImplemented(_self, _args)
  150.     ComponentInstanceObject *_self;
  151.     PyObject *_args;
  152. {
  153.     PyObject *_res = NULL;
  154.     long _rv;
  155.     short ftnNumber;
  156.     if (!PyArg_ParseTuple(_args, "h",
  157.                           &ftnNumber))
  158.         return NULL;
  159.     _rv = ComponentFunctionImplemented(_self->ob_itself,
  160.                                        ftnNumber);
  161.     _res = Py_BuildValue("l",
  162.                          _rv);
  163.     return _res;
  164. }
  165.  
  166. static PyObject *CmpInstObj_GetComponentVersion(_self, _args)
  167.     ComponentInstanceObject *_self;
  168.     PyObject *_args;
  169. {
  170.     PyObject *_res = NULL;
  171.     long _rv;
  172.     if (!PyArg_ParseTuple(_args, ""))
  173.         return NULL;
  174.     _rv = GetComponentVersion(_self->ob_itself);
  175.     _res = Py_BuildValue("l",
  176.                          _rv);
  177.     return _res;
  178. }
  179.  
  180. static PyObject *CmpInstObj_ComponentSetTarget(_self, _args)
  181.     ComponentInstanceObject *_self;
  182.     PyObject *_args;
  183. {
  184.     PyObject *_res = NULL;
  185.     long _rv;
  186.     ComponentInstance target;
  187.     if (!PyArg_ParseTuple(_args, "O&",
  188.                           CmpInstObj_Convert, &target))
  189.         return NULL;
  190.     _rv = ComponentSetTarget(_self->ob_itself,
  191.                              target);
  192.     _res = Py_BuildValue("l",
  193.                          _rv);
  194.     return _res;
  195. }
  196.  
  197. static PyObject *CmpInstObj_SetComponentInstanceError(_self, _args)
  198.     ComponentInstanceObject *_self;
  199.     PyObject *_args;
  200. {
  201.     PyObject *_res = NULL;
  202.     OSErr theError;
  203.     if (!PyArg_ParseTuple(_args, "h",
  204.                           &theError))
  205.         return NULL;
  206.     SetComponentInstanceError(_self->ob_itself,
  207.                               theError);
  208.     Py_INCREF(Py_None);
  209.     _res = Py_None;
  210.     return _res;
  211. }
  212.  
  213. static PyObject *CmpInstObj_GetComponentInstanceStorage(_self, _args)
  214.     ComponentInstanceObject *_self;
  215.     PyObject *_args;
  216. {
  217.     PyObject *_res = NULL;
  218.     Handle _rv;
  219.     if (!PyArg_ParseTuple(_args, ""))
  220.         return NULL;
  221.     _rv = GetComponentInstanceStorage(_self->ob_itself);
  222.     _res = Py_BuildValue("O&",
  223.                          ResObj_New, _rv);
  224.     return _res;
  225. }
  226.  
  227. static PyObject *CmpInstObj_SetComponentInstanceStorage(_self, _args)
  228.     ComponentInstanceObject *_self;
  229.     PyObject *_args;
  230. {
  231.     PyObject *_res = NULL;
  232.     Handle theStorage;
  233.     if (!PyArg_ParseTuple(_args, "O&",
  234.                           ResObj_Convert, &theStorage))
  235.         return NULL;
  236.     SetComponentInstanceStorage(_self->ob_itself,
  237.                                 theStorage);
  238.     Py_INCREF(Py_None);
  239.     _res = Py_None;
  240.     return _res;
  241. }
  242.  
  243. static PyObject *CmpInstObj_GetComponentInstanceA5(_self, _args)
  244.     ComponentInstanceObject *_self;
  245.     PyObject *_args;
  246. {
  247.     PyObject *_res = NULL;
  248.     long _rv;
  249.     if (!PyArg_ParseTuple(_args, ""))
  250.         return NULL;
  251.     _rv = GetComponentInstanceA5(_self->ob_itself);
  252.     _res = Py_BuildValue("l",
  253.                          _rv);
  254.     return _res;
  255. }
  256.  
  257. static PyObject *CmpInstObj_SetComponentInstanceA5(_self, _args)
  258.     ComponentInstanceObject *_self;
  259.     PyObject *_args;
  260. {
  261.     PyObject *_res = NULL;
  262.     long theA5;
  263.     if (!PyArg_ParseTuple(_args, "l",
  264.                           &theA5))
  265.         return NULL;
  266.     SetComponentInstanceA5(_self->ob_itself,
  267.                            theA5);
  268.     Py_INCREF(Py_None);
  269.     _res = Py_None;
  270.     return _res;
  271. }
  272.  
  273. static PyMethodDef CmpInstObj_methods[] = {
  274.     {"CloseComponent", (PyCFunction)CmpInstObj_CloseComponent, 1,
  275.      "() -> None"},
  276.     {"GetComponentInstanceError", (PyCFunction)CmpInstObj_GetComponentInstanceError, 1,
  277.      "() -> None"},
  278.     {"ComponentFunctionImplemented", (PyCFunction)CmpInstObj_ComponentFunctionImplemented, 1,
  279.      "(short ftnNumber) -> (long _rv)"},
  280.     {"GetComponentVersion", (PyCFunction)CmpInstObj_GetComponentVersion, 1,
  281.      "() -> (long _rv)"},
  282.     {"ComponentSetTarget", (PyCFunction)CmpInstObj_ComponentSetTarget, 1,
  283.      "(ComponentInstance target) -> (long _rv)"},
  284.     {"SetComponentInstanceError", (PyCFunction)CmpInstObj_SetComponentInstanceError, 1,
  285.      "(OSErr theError) -> None"},
  286.     {"GetComponentInstanceStorage", (PyCFunction)CmpInstObj_GetComponentInstanceStorage, 1,
  287.      "() -> (Handle _rv)"},
  288.     {"SetComponentInstanceStorage", (PyCFunction)CmpInstObj_SetComponentInstanceStorage, 1,
  289.      "(Handle theStorage) -> None"},
  290.     {"GetComponentInstanceA5", (PyCFunction)CmpInstObj_GetComponentInstanceA5, 1,
  291.      "() -> (long _rv)"},
  292.     {"SetComponentInstanceA5", (PyCFunction)CmpInstObj_SetComponentInstanceA5, 1,
  293.      "(long theA5) -> None"},
  294.     {NULL, NULL, 0}
  295. };
  296.  
  297. PyMethodChain CmpInstObj_chain = { CmpInstObj_methods, NULL };
  298.  
  299. static PyObject *CmpInstObj_getattr(self, name)
  300.     ComponentInstanceObject *self;
  301.     char *name;
  302. {
  303.     return Py_FindMethodInChain(&CmpInstObj_chain, (PyObject *)self, name);
  304. }
  305.  
  306. #define CmpInstObj_setattr NULL
  307.  
  308. PyTypeObject ComponentInstance_Type = {
  309.     PyObject_HEAD_INIT(&PyType_Type)
  310.     0, /*ob_size*/
  311.     "ComponentInstance", /*tp_name*/
  312.     sizeof(ComponentInstanceObject), /*tp_basicsize*/
  313.     0, /*tp_itemsize*/
  314.     /* methods */
  315.     (destructor) CmpInstObj_dealloc, /*tp_dealloc*/
  316.     0, /*tp_print*/
  317.     (getattrfunc) CmpInstObj_getattr, /*tp_getattr*/
  318.     (setattrfunc) CmpInstObj_setattr, /*tp_setattr*/
  319. };
  320.  
  321. /* --------------- End object type ComponentInstance ---------------- */
  322.  
  323.  
  324. /* --------------------- Object type Component ---------------------- */
  325.  
  326. PyTypeObject Component_Type;
  327.  
  328. #define CmpObj_Check(x) ((x)->ob_type == &Component_Type)
  329.  
  330. typedef struct ComponentObject {
  331.     PyObject_HEAD
  332.     Component ob_itself;
  333. } ComponentObject;
  334.  
  335. PyObject *CmpObj_New(itself)
  336.     Component itself;
  337. {
  338.     ComponentObject *it;
  339.     if (itself == NULL) {
  340.                         /* XXXX Or should we return None? */
  341.                         PyErr_SetString(Cm_Error,"No such component");
  342.                         return NULL;
  343.                     }
  344.     it = PyObject_NEW(ComponentObject, &Component_Type);
  345.     if (it == NULL) return NULL;
  346.     it->ob_itself = itself;
  347.     return (PyObject *)it;
  348. }
  349. CmpObj_Convert(v, p_itself)
  350.     PyObject *v;
  351.     Component *p_itself;
  352. {
  353.     if ( v == Py_None ) {
  354.                         *p_itself = 0;
  355.                         return 1;
  356.             }
  357.     if (!CmpObj_Check(v))
  358.     {
  359.         PyErr_SetString(PyExc_TypeError, "Component required");
  360.         return 0;
  361.     }
  362.     *p_itself = ((ComponentObject *)v)->ob_itself;
  363.     return 1;
  364. }
  365.  
  366. static void CmpObj_dealloc(self)
  367.     ComponentObject *self;
  368. {
  369.     /* Cleanup of self->ob_itself goes here */
  370.     PyMem_DEL(self);
  371. }
  372.  
  373. static PyObject *CmpObj_UnregisterComponent(_self, _args)
  374.     ComponentObject *_self;
  375.     PyObject *_args;
  376. {
  377.     PyObject *_res = NULL;
  378.     OSErr _err;
  379.     if (!PyArg_ParseTuple(_args, ""))
  380.         return NULL;
  381.     _err = UnregisterComponent(_self->ob_itself);
  382.     if (_err != noErr) return PyMac_Error(_err);
  383.     Py_INCREF(Py_None);
  384.     _res = Py_None;
  385.     return _res;
  386. }
  387.  
  388. static PyObject *CmpObj_GetComponentInfo(_self, _args)
  389.     ComponentObject *_self;
  390.     PyObject *_args;
  391. {
  392.     PyObject *_res = NULL;
  393.     OSErr _err;
  394.     ComponentDescription cd;
  395.     Handle componentName;
  396.     Handle componentInfo;
  397.     Handle componentIcon;
  398.     if (!PyArg_ParseTuple(_args, "O&O&O&",
  399.                           ResObj_Convert, &componentName,
  400.                           ResObj_Convert, &componentInfo,
  401.                           ResObj_Convert, &componentIcon))
  402.         return NULL;
  403.     _err = GetComponentInfo(_self->ob_itself,
  404.                             &cd,
  405.                             componentName,
  406.                             componentInfo,
  407.                             componentIcon);
  408.     if (_err != noErr) return PyMac_Error(_err);
  409.     _res = Py_BuildValue("O&",
  410.                          CmpDesc_New, &cd);
  411.     return _res;
  412. }
  413.  
  414. static PyObject *CmpObj_OpenComponent(_self, _args)
  415.     ComponentObject *_self;
  416.     PyObject *_args;
  417. {
  418.     PyObject *_res = NULL;
  419.     ComponentInstance _rv;
  420.     if (!PyArg_ParseTuple(_args, ""))
  421.         return NULL;
  422.     _rv = OpenComponent(_self->ob_itself);
  423.     _res = Py_BuildValue("O&",
  424.                          CmpInstObj_New, _rv);
  425.     return _res;
  426. }
  427.  
  428. static PyObject *CmpObj_GetComponentRefcon(_self, _args)
  429.     ComponentObject *_self;
  430.     PyObject *_args;
  431. {
  432.     PyObject *_res = NULL;
  433.     long _rv;
  434.     if (!PyArg_ParseTuple(_args, ""))
  435.         return NULL;
  436.     _rv = GetComponentRefcon(_self->ob_itself);
  437.     _res = Py_BuildValue("l",
  438.                          _rv);
  439.     return _res;
  440. }
  441.  
  442. static PyObject *CmpObj_SetComponentRefcon(_self, _args)
  443.     ComponentObject *_self;
  444.     PyObject *_args;
  445. {
  446.     PyObject *_res = NULL;
  447.     long theRefcon;
  448.     if (!PyArg_ParseTuple(_args, "l",
  449.                           &theRefcon))
  450.         return NULL;
  451.     SetComponentRefcon(_self->ob_itself,
  452.                        theRefcon);
  453.     Py_INCREF(Py_None);
  454.     _res = Py_None;
  455.     return _res;
  456. }
  457.  
  458. static PyObject *CmpObj_OpenComponentResFile(_self, _args)
  459.     ComponentObject *_self;
  460.     PyObject *_args;
  461. {
  462.     PyObject *_res = NULL;
  463.     short _rv;
  464.     if (!PyArg_ParseTuple(_args, ""))
  465.         return NULL;
  466.     _rv = OpenComponentResFile(_self->ob_itself);
  467.     _res = Py_BuildValue("h",
  468.                          _rv);
  469.     return _res;
  470. }
  471.  
  472. static PyObject *CmpObj_CountComponentInstances(_self, _args)
  473.     ComponentObject *_self;
  474.     PyObject *_args;
  475. {
  476.     PyObject *_res = NULL;
  477.     long _rv;
  478.     if (!PyArg_ParseTuple(_args, ""))
  479.         return NULL;
  480.     _rv = CountComponentInstances(_self->ob_itself);
  481.     _res = Py_BuildValue("l",
  482.                          _rv);
  483.     return _res;
  484. }
  485.  
  486. static PyObject *CmpObj_SetDefaultComponent(_self, _args)
  487.     ComponentObject *_self;
  488.     PyObject *_args;
  489. {
  490.     PyObject *_res = NULL;
  491.     OSErr _err;
  492.     short flags;
  493.     if (!PyArg_ParseTuple(_args, "h",
  494.                           &flags))
  495.         return NULL;
  496.     _err = SetDefaultComponent(_self->ob_itself,
  497.                                flags);
  498.     if (_err != noErr) return PyMac_Error(_err);
  499.     Py_INCREF(Py_None);
  500.     _res = Py_None;
  501.     return _res;
  502. }
  503.  
  504. static PyObject *CmpObj_CaptureComponent(_self, _args)
  505.     ComponentObject *_self;
  506.     PyObject *_args;
  507. {
  508.     PyObject *_res = NULL;
  509.     Component _rv;
  510.     Component capturingComponent;
  511.     if (!PyArg_ParseTuple(_args, "O&",
  512.                           CmpObj_Convert, &capturingComponent))
  513.         return NULL;
  514.     _rv = CaptureComponent(_self->ob_itself,
  515.                            capturingComponent);
  516.     _res = Py_BuildValue("O&",
  517.                          CmpObj_New, _rv);
  518.     return _res;
  519. }
  520.  
  521. static PyObject *CmpObj_UncaptureComponent(_self, _args)
  522.     ComponentObject *_self;
  523.     PyObject *_args;
  524. {
  525.     PyObject *_res = NULL;
  526.     OSErr _err;
  527.     if (!PyArg_ParseTuple(_args, ""))
  528.         return NULL;
  529.     _err = UncaptureComponent(_self->ob_itself);
  530.     if (_err != noErr) return PyMac_Error(_err);
  531.     Py_INCREF(Py_None);
  532.     _res = Py_None;
  533.     return _res;
  534. }
  535.  
  536. static PyObject *CmpObj_GetComponentIconSuite(_self, _args)
  537.     ComponentObject *_self;
  538.     PyObject *_args;
  539. {
  540.     PyObject *_res = NULL;
  541.     OSErr _err;
  542.     Handle iconSuite;
  543.     if (!PyArg_ParseTuple(_args, ""))
  544.         return NULL;
  545.     _err = GetComponentIconSuite(_self->ob_itself,
  546.                                  &iconSuite);
  547.     if (_err != noErr) return PyMac_Error(_err);
  548.     _res = Py_BuildValue("O&",
  549.                          ResObj_New, iconSuite);
  550.     return _res;
  551. }
  552.  
  553. static PyMethodDef CmpObj_methods[] = {
  554.     {"UnregisterComponent", (PyCFunction)CmpObj_UnregisterComponent, 1,
  555.      "() -> None"},
  556.     {"GetComponentInfo", (PyCFunction)CmpObj_GetComponentInfo, 1,
  557.      "(Handle componentName, Handle componentInfo, Handle componentIcon) -> (ComponentDescription cd)"},
  558.     {"OpenComponent", (PyCFunction)CmpObj_OpenComponent, 1,
  559.      "() -> (ComponentInstance _rv)"},
  560.     {"GetComponentRefcon", (PyCFunction)CmpObj_GetComponentRefcon, 1,
  561.      "() -> (long _rv)"},
  562.     {"SetComponentRefcon", (PyCFunction)CmpObj_SetComponentRefcon, 1,
  563.      "(long theRefcon) -> None"},
  564.     {"OpenComponentResFile", (PyCFunction)CmpObj_OpenComponentResFile, 1,
  565.      "() -> (short _rv)"},
  566.     {"CountComponentInstances", (PyCFunction)CmpObj_CountComponentInstances, 1,
  567.      "() -> (long _rv)"},
  568.     {"SetDefaultComponent", (PyCFunction)CmpObj_SetDefaultComponent, 1,
  569.      "(short flags) -> None"},
  570.     {"CaptureComponent", (PyCFunction)CmpObj_CaptureComponent, 1,
  571.      "(Component capturingComponent) -> (Component _rv)"},
  572.     {"UncaptureComponent", (PyCFunction)CmpObj_UncaptureComponent, 1,
  573.      "() -> None"},
  574.     {"GetComponentIconSuite", (PyCFunction)CmpObj_GetComponentIconSuite, 1,
  575.      "() -> (Handle iconSuite)"},
  576.     {NULL, NULL, 0}
  577. };
  578.  
  579. PyMethodChain CmpObj_chain = { CmpObj_methods, NULL };
  580.  
  581. static PyObject *CmpObj_getattr(self, name)
  582.     ComponentObject *self;
  583.     char *name;
  584. {
  585.     return Py_FindMethodInChain(&CmpObj_chain, (PyObject *)self, name);
  586. }
  587.  
  588. #define CmpObj_setattr NULL
  589.  
  590. PyTypeObject Component_Type = {
  591.     PyObject_HEAD_INIT(&PyType_Type)
  592.     0, /*ob_size*/
  593.     "Component", /*tp_name*/
  594.     sizeof(ComponentObject), /*tp_basicsize*/
  595.     0, /*tp_itemsize*/
  596.     /* methods */
  597.     (destructor) CmpObj_dealloc, /*tp_dealloc*/
  598.     0, /*tp_print*/
  599.     (getattrfunc) CmpObj_getattr, /*tp_getattr*/
  600.     (setattrfunc) CmpObj_setattr, /*tp_setattr*/
  601. };
  602.  
  603. /* ------------------- End object type Component -------------------- */
  604.  
  605.  
  606. static PyObject *Cm_RegisterComponentResource(_self, _args)
  607.     PyObject *_self;
  608.     PyObject *_args;
  609. {
  610.     PyObject *_res = NULL;
  611.     Component _rv;
  612.     ComponentResourceHandle tr;
  613.     short global;
  614.     if (!PyArg_ParseTuple(_args, "O&h",
  615.                           ResObj_Convert, &tr,
  616.                           &global))
  617.         return NULL;
  618.     _rv = RegisterComponentResource(tr,
  619.                                     global);
  620.     _res = Py_BuildValue("O&",
  621.                          CmpObj_New, _rv);
  622.     return _res;
  623. }
  624.  
  625. static PyObject *Cm_FindNextComponent(_self, _args)
  626.     PyObject *_self;
  627.     PyObject *_args;
  628. {
  629.     PyObject *_res = NULL;
  630.     Component _rv;
  631.     Component aComponent;
  632.     ComponentDescription looking;
  633.     if (!PyArg_ParseTuple(_args, "O&O&",
  634.                           CmpObj_Convert, &aComponent,
  635.                           CmpDesc_Convert, &looking))
  636.         return NULL;
  637.     _rv = FindNextComponent(aComponent,
  638.                             &looking);
  639.     _res = Py_BuildValue("O&",
  640.                          CmpObj_New, _rv);
  641.     return _res;
  642. }
  643.  
  644. static PyObject *Cm_CountComponents(_self, _args)
  645.     PyObject *_self;
  646.     PyObject *_args;
  647. {
  648.     PyObject *_res = NULL;
  649.     long _rv;
  650.     ComponentDescription looking;
  651.     if (!PyArg_ParseTuple(_args, "O&",
  652.                           CmpDesc_Convert, &looking))
  653.         return NULL;
  654.     _rv = CountComponents(&looking);
  655.     _res = Py_BuildValue("l",
  656.                          _rv);
  657.     return _res;
  658. }
  659.  
  660. static PyObject *Cm_GetComponentListModSeed(_self, _args)
  661.     PyObject *_self;
  662.     PyObject *_args;
  663. {
  664.     PyObject *_res = NULL;
  665.     long _rv;
  666.     if (!PyArg_ParseTuple(_args, ""))
  667.         return NULL;
  668.     _rv = GetComponentListModSeed();
  669.     _res = Py_BuildValue("l",
  670.                          _rv);
  671.     return _res;
  672. }
  673.  
  674. static PyObject *Cm_CloseComponentResFile(_self, _args)
  675.     PyObject *_self;
  676.     PyObject *_args;
  677. {
  678.     PyObject *_res = NULL;
  679.     OSErr _err;
  680.     short refnum;
  681.     if (!PyArg_ParseTuple(_args, "h",
  682.                           &refnum))
  683.         return NULL;
  684.     _err = CloseComponentResFile(refnum);
  685.     if (_err != noErr) return PyMac_Error(_err);
  686.     Py_INCREF(Py_None);
  687.     _res = Py_None;
  688.     return _res;
  689. }
  690.  
  691. static PyObject *Cm_OpenDefaultComponent(_self, _args)
  692.     PyObject *_self;
  693.     PyObject *_args;
  694. {
  695.     PyObject *_res = NULL;
  696.     ComponentInstance _rv;
  697.     OSType componentType;
  698.     OSType componentSubType;
  699.     if (!PyArg_ParseTuple(_args, "O&O&",
  700.                           PyMac_GetOSType, &componentType,
  701.                           PyMac_GetOSType, &componentSubType))
  702.         return NULL;
  703.     _rv = OpenDefaultComponent(componentType,
  704.                                componentSubType);
  705.     _res = Py_BuildValue("O&",
  706.                          CmpInstObj_New, _rv);
  707.     return _res;
  708. }
  709.  
  710. static PyObject *Cm_RegisterComponentResourceFile(_self, _args)
  711.     PyObject *_self;
  712.     PyObject *_args;
  713. {
  714.     PyObject *_res = NULL;
  715.     long _rv;
  716.     short resRefNum;
  717.     short global;
  718.     if (!PyArg_ParseTuple(_args, "hh",
  719.                           &resRefNum,
  720.                           &global))
  721.         return NULL;
  722.     _rv = RegisterComponentResourceFile(resRefNum,
  723.                                         global);
  724.     _res = Py_BuildValue("l",
  725.                          _rv);
  726.     return _res;
  727. }
  728.  
  729. static PyMethodDef Cm_methods[] = {
  730.     {"RegisterComponentResource", (PyCFunction)Cm_RegisterComponentResource, 1,
  731.      "(ComponentResourceHandle tr, short global) -> (Component _rv)"},
  732.     {"FindNextComponent", (PyCFunction)Cm_FindNextComponent, 1,
  733.      "(Component aComponent, ComponentDescription looking) -> (Component _rv)"},
  734.     {"CountComponents", (PyCFunction)Cm_CountComponents, 1,
  735.      "(ComponentDescription looking) -> (long _rv)"},
  736.     {"GetComponentListModSeed", (PyCFunction)Cm_GetComponentListModSeed, 1,
  737.      "() -> (long _rv)"},
  738.     {"CloseComponentResFile", (PyCFunction)Cm_CloseComponentResFile, 1,
  739.      "(short refnum) -> None"},
  740.     {"OpenDefaultComponent", (PyCFunction)Cm_OpenDefaultComponent, 1,
  741.      "(OSType componentType, OSType componentSubType) -> (ComponentInstance _rv)"},
  742.     {"RegisterComponentResourceFile", (PyCFunction)Cm_RegisterComponentResourceFile, 1,
  743.      "(short resRefNum, short global) -> (long _rv)"},
  744.     {NULL, NULL, 0}
  745. };
  746.  
  747.  
  748.  
  749.  
  750. void initCm()
  751. {
  752.     PyObject *m;
  753.     PyObject *d;
  754.  
  755.  
  756.  
  757.  
  758.     m = Py_InitModule("Cm", Cm_methods);
  759.     d = PyModule_GetDict(m);
  760.     Cm_Error = PyMac_GetOSErrException();
  761.     if (Cm_Error == NULL ||
  762.         PyDict_SetItemString(d, "Error", Cm_Error) != 0)
  763.         Py_FatalError("can't initialize Cm.Error");
  764. }
  765.  
  766. /* ========================= End module Cm ========================== */
  767.  
  768.