This is (hopefully) last checkin before releasing 2.1c2 -- get rid of
[python/dscho.git] / Mac / Modules / cm / Cmmodule.c
blob93a3e09841c167f7a4b8923fdce827b1ad5c8d52
2 /* =========================== Module Cm ============================ */
4 #include "Python.h"
8 #include "macglue.h"
9 #include "pymactoolbox.h"
11 #include <Components.h>
14 ** Parse/generate ComponentDescriptor records
16 static PyObject *
17 CmpDesc_New(itself)
18 ComponentDescription *itself;
21 return Py_BuildValue("O&O&O&ll",
22 PyMac_BuildOSType, itself->componentType,
23 PyMac_BuildOSType, itself->componentSubType,
24 PyMac_BuildOSType, itself->componentManufacturer,
25 itself->componentFlags, itself->componentFlagsMask);
28 static int
29 CmpDesc_Convert(v, p_itself)
30 PyObject *v;
31 ComponentDescription *p_itself;
33 return PyArg_ParseTuple(v, "O&O&O&ll",
34 PyMac_GetOSType, &p_itself->componentType,
35 PyMac_GetOSType, &p_itself->componentSubType,
36 PyMac_GetOSType, &p_itself->componentManufacturer,
37 &p_itself->componentFlags, &p_itself->componentFlagsMask);
41 static PyObject *Cm_Error;
43 /* ----------------- Object type ComponentInstance ------------------ */
45 PyTypeObject ComponentInstance_Type;
47 #define CmpInstObj_Check(x) ((x)->ob_type == &ComponentInstance_Type)
49 typedef struct ComponentInstanceObject {
50 PyObject_HEAD
51 ComponentInstance ob_itself;
52 } ComponentInstanceObject;
54 PyObject *CmpInstObj_New(itself)
55 ComponentInstance itself;
57 ComponentInstanceObject *it;
58 if (itself == NULL) {
59 PyErr_SetString(Cm_Error,"NULL ComponentInstance");
60 return NULL;
62 it = PyObject_NEW(ComponentInstanceObject, &ComponentInstance_Type);
63 if (it == NULL) return NULL;
64 it->ob_itself = itself;
65 return (PyObject *)it;
67 CmpInstObj_Convert(v, p_itself)
68 PyObject *v;
69 ComponentInstance *p_itself;
71 if (!CmpInstObj_Check(v))
73 PyErr_SetString(PyExc_TypeError, "ComponentInstance required");
74 return 0;
76 *p_itself = ((ComponentInstanceObject *)v)->ob_itself;
77 return 1;
80 static void CmpInstObj_dealloc(self)
81 ComponentInstanceObject *self;
83 /* Cleanup of self->ob_itself goes here */
84 PyMem_DEL(self);
87 static PyObject *CmpInstObj_CloseComponent(_self, _args)
88 ComponentInstanceObject *_self;
89 PyObject *_args;
91 PyObject *_res = NULL;
92 OSErr _err;
93 if (!PyArg_ParseTuple(_args, ""))
94 return NULL;
95 _err = CloseComponent(_self->ob_itself);
96 if (_err != noErr) return PyMac_Error(_err);
97 Py_INCREF(Py_None);
98 _res = Py_None;
99 return _res;
102 static PyObject *CmpInstObj_GetComponentInstanceError(_self, _args)
103 ComponentInstanceObject *_self;
104 PyObject *_args;
106 PyObject *_res = NULL;
107 OSErr _err;
108 if (!PyArg_ParseTuple(_args, ""))
109 return NULL;
110 _err = GetComponentInstanceError(_self->ob_itself);
111 if (_err != noErr) return PyMac_Error(_err);
112 Py_INCREF(Py_None);
113 _res = Py_None;
114 return _res;
117 static PyObject *CmpInstObj_SetComponentInstanceError(_self, _args)
118 ComponentInstanceObject *_self;
119 PyObject *_args;
121 PyObject *_res = NULL;
122 OSErr theError;
123 if (!PyArg_ParseTuple(_args, "h",
124 &theError))
125 return NULL;
126 SetComponentInstanceError(_self->ob_itself,
127 theError);
128 Py_INCREF(Py_None);
129 _res = Py_None;
130 return _res;
133 static PyObject *CmpInstObj_GetComponentInstanceStorage(_self, _args)
134 ComponentInstanceObject *_self;
135 PyObject *_args;
137 PyObject *_res = NULL;
138 Handle _rv;
139 if (!PyArg_ParseTuple(_args, ""))
140 return NULL;
141 _rv = GetComponentInstanceStorage(_self->ob_itself);
142 _res = Py_BuildValue("O&",
143 ResObj_New, _rv);
144 return _res;
147 static PyObject *CmpInstObj_SetComponentInstanceStorage(_self, _args)
148 ComponentInstanceObject *_self;
149 PyObject *_args;
151 PyObject *_res = NULL;
152 Handle theStorage;
153 if (!PyArg_ParseTuple(_args, "O&",
154 ResObj_Convert, &theStorage))
155 return NULL;
156 SetComponentInstanceStorage(_self->ob_itself,
157 theStorage);
158 Py_INCREF(Py_None);
159 _res = Py_None;
160 return _res;
163 #if !TARGET_API_MAC_CARBON
165 static PyObject *CmpInstObj_GetComponentInstanceA5(_self, _args)
166 ComponentInstanceObject *_self;
167 PyObject *_args;
169 PyObject *_res = NULL;
170 long _rv;
171 if (!PyArg_ParseTuple(_args, ""))
172 return NULL;
173 _rv = GetComponentInstanceA5(_self->ob_itself);
174 _res = Py_BuildValue("l",
175 _rv);
176 return _res;
178 #endif
180 #if !TARGET_API_MAC_CARBON
182 static PyObject *CmpInstObj_SetComponentInstanceA5(_self, _args)
183 ComponentInstanceObject *_self;
184 PyObject *_args;
186 PyObject *_res = NULL;
187 long theA5;
188 if (!PyArg_ParseTuple(_args, "l",
189 &theA5))
190 return NULL;
191 SetComponentInstanceA5(_self->ob_itself,
192 theA5);
193 Py_INCREF(Py_None);
194 _res = Py_None;
195 return _res;
197 #endif
199 static PyObject *CmpInstObj_ComponentFunctionImplemented(_self, _args)
200 ComponentInstanceObject *_self;
201 PyObject *_args;
203 PyObject *_res = NULL;
204 long _rv;
205 short ftnNumber;
206 if (!PyArg_ParseTuple(_args, "h",
207 &ftnNumber))
208 return NULL;
209 _rv = ComponentFunctionImplemented(_self->ob_itself,
210 ftnNumber);
211 _res = Py_BuildValue("l",
212 _rv);
213 return _res;
216 static PyObject *CmpInstObj_GetComponentVersion(_self, _args)
217 ComponentInstanceObject *_self;
218 PyObject *_args;
220 PyObject *_res = NULL;
221 long _rv;
222 if (!PyArg_ParseTuple(_args, ""))
223 return NULL;
224 _rv = GetComponentVersion(_self->ob_itself);
225 _res = Py_BuildValue("l",
226 _rv);
227 return _res;
230 static PyObject *CmpInstObj_ComponentSetTarget(_self, _args)
231 ComponentInstanceObject *_self;
232 PyObject *_args;
234 PyObject *_res = NULL;
235 long _rv;
236 ComponentInstance target;
237 if (!PyArg_ParseTuple(_args, "O&",
238 CmpInstObj_Convert, &target))
239 return NULL;
240 _rv = ComponentSetTarget(_self->ob_itself,
241 target);
242 _res = Py_BuildValue("l",
243 _rv);
244 return _res;
247 static PyMethodDef CmpInstObj_methods[] = {
248 {"CloseComponent", (PyCFunction)CmpInstObj_CloseComponent, 1,
249 "() -> None"},
250 {"GetComponentInstanceError", (PyCFunction)CmpInstObj_GetComponentInstanceError, 1,
251 "() -> None"},
252 {"SetComponentInstanceError", (PyCFunction)CmpInstObj_SetComponentInstanceError, 1,
253 "(OSErr theError) -> None"},
254 {"GetComponentInstanceStorage", (PyCFunction)CmpInstObj_GetComponentInstanceStorage, 1,
255 "() -> (Handle _rv)"},
256 {"SetComponentInstanceStorage", (PyCFunction)CmpInstObj_SetComponentInstanceStorage, 1,
257 "(Handle theStorage) -> None"},
259 #if !TARGET_API_MAC_CARBON
260 {"GetComponentInstanceA5", (PyCFunction)CmpInstObj_GetComponentInstanceA5, 1,
261 "() -> (long _rv)"},
262 #endif
264 #if !TARGET_API_MAC_CARBON
265 {"SetComponentInstanceA5", (PyCFunction)CmpInstObj_SetComponentInstanceA5, 1,
266 "(long theA5) -> None"},
267 #endif
268 {"ComponentFunctionImplemented", (PyCFunction)CmpInstObj_ComponentFunctionImplemented, 1,
269 "(short ftnNumber) -> (long _rv)"},
270 {"GetComponentVersion", (PyCFunction)CmpInstObj_GetComponentVersion, 1,
271 "() -> (long _rv)"},
272 {"ComponentSetTarget", (PyCFunction)CmpInstObj_ComponentSetTarget, 1,
273 "(ComponentInstance target) -> (long _rv)"},
274 {NULL, NULL, 0}
277 PyMethodChain CmpInstObj_chain = { CmpInstObj_methods, NULL };
279 static PyObject *CmpInstObj_getattr(self, name)
280 ComponentInstanceObject *self;
281 char *name;
283 return Py_FindMethodInChain(&CmpInstObj_chain, (PyObject *)self, name);
286 #define CmpInstObj_setattr NULL
288 #define CmpInstObj_compare NULL
290 #define CmpInstObj_repr NULL
292 #define CmpInstObj_hash NULL
294 PyTypeObject ComponentInstance_Type = {
295 PyObject_HEAD_INIT(&PyType_Type)
296 0, /*ob_size*/
297 "ComponentInstance", /*tp_name*/
298 sizeof(ComponentInstanceObject), /*tp_basicsize*/
299 0, /*tp_itemsize*/
300 /* methods */
301 (destructor) CmpInstObj_dealloc, /*tp_dealloc*/
302 0, /*tp_print*/
303 (getattrfunc) CmpInstObj_getattr, /*tp_getattr*/
304 (setattrfunc) CmpInstObj_setattr, /*tp_setattr*/
305 (cmpfunc) CmpInstObj_compare, /*tp_compare*/
306 (reprfunc) CmpInstObj_repr, /*tp_repr*/
307 (PyNumberMethods *)0, /* tp_as_number */
308 (PySequenceMethods *)0, /* tp_as_sequence */
309 (PyMappingMethods *)0, /* tp_as_mapping */
310 (hashfunc) CmpInstObj_hash, /*tp_hash*/
313 /* --------------- End object type ComponentInstance ---------------- */
316 /* --------------------- Object type Component ---------------------- */
318 PyTypeObject Component_Type;
320 #define CmpObj_Check(x) ((x)->ob_type == &Component_Type)
322 typedef struct ComponentObject {
323 PyObject_HEAD
324 Component ob_itself;
325 } ComponentObject;
327 PyObject *CmpObj_New(itself)
328 Component itself;
330 ComponentObject *it;
331 if (itself == NULL) {
332 /* XXXX Or should we return None? */
333 PyErr_SetString(Cm_Error,"No such component");
334 return NULL;
336 it = PyObject_NEW(ComponentObject, &Component_Type);
337 if (it == NULL) return NULL;
338 it->ob_itself = itself;
339 return (PyObject *)it;
341 CmpObj_Convert(v, p_itself)
342 PyObject *v;
343 Component *p_itself;
345 if ( v == Py_None ) {
346 *p_itself = 0;
347 return 1;
349 if (!CmpObj_Check(v))
351 PyErr_SetString(PyExc_TypeError, "Component required");
352 return 0;
354 *p_itself = ((ComponentObject *)v)->ob_itself;
355 return 1;
358 static void CmpObj_dealloc(self)
359 ComponentObject *self;
361 /* Cleanup of self->ob_itself goes here */
362 PyMem_DEL(self);
365 static PyObject *CmpObj_UnregisterComponent(_self, _args)
366 ComponentObject *_self;
367 PyObject *_args;
369 PyObject *_res = NULL;
370 OSErr _err;
371 if (!PyArg_ParseTuple(_args, ""))
372 return NULL;
373 _err = UnregisterComponent(_self->ob_itself);
374 if (_err != noErr) return PyMac_Error(_err);
375 Py_INCREF(Py_None);
376 _res = Py_None;
377 return _res;
380 static PyObject *CmpObj_GetComponentInfo(_self, _args)
381 ComponentObject *_self;
382 PyObject *_args;
384 PyObject *_res = NULL;
385 OSErr _err;
386 ComponentDescription cd;
387 Handle componentName;
388 Handle componentInfo;
389 Handle componentIcon;
390 if (!PyArg_ParseTuple(_args, "O&O&O&",
391 ResObj_Convert, &componentName,
392 ResObj_Convert, &componentInfo,
393 ResObj_Convert, &componentIcon))
394 return NULL;
395 _err = GetComponentInfo(_self->ob_itself,
396 &cd,
397 componentName,
398 componentInfo,
399 componentIcon);
400 if (_err != noErr) return PyMac_Error(_err);
401 _res = Py_BuildValue("O&",
402 CmpDesc_New, &cd);
403 return _res;
406 static PyObject *CmpObj_OpenComponent(_self, _args)
407 ComponentObject *_self;
408 PyObject *_args;
410 PyObject *_res = NULL;
411 ComponentInstance _rv;
412 if (!PyArg_ParseTuple(_args, ""))
413 return NULL;
414 _rv = OpenComponent(_self->ob_itself);
415 _res = Py_BuildValue("O&",
416 CmpInstObj_New, _rv);
417 return _res;
420 static PyObject *CmpObj_GetComponentRefcon(_self, _args)
421 ComponentObject *_self;
422 PyObject *_args;
424 PyObject *_res = NULL;
425 long _rv;
426 if (!PyArg_ParseTuple(_args, ""))
427 return NULL;
428 _rv = GetComponentRefcon(_self->ob_itself);
429 _res = Py_BuildValue("l",
430 _rv);
431 return _res;
434 static PyObject *CmpObj_SetComponentRefcon(_self, _args)
435 ComponentObject *_self;
436 PyObject *_args;
438 PyObject *_res = NULL;
439 long theRefcon;
440 if (!PyArg_ParseTuple(_args, "l",
441 &theRefcon))
442 return NULL;
443 SetComponentRefcon(_self->ob_itself,
444 theRefcon);
445 Py_INCREF(Py_None);
446 _res = Py_None;
447 return _res;
450 static PyObject *CmpObj_OpenComponentResFile(_self, _args)
451 ComponentObject *_self;
452 PyObject *_args;
454 PyObject *_res = NULL;
455 short _rv;
456 if (!PyArg_ParseTuple(_args, ""))
457 return NULL;
458 _rv = OpenComponentResFile(_self->ob_itself);
459 _res = Py_BuildValue("h",
460 _rv);
461 return _res;
464 static PyObject *CmpObj_GetComponentResource(_self, _args)
465 ComponentObject *_self;
466 PyObject *_args;
468 PyObject *_res = NULL;
469 OSErr _err;
470 OSType resType;
471 short resID;
472 Handle theResource;
473 if (!PyArg_ParseTuple(_args, "O&h",
474 PyMac_GetOSType, &resType,
475 &resID))
476 return NULL;
477 _err = GetComponentResource(_self->ob_itself,
478 resType,
479 resID,
480 &theResource);
481 if (_err != noErr) return PyMac_Error(_err);
482 _res = Py_BuildValue("O&",
483 ResObj_New, theResource);
484 return _res;
487 static PyObject *CmpObj_GetComponentIndString(_self, _args)
488 ComponentObject *_self;
489 PyObject *_args;
491 PyObject *_res = NULL;
492 OSErr _err;
493 Str255 theString;
494 short strListID;
495 short index;
496 if (!PyArg_ParseTuple(_args, "O&hh",
497 PyMac_GetStr255, theString,
498 &strListID,
499 &index))
500 return NULL;
501 _err = GetComponentIndString(_self->ob_itself,
502 theString,
503 strListID,
504 index);
505 if (_err != noErr) return PyMac_Error(_err);
506 Py_INCREF(Py_None);
507 _res = Py_None;
508 return _res;
511 static PyObject *CmpObj_ResolveComponentAlias(_self, _args)
512 ComponentObject *_self;
513 PyObject *_args;
515 PyObject *_res = NULL;
516 Component _rv;
517 if (!PyArg_ParseTuple(_args, ""))
518 return NULL;
519 _rv = ResolveComponentAlias(_self->ob_itself);
520 _res = Py_BuildValue("O&",
521 CmpObj_New, _rv);
522 return _res;
525 static PyObject *CmpObj_CountComponentInstances(_self, _args)
526 ComponentObject *_self;
527 PyObject *_args;
529 PyObject *_res = NULL;
530 long _rv;
531 if (!PyArg_ParseTuple(_args, ""))
532 return NULL;
533 _rv = CountComponentInstances(_self->ob_itself);
534 _res = Py_BuildValue("l",
535 _rv);
536 return _res;
539 static PyObject *CmpObj_SetDefaultComponent(_self, _args)
540 ComponentObject *_self;
541 PyObject *_args;
543 PyObject *_res = NULL;
544 OSErr _err;
545 short flags;
546 if (!PyArg_ParseTuple(_args, "h",
547 &flags))
548 return NULL;
549 _err = SetDefaultComponent(_self->ob_itself,
550 flags);
551 if (_err != noErr) return PyMac_Error(_err);
552 Py_INCREF(Py_None);
553 _res = Py_None;
554 return _res;
557 static PyObject *CmpObj_CaptureComponent(_self, _args)
558 ComponentObject *_self;
559 PyObject *_args;
561 PyObject *_res = NULL;
562 Component _rv;
563 Component capturingComponent;
564 if (!PyArg_ParseTuple(_args, "O&",
565 CmpObj_Convert, &capturingComponent))
566 return NULL;
567 _rv = CaptureComponent(_self->ob_itself,
568 capturingComponent);
569 _res = Py_BuildValue("O&",
570 CmpObj_New, _rv);
571 return _res;
574 static PyObject *CmpObj_UncaptureComponent(_self, _args)
575 ComponentObject *_self;
576 PyObject *_args;
578 PyObject *_res = NULL;
579 OSErr _err;
580 if (!PyArg_ParseTuple(_args, ""))
581 return NULL;
582 _err = UncaptureComponent(_self->ob_itself);
583 if (_err != noErr) return PyMac_Error(_err);
584 Py_INCREF(Py_None);
585 _res = Py_None;
586 return _res;
589 static PyObject *CmpObj_GetComponentIconSuite(_self, _args)
590 ComponentObject *_self;
591 PyObject *_args;
593 PyObject *_res = NULL;
594 OSErr _err;
595 Handle iconSuite;
596 if (!PyArg_ParseTuple(_args, ""))
597 return NULL;
598 _err = GetComponentIconSuite(_self->ob_itself,
599 &iconSuite);
600 if (_err != noErr) return PyMac_Error(_err);
601 _res = Py_BuildValue("O&",
602 ResObj_New, iconSuite);
603 return _res;
606 static PyMethodDef CmpObj_methods[] = {
607 {"UnregisterComponent", (PyCFunction)CmpObj_UnregisterComponent, 1,
608 "() -> None"},
609 {"GetComponentInfo", (PyCFunction)CmpObj_GetComponentInfo, 1,
610 "(Handle componentName, Handle componentInfo, Handle componentIcon) -> (ComponentDescription cd)"},
611 {"OpenComponent", (PyCFunction)CmpObj_OpenComponent, 1,
612 "() -> (ComponentInstance _rv)"},
613 {"GetComponentRefcon", (PyCFunction)CmpObj_GetComponentRefcon, 1,
614 "() -> (long _rv)"},
615 {"SetComponentRefcon", (PyCFunction)CmpObj_SetComponentRefcon, 1,
616 "(long theRefcon) -> None"},
617 {"OpenComponentResFile", (PyCFunction)CmpObj_OpenComponentResFile, 1,
618 "() -> (short _rv)"},
619 {"GetComponentResource", (PyCFunction)CmpObj_GetComponentResource, 1,
620 "(OSType resType, short resID) -> (Handle theResource)"},
621 {"GetComponentIndString", (PyCFunction)CmpObj_GetComponentIndString, 1,
622 "(Str255 theString, short strListID, short index) -> None"},
623 {"ResolveComponentAlias", (PyCFunction)CmpObj_ResolveComponentAlias, 1,
624 "() -> (Component _rv)"},
625 {"CountComponentInstances", (PyCFunction)CmpObj_CountComponentInstances, 1,
626 "() -> (long _rv)"},
627 {"SetDefaultComponent", (PyCFunction)CmpObj_SetDefaultComponent, 1,
628 "(short flags) -> None"},
629 {"CaptureComponent", (PyCFunction)CmpObj_CaptureComponent, 1,
630 "(Component capturingComponent) -> (Component _rv)"},
631 {"UncaptureComponent", (PyCFunction)CmpObj_UncaptureComponent, 1,
632 "() -> None"},
633 {"GetComponentIconSuite", (PyCFunction)CmpObj_GetComponentIconSuite, 1,
634 "() -> (Handle iconSuite)"},
635 {NULL, NULL, 0}
638 PyMethodChain CmpObj_chain = { CmpObj_methods, NULL };
640 static PyObject *CmpObj_getattr(self, name)
641 ComponentObject *self;
642 char *name;
644 return Py_FindMethodInChain(&CmpObj_chain, (PyObject *)self, name);
647 #define CmpObj_setattr NULL
649 #define CmpObj_compare NULL
651 #define CmpObj_repr NULL
653 #define CmpObj_hash NULL
655 PyTypeObject Component_Type = {
656 PyObject_HEAD_INIT(&PyType_Type)
657 0, /*ob_size*/
658 "Component", /*tp_name*/
659 sizeof(ComponentObject), /*tp_basicsize*/
660 0, /*tp_itemsize*/
661 /* methods */
662 (destructor) CmpObj_dealloc, /*tp_dealloc*/
663 0, /*tp_print*/
664 (getattrfunc) CmpObj_getattr, /*tp_getattr*/
665 (setattrfunc) CmpObj_setattr, /*tp_setattr*/
666 (cmpfunc) CmpObj_compare, /*tp_compare*/
667 (reprfunc) CmpObj_repr, /*tp_repr*/
668 (PyNumberMethods *)0, /* tp_as_number */
669 (PySequenceMethods *)0, /* tp_as_sequence */
670 (PyMappingMethods *)0, /* tp_as_mapping */
671 (hashfunc) CmpObj_hash, /*tp_hash*/
674 /* ------------------- End object type Component -------------------- */
677 static PyObject *Cm_RegisterComponentResource(_self, _args)
678 PyObject *_self;
679 PyObject *_args;
681 PyObject *_res = NULL;
682 Component _rv;
683 ComponentResourceHandle cr;
684 short global;
685 if (!PyArg_ParseTuple(_args, "O&h",
686 ResObj_Convert, &cr,
687 &global))
688 return NULL;
689 _rv = RegisterComponentResource(cr,
690 global);
691 _res = Py_BuildValue("O&",
692 CmpObj_New, _rv);
693 return _res;
696 static PyObject *Cm_FindNextComponent(_self, _args)
697 PyObject *_self;
698 PyObject *_args;
700 PyObject *_res = NULL;
701 Component _rv;
702 Component aComponent;
703 ComponentDescription looking;
704 if (!PyArg_ParseTuple(_args, "O&O&",
705 CmpObj_Convert, &aComponent,
706 CmpDesc_Convert, &looking))
707 return NULL;
708 _rv = FindNextComponent(aComponent,
709 &looking);
710 _res = Py_BuildValue("O&",
711 CmpObj_New, _rv);
712 return _res;
715 static PyObject *Cm_CountComponents(_self, _args)
716 PyObject *_self;
717 PyObject *_args;
719 PyObject *_res = NULL;
720 long _rv;
721 ComponentDescription looking;
722 if (!PyArg_ParseTuple(_args, "O&",
723 CmpDesc_Convert, &looking))
724 return NULL;
725 _rv = CountComponents(&looking);
726 _res = Py_BuildValue("l",
727 _rv);
728 return _res;
731 static PyObject *Cm_GetComponentListModSeed(_self, _args)
732 PyObject *_self;
733 PyObject *_args;
735 PyObject *_res = NULL;
736 long _rv;
737 if (!PyArg_ParseTuple(_args, ""))
738 return NULL;
739 _rv = GetComponentListModSeed();
740 _res = Py_BuildValue("l",
741 _rv);
742 return _res;
745 static PyObject *Cm_CloseComponentResFile(_self, _args)
746 PyObject *_self;
747 PyObject *_args;
749 PyObject *_res = NULL;
750 OSErr _err;
751 short refnum;
752 if (!PyArg_ParseTuple(_args, "h",
753 &refnum))
754 return NULL;
755 _err = CloseComponentResFile(refnum);
756 if (_err != noErr) return PyMac_Error(_err);
757 Py_INCREF(Py_None);
758 _res = Py_None;
759 return _res;
762 static PyObject *Cm_OpenDefaultComponent(_self, _args)
763 PyObject *_self;
764 PyObject *_args;
766 PyObject *_res = NULL;
767 ComponentInstance _rv;
768 OSType componentType;
769 OSType componentSubType;
770 if (!PyArg_ParseTuple(_args, "O&O&",
771 PyMac_GetOSType, &componentType,
772 PyMac_GetOSType, &componentSubType))
773 return NULL;
774 _rv = OpenDefaultComponent(componentType,
775 componentSubType);
776 _res = Py_BuildValue("O&",
777 CmpInstObj_New, _rv);
778 return _res;
781 static PyObject *Cm_RegisterComponentResourceFile(_self, _args)
782 PyObject *_self;
783 PyObject *_args;
785 PyObject *_res = NULL;
786 long _rv;
787 short resRefNum;
788 short global;
789 if (!PyArg_ParseTuple(_args, "hh",
790 &resRefNum,
791 &global))
792 return NULL;
793 _rv = RegisterComponentResourceFile(resRefNum,
794 global);
795 _res = Py_BuildValue("l",
796 _rv);
797 return _res;
800 static PyMethodDef Cm_methods[] = {
801 {"RegisterComponentResource", (PyCFunction)Cm_RegisterComponentResource, 1,
802 "(ComponentResourceHandle cr, short global) -> (Component _rv)"},
803 {"FindNextComponent", (PyCFunction)Cm_FindNextComponent, 1,
804 "(Component aComponent, ComponentDescription looking) -> (Component _rv)"},
805 {"CountComponents", (PyCFunction)Cm_CountComponents, 1,
806 "(ComponentDescription looking) -> (long _rv)"},
807 {"GetComponentListModSeed", (PyCFunction)Cm_GetComponentListModSeed, 1,
808 "() -> (long _rv)"},
809 {"CloseComponentResFile", (PyCFunction)Cm_CloseComponentResFile, 1,
810 "(short refnum) -> None"},
811 {"OpenDefaultComponent", (PyCFunction)Cm_OpenDefaultComponent, 1,
812 "(OSType componentType, OSType componentSubType) -> (ComponentInstance _rv)"},
813 {"RegisterComponentResourceFile", (PyCFunction)Cm_RegisterComponentResourceFile, 1,
814 "(short resRefNum, short global) -> (long _rv)"},
815 {NULL, NULL, 0}
821 void initCm()
823 PyObject *m;
824 PyObject *d;
829 m = Py_InitModule("Cm", Cm_methods);
830 d = PyModule_GetDict(m);
831 Cm_Error = PyMac_GetOSErrException();
832 if (Cm_Error == NULL ||
833 PyDict_SetItemString(d, "Error", Cm_Error) != 0)
834 return;
835 ComponentInstance_Type.ob_type = &PyType_Type;
836 Py_INCREF(&ComponentInstance_Type);
837 if (PyDict_SetItemString(d, "ComponentInstanceType", (PyObject *)&ComponentInstance_Type) != 0)
838 Py_FatalError("can't initialize ComponentInstanceType");
839 Component_Type.ob_type = &PyType_Type;
840 Py_INCREF(&Component_Type);
841 if (PyDict_SetItemString(d, "ComponentType", (PyObject *)&Component_Type) != 0)
842 Py_FatalError("can't initialize ComponentType");
845 /* ========================= End module Cm ========================== */