Quick update to the README file. For intros and books we now point to
[python/dscho.git] / Mac / Modules / cm / Cmmodule.c
blobab293d9da38216aa87049e8d2b6253eebf4e8e26
2 /* =========================== Module Cm ============================ */
4 #include "Python.h"
8 #define SystemSevenOrLater 1
10 #include "macglue.h"
11 #include <Memory.h>
12 #include <Dialogs.h>
13 #include <Menus.h>
14 #include <Controls.h>
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 *);
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)
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)
31 extern PyObject *MenuObj_New(MenuHandle);
32 extern int MenuObj_Convert(PyObject *, MenuHandle *);
34 extern PyObject *CtlObj_New(ControlHandle);
35 extern int CtlObj_Convert(PyObject *, ControlHandle *);
37 extern PyObject *GrafObj_New(GrafPtr);
38 extern int GrafObj_Convert(PyObject *, GrafPtr *);
40 extern PyObject *BMObj_New(BitMapPtr);
41 extern int BMObj_Convert(PyObject *, BitMapPtr *);
43 extern PyObject *WinObj_WhichWindow(WindowPtr);
45 #include <Components.h>
48 ** Parse/generate ComponentDescriptor records
50 PyObject *CmpDesc_New(itself)
51 ComponentDescription *itself;
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);
61 CmpDesc_Convert(v, p_itself)
62 PyObject *v;
63 ComponentDescription *p_itself;
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);
73 static PyObject *Cm_Error;
75 /* ----------------- Object type ComponentInstance ------------------ */
77 PyTypeObject ComponentInstance_Type;
79 #define CmpInstObj_Check(x) ((x)->ob_type == &ComponentInstance_Type)
81 typedef struct ComponentInstanceObject {
82 PyObject_HEAD
83 ComponentInstance ob_itself;
84 } ComponentInstanceObject;
86 PyObject *CmpInstObj_New(itself)
87 ComponentInstance itself;
89 ComponentInstanceObject *it;
90 if (itself == NULL) {
91 PyErr_SetString(Cm_Error,"NULL ComponentInstance");
92 return NULL;
94 it = PyObject_NEW(ComponentInstanceObject, &ComponentInstance_Type);
95 if (it == NULL) return NULL;
96 it->ob_itself = itself;
97 return (PyObject *)it;
99 CmpInstObj_Convert(v, p_itself)
100 PyObject *v;
101 ComponentInstance *p_itself;
103 if (!CmpInstObj_Check(v))
105 PyErr_SetString(PyExc_TypeError, "ComponentInstance required");
106 return 0;
108 *p_itself = ((ComponentInstanceObject *)v)->ob_itself;
109 return 1;
112 static void CmpInstObj_dealloc(self)
113 ComponentInstanceObject *self;
115 /* Cleanup of self->ob_itself goes here */
116 PyMem_DEL(self);
119 static PyObject *CmpInstObj_CloseComponent(_self, _args)
120 ComponentInstanceObject *_self;
121 PyObject *_args;
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;
134 static PyObject *CmpInstObj_GetComponentInstanceError(_self, _args)
135 ComponentInstanceObject *_self;
136 PyObject *_args;
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;
149 static PyObject *CmpInstObj_SetComponentInstanceError(_self, _args)
150 ComponentInstanceObject *_self;
151 PyObject *_args;
153 PyObject *_res = NULL;
154 OSErr theError;
155 if (!PyArg_ParseTuple(_args, "h",
156 &theError))
157 return NULL;
158 SetComponentInstanceError(_self->ob_itself,
159 theError);
160 Py_INCREF(Py_None);
161 _res = Py_None;
162 return _res;
165 static PyObject *CmpInstObj_GetComponentInstanceStorage(_self, _args)
166 ComponentInstanceObject *_self;
167 PyObject *_args;
169 PyObject *_res = NULL;
170 Handle _rv;
171 if (!PyArg_ParseTuple(_args, ""))
172 return NULL;
173 _rv = GetComponentInstanceStorage(_self->ob_itself);
174 _res = Py_BuildValue("O&",
175 ResObj_New, _rv);
176 return _res;
179 static PyObject *CmpInstObj_SetComponentInstanceStorage(_self, _args)
180 ComponentInstanceObject *_self;
181 PyObject *_args;
183 PyObject *_res = NULL;
184 Handle theStorage;
185 if (!PyArg_ParseTuple(_args, "O&",
186 ResObj_Convert, &theStorage))
187 return NULL;
188 SetComponentInstanceStorage(_self->ob_itself,
189 theStorage);
190 Py_INCREF(Py_None);
191 _res = Py_None;
192 return _res;
195 static PyObject *CmpInstObj_GetComponentInstanceA5(_self, _args)
196 ComponentInstanceObject *_self;
197 PyObject *_args;
199 PyObject *_res = NULL;
200 long _rv;
201 if (!PyArg_ParseTuple(_args, ""))
202 return NULL;
203 _rv = GetComponentInstanceA5(_self->ob_itself);
204 _res = Py_BuildValue("l",
205 _rv);
206 return _res;
209 static PyObject *CmpInstObj_SetComponentInstanceA5(_self, _args)
210 ComponentInstanceObject *_self;
211 PyObject *_args;
213 PyObject *_res = NULL;
214 long theA5;
215 if (!PyArg_ParseTuple(_args, "l",
216 &theA5))
217 return NULL;
218 SetComponentInstanceA5(_self->ob_itself,
219 theA5);
220 Py_INCREF(Py_None);
221 _res = Py_None;
222 return _res;
225 static PyObject *CmpInstObj_ComponentFunctionImplemented(_self, _args)
226 ComponentInstanceObject *_self;
227 PyObject *_args;
229 PyObject *_res = NULL;
230 long _rv;
231 short ftnNumber;
232 if (!PyArg_ParseTuple(_args, "h",
233 &ftnNumber))
234 return NULL;
235 _rv = ComponentFunctionImplemented(_self->ob_itself,
236 ftnNumber);
237 _res = Py_BuildValue("l",
238 _rv);
239 return _res;
242 static PyObject *CmpInstObj_GetComponentVersion(_self, _args)
243 ComponentInstanceObject *_self;
244 PyObject *_args;
246 PyObject *_res = NULL;
247 long _rv;
248 if (!PyArg_ParseTuple(_args, ""))
249 return NULL;
250 _rv = GetComponentVersion(_self->ob_itself);
251 _res = Py_BuildValue("l",
252 _rv);
253 return _res;
256 static PyObject *CmpInstObj_ComponentSetTarget(_self, _args)
257 ComponentInstanceObject *_self;
258 PyObject *_args;
260 PyObject *_res = NULL;
261 long _rv;
262 ComponentInstance target;
263 if (!PyArg_ParseTuple(_args, "O&",
264 CmpInstObj_Convert, &target))
265 return NULL;
266 _rv = ComponentSetTarget(_self->ob_itself,
267 target);
268 _res = Py_BuildValue("l",
269 _rv);
270 return _res;
273 static PyMethodDef CmpInstObj_methods[] = {
274 {"CloseComponent", (PyCFunction)CmpInstObj_CloseComponent, 1,
275 "() -> None"},
276 {"GetComponentInstanceError", (PyCFunction)CmpInstObj_GetComponentInstanceError, 1,
277 "() -> None"},
278 {"SetComponentInstanceError", (PyCFunction)CmpInstObj_SetComponentInstanceError, 1,
279 "(OSErr theError) -> None"},
280 {"GetComponentInstanceStorage", (PyCFunction)CmpInstObj_GetComponentInstanceStorage, 1,
281 "() -> (Handle _rv)"},
282 {"SetComponentInstanceStorage", (PyCFunction)CmpInstObj_SetComponentInstanceStorage, 1,
283 "(Handle theStorage) -> None"},
284 {"GetComponentInstanceA5", (PyCFunction)CmpInstObj_GetComponentInstanceA5, 1,
285 "() -> (long _rv)"},
286 {"SetComponentInstanceA5", (PyCFunction)CmpInstObj_SetComponentInstanceA5, 1,
287 "(long theA5) -> None"},
288 {"ComponentFunctionImplemented", (PyCFunction)CmpInstObj_ComponentFunctionImplemented, 1,
289 "(short ftnNumber) -> (long _rv)"},
290 {"GetComponentVersion", (PyCFunction)CmpInstObj_GetComponentVersion, 1,
291 "() -> (long _rv)"},
292 {"ComponentSetTarget", (PyCFunction)CmpInstObj_ComponentSetTarget, 1,
293 "(ComponentInstance target) -> (long _rv)"},
294 {NULL, NULL, 0}
297 PyMethodChain CmpInstObj_chain = { CmpInstObj_methods, NULL };
299 static PyObject *CmpInstObj_getattr(self, name)
300 ComponentInstanceObject *self;
301 char *name;
303 return Py_FindMethodInChain(&CmpInstObj_chain, (PyObject *)self, name);
306 #define CmpInstObj_setattr NULL
308 #define CmpInstObj_compare NULL
310 #define CmpInstObj_repr NULL
312 #define CmpInstObj_hash NULL
314 PyTypeObject ComponentInstance_Type = {
315 PyObject_HEAD_INIT(&PyType_Type)
316 0, /*ob_size*/
317 "ComponentInstance", /*tp_name*/
318 sizeof(ComponentInstanceObject), /*tp_basicsize*/
319 0, /*tp_itemsize*/
320 /* methods */
321 (destructor) CmpInstObj_dealloc, /*tp_dealloc*/
322 0, /*tp_print*/
323 (getattrfunc) CmpInstObj_getattr, /*tp_getattr*/
324 (setattrfunc) CmpInstObj_setattr, /*tp_setattr*/
325 (cmpfunc) CmpInstObj_compare, /*tp_compare*/
326 (reprfunc) CmpInstObj_repr, /*tp_repr*/
327 (PyNumberMethods *)0, /* tp_as_number */
328 (PySequenceMethods *)0, /* tp_as_sequence */
329 (PyMappingMethods *)0, /* tp_as_mapping */
330 (hashfunc) CmpInstObj_hash, /*tp_hash*/
333 /* --------------- End object type ComponentInstance ---------------- */
336 /* --------------------- Object type Component ---------------------- */
338 PyTypeObject Component_Type;
340 #define CmpObj_Check(x) ((x)->ob_type == &Component_Type)
342 typedef struct ComponentObject {
343 PyObject_HEAD
344 Component ob_itself;
345 } ComponentObject;
347 PyObject *CmpObj_New(itself)
348 Component itself;
350 ComponentObject *it;
351 if (itself == NULL) {
352 /* XXXX Or should we return None? */
353 PyErr_SetString(Cm_Error,"No such component");
354 return NULL;
356 it = PyObject_NEW(ComponentObject, &Component_Type);
357 if (it == NULL) return NULL;
358 it->ob_itself = itself;
359 return (PyObject *)it;
361 CmpObj_Convert(v, p_itself)
362 PyObject *v;
363 Component *p_itself;
365 if ( v == Py_None ) {
366 *p_itself = 0;
367 return 1;
369 if (!CmpObj_Check(v))
371 PyErr_SetString(PyExc_TypeError, "Component required");
372 return 0;
374 *p_itself = ((ComponentObject *)v)->ob_itself;
375 return 1;
378 static void CmpObj_dealloc(self)
379 ComponentObject *self;
381 /* Cleanup of self->ob_itself goes here */
382 PyMem_DEL(self);
385 static PyObject *CmpObj_UnregisterComponent(_self, _args)
386 ComponentObject *_self;
387 PyObject *_args;
389 PyObject *_res = NULL;
390 OSErr _err;
391 if (!PyArg_ParseTuple(_args, ""))
392 return NULL;
393 _err = UnregisterComponent(_self->ob_itself);
394 if (_err != noErr) return PyMac_Error(_err);
395 Py_INCREF(Py_None);
396 _res = Py_None;
397 return _res;
400 static PyObject *CmpObj_GetComponentInfo(_self, _args)
401 ComponentObject *_self;
402 PyObject *_args;
404 PyObject *_res = NULL;
405 OSErr _err;
406 ComponentDescription cd;
407 Handle componentName;
408 Handle componentInfo;
409 Handle componentIcon;
410 if (!PyArg_ParseTuple(_args, "O&O&O&",
411 ResObj_Convert, &componentName,
412 ResObj_Convert, &componentInfo,
413 ResObj_Convert, &componentIcon))
414 return NULL;
415 _err = GetComponentInfo(_self->ob_itself,
416 &cd,
417 componentName,
418 componentInfo,
419 componentIcon);
420 if (_err != noErr) return PyMac_Error(_err);
421 _res = Py_BuildValue("O&",
422 CmpDesc_New, &cd);
423 return _res;
426 static PyObject *CmpObj_OpenComponent(_self, _args)
427 ComponentObject *_self;
428 PyObject *_args;
430 PyObject *_res = NULL;
431 ComponentInstance _rv;
432 if (!PyArg_ParseTuple(_args, ""))
433 return NULL;
434 _rv = OpenComponent(_self->ob_itself);
435 _res = Py_BuildValue("O&",
436 CmpInstObj_New, _rv);
437 return _res;
440 static PyObject *CmpObj_GetComponentRefcon(_self, _args)
441 ComponentObject *_self;
442 PyObject *_args;
444 PyObject *_res = NULL;
445 long _rv;
446 if (!PyArg_ParseTuple(_args, ""))
447 return NULL;
448 _rv = GetComponentRefcon(_self->ob_itself);
449 _res = Py_BuildValue("l",
450 _rv);
451 return _res;
454 static PyObject *CmpObj_SetComponentRefcon(_self, _args)
455 ComponentObject *_self;
456 PyObject *_args;
458 PyObject *_res = NULL;
459 long theRefcon;
460 if (!PyArg_ParseTuple(_args, "l",
461 &theRefcon))
462 return NULL;
463 SetComponentRefcon(_self->ob_itself,
464 theRefcon);
465 Py_INCREF(Py_None);
466 _res = Py_None;
467 return _res;
470 static PyObject *CmpObj_OpenComponentResFile(_self, _args)
471 ComponentObject *_self;
472 PyObject *_args;
474 PyObject *_res = NULL;
475 short _rv;
476 if (!PyArg_ParseTuple(_args, ""))
477 return NULL;
478 _rv = OpenComponentResFile(_self->ob_itself);
479 _res = Py_BuildValue("h",
480 _rv);
481 return _res;
484 static PyObject *CmpObj_GetComponentResource(_self, _args)
485 ComponentObject *_self;
486 PyObject *_args;
488 PyObject *_res = NULL;
489 OSErr _err;
490 OSType resType;
491 short resID;
492 Handle theResource;
493 if (!PyArg_ParseTuple(_args, "O&h",
494 PyMac_GetOSType, &resType,
495 &resID))
496 return NULL;
497 _err = GetComponentResource(_self->ob_itself,
498 resType,
499 resID,
500 &theResource);
501 if (_err != noErr) return PyMac_Error(_err);
502 _res = Py_BuildValue("O&",
503 ResObj_New, theResource);
504 return _res;
507 static PyObject *CmpObj_GetComponentIndString(_self, _args)
508 ComponentObject *_self;
509 PyObject *_args;
511 PyObject *_res = NULL;
512 OSErr _err;
513 Str255 theString;
514 short strListID;
515 short index;
516 if (!PyArg_ParseTuple(_args, "O&hh",
517 PyMac_GetStr255, theString,
518 &strListID,
519 &index))
520 return NULL;
521 _err = GetComponentIndString(_self->ob_itself,
522 theString,
523 strListID,
524 index);
525 if (_err != noErr) return PyMac_Error(_err);
526 Py_INCREF(Py_None);
527 _res = Py_None;
528 return _res;
531 static PyObject *CmpObj_ResolveComponentAlias(_self, _args)
532 ComponentObject *_self;
533 PyObject *_args;
535 PyObject *_res = NULL;
536 Component _rv;
537 if (!PyArg_ParseTuple(_args, ""))
538 return NULL;
539 _rv = ResolveComponentAlias(_self->ob_itself);
540 _res = Py_BuildValue("O&",
541 CmpObj_New, _rv);
542 return _res;
545 static PyObject *CmpObj_CountComponentInstances(_self, _args)
546 ComponentObject *_self;
547 PyObject *_args;
549 PyObject *_res = NULL;
550 long _rv;
551 if (!PyArg_ParseTuple(_args, ""))
552 return NULL;
553 _rv = CountComponentInstances(_self->ob_itself);
554 _res = Py_BuildValue("l",
555 _rv);
556 return _res;
559 static PyObject *CmpObj_SetDefaultComponent(_self, _args)
560 ComponentObject *_self;
561 PyObject *_args;
563 PyObject *_res = NULL;
564 OSErr _err;
565 short flags;
566 if (!PyArg_ParseTuple(_args, "h",
567 &flags))
568 return NULL;
569 _err = SetDefaultComponent(_self->ob_itself,
570 flags);
571 if (_err != noErr) return PyMac_Error(_err);
572 Py_INCREF(Py_None);
573 _res = Py_None;
574 return _res;
577 static PyObject *CmpObj_CaptureComponent(_self, _args)
578 ComponentObject *_self;
579 PyObject *_args;
581 PyObject *_res = NULL;
582 Component _rv;
583 Component capturingComponent;
584 if (!PyArg_ParseTuple(_args, "O&",
585 CmpObj_Convert, &capturingComponent))
586 return NULL;
587 _rv = CaptureComponent(_self->ob_itself,
588 capturingComponent);
589 _res = Py_BuildValue("O&",
590 CmpObj_New, _rv);
591 return _res;
594 static PyObject *CmpObj_UncaptureComponent(_self, _args)
595 ComponentObject *_self;
596 PyObject *_args;
598 PyObject *_res = NULL;
599 OSErr _err;
600 if (!PyArg_ParseTuple(_args, ""))
601 return NULL;
602 _err = UncaptureComponent(_self->ob_itself);
603 if (_err != noErr) return PyMac_Error(_err);
604 Py_INCREF(Py_None);
605 _res = Py_None;
606 return _res;
609 static PyObject *CmpObj_GetComponentIconSuite(_self, _args)
610 ComponentObject *_self;
611 PyObject *_args;
613 PyObject *_res = NULL;
614 OSErr _err;
615 Handle iconSuite;
616 if (!PyArg_ParseTuple(_args, ""))
617 return NULL;
618 _err = GetComponentIconSuite(_self->ob_itself,
619 &iconSuite);
620 if (_err != noErr) return PyMac_Error(_err);
621 _res = Py_BuildValue("O&",
622 ResObj_New, iconSuite);
623 return _res;
626 static PyMethodDef CmpObj_methods[] = {
627 {"UnregisterComponent", (PyCFunction)CmpObj_UnregisterComponent, 1,
628 "() -> None"},
629 {"GetComponentInfo", (PyCFunction)CmpObj_GetComponentInfo, 1,
630 "(Handle componentName, Handle componentInfo, Handle componentIcon) -> (ComponentDescription cd)"},
631 {"OpenComponent", (PyCFunction)CmpObj_OpenComponent, 1,
632 "() -> (ComponentInstance _rv)"},
633 {"GetComponentRefcon", (PyCFunction)CmpObj_GetComponentRefcon, 1,
634 "() -> (long _rv)"},
635 {"SetComponentRefcon", (PyCFunction)CmpObj_SetComponentRefcon, 1,
636 "(long theRefcon) -> None"},
637 {"OpenComponentResFile", (PyCFunction)CmpObj_OpenComponentResFile, 1,
638 "() -> (short _rv)"},
639 {"GetComponentResource", (PyCFunction)CmpObj_GetComponentResource, 1,
640 "(OSType resType, short resID) -> (Handle theResource)"},
641 {"GetComponentIndString", (PyCFunction)CmpObj_GetComponentIndString, 1,
642 "(Str255 theString, short strListID, short index) -> None"},
643 {"ResolveComponentAlias", (PyCFunction)CmpObj_ResolveComponentAlias, 1,
644 "() -> (Component _rv)"},
645 {"CountComponentInstances", (PyCFunction)CmpObj_CountComponentInstances, 1,
646 "() -> (long _rv)"},
647 {"SetDefaultComponent", (PyCFunction)CmpObj_SetDefaultComponent, 1,
648 "(short flags) -> None"},
649 {"CaptureComponent", (PyCFunction)CmpObj_CaptureComponent, 1,
650 "(Component capturingComponent) -> (Component _rv)"},
651 {"UncaptureComponent", (PyCFunction)CmpObj_UncaptureComponent, 1,
652 "() -> None"},
653 {"GetComponentIconSuite", (PyCFunction)CmpObj_GetComponentIconSuite, 1,
654 "() -> (Handle iconSuite)"},
655 {NULL, NULL, 0}
658 PyMethodChain CmpObj_chain = { CmpObj_methods, NULL };
660 static PyObject *CmpObj_getattr(self, name)
661 ComponentObject *self;
662 char *name;
664 return Py_FindMethodInChain(&CmpObj_chain, (PyObject *)self, name);
667 #define CmpObj_setattr NULL
669 #define CmpObj_compare NULL
671 #define CmpObj_repr NULL
673 #define CmpObj_hash NULL
675 PyTypeObject Component_Type = {
676 PyObject_HEAD_INIT(&PyType_Type)
677 0, /*ob_size*/
678 "Component", /*tp_name*/
679 sizeof(ComponentObject), /*tp_basicsize*/
680 0, /*tp_itemsize*/
681 /* methods */
682 (destructor) CmpObj_dealloc, /*tp_dealloc*/
683 0, /*tp_print*/
684 (getattrfunc) CmpObj_getattr, /*tp_getattr*/
685 (setattrfunc) CmpObj_setattr, /*tp_setattr*/
686 (cmpfunc) CmpObj_compare, /*tp_compare*/
687 (reprfunc) CmpObj_repr, /*tp_repr*/
688 (PyNumberMethods *)0, /* tp_as_number */
689 (PySequenceMethods *)0, /* tp_as_sequence */
690 (PyMappingMethods *)0, /* tp_as_mapping */
691 (hashfunc) CmpObj_hash, /*tp_hash*/
694 /* ------------------- End object type Component -------------------- */
697 static PyObject *Cm_RegisterComponentResource(_self, _args)
698 PyObject *_self;
699 PyObject *_args;
701 PyObject *_res = NULL;
702 Component _rv;
703 ComponentResourceHandle cr;
704 short global;
705 if (!PyArg_ParseTuple(_args, "O&h",
706 ResObj_Convert, &cr,
707 &global))
708 return NULL;
709 _rv = RegisterComponentResource(cr,
710 global);
711 _res = Py_BuildValue("O&",
712 CmpObj_New, _rv);
713 return _res;
716 static PyObject *Cm_FindNextComponent(_self, _args)
717 PyObject *_self;
718 PyObject *_args;
720 PyObject *_res = NULL;
721 Component _rv;
722 Component aComponent;
723 ComponentDescription looking;
724 if (!PyArg_ParseTuple(_args, "O&O&",
725 CmpObj_Convert, &aComponent,
726 CmpDesc_Convert, &looking))
727 return NULL;
728 _rv = FindNextComponent(aComponent,
729 &looking);
730 _res = Py_BuildValue("O&",
731 CmpObj_New, _rv);
732 return _res;
735 static PyObject *Cm_CountComponents(_self, _args)
736 PyObject *_self;
737 PyObject *_args;
739 PyObject *_res = NULL;
740 long _rv;
741 ComponentDescription looking;
742 if (!PyArg_ParseTuple(_args, "O&",
743 CmpDesc_Convert, &looking))
744 return NULL;
745 _rv = CountComponents(&looking);
746 _res = Py_BuildValue("l",
747 _rv);
748 return _res;
751 static PyObject *Cm_GetComponentListModSeed(_self, _args)
752 PyObject *_self;
753 PyObject *_args;
755 PyObject *_res = NULL;
756 long _rv;
757 if (!PyArg_ParseTuple(_args, ""))
758 return NULL;
759 _rv = GetComponentListModSeed();
760 _res = Py_BuildValue("l",
761 _rv);
762 return _res;
765 static PyObject *Cm_CloseComponentResFile(_self, _args)
766 PyObject *_self;
767 PyObject *_args;
769 PyObject *_res = NULL;
770 OSErr _err;
771 short refnum;
772 if (!PyArg_ParseTuple(_args, "h",
773 &refnum))
774 return NULL;
775 _err = CloseComponentResFile(refnum);
776 if (_err != noErr) return PyMac_Error(_err);
777 Py_INCREF(Py_None);
778 _res = Py_None;
779 return _res;
782 static PyObject *Cm_OpenDefaultComponent(_self, _args)
783 PyObject *_self;
784 PyObject *_args;
786 PyObject *_res = NULL;
787 ComponentInstance _rv;
788 OSType componentType;
789 OSType componentSubType;
790 if (!PyArg_ParseTuple(_args, "O&O&",
791 PyMac_GetOSType, &componentType,
792 PyMac_GetOSType, &componentSubType))
793 return NULL;
794 _rv = OpenDefaultComponent(componentType,
795 componentSubType);
796 _res = Py_BuildValue("O&",
797 CmpInstObj_New, _rv);
798 return _res;
801 static PyObject *Cm_RegisterComponentResourceFile(_self, _args)
802 PyObject *_self;
803 PyObject *_args;
805 PyObject *_res = NULL;
806 long _rv;
807 short resRefNum;
808 short global;
809 if (!PyArg_ParseTuple(_args, "hh",
810 &resRefNum,
811 &global))
812 return NULL;
813 _rv = RegisterComponentResourceFile(resRefNum,
814 global);
815 _res = Py_BuildValue("l",
816 _rv);
817 return _res;
820 static PyMethodDef Cm_methods[] = {
821 {"RegisterComponentResource", (PyCFunction)Cm_RegisterComponentResource, 1,
822 "(ComponentResourceHandle cr, short global) -> (Component _rv)"},
823 {"FindNextComponent", (PyCFunction)Cm_FindNextComponent, 1,
824 "(Component aComponent, ComponentDescription looking) -> (Component _rv)"},
825 {"CountComponents", (PyCFunction)Cm_CountComponents, 1,
826 "(ComponentDescription looking) -> (long _rv)"},
827 {"GetComponentListModSeed", (PyCFunction)Cm_GetComponentListModSeed, 1,
828 "() -> (long _rv)"},
829 {"CloseComponentResFile", (PyCFunction)Cm_CloseComponentResFile, 1,
830 "(short refnum) -> None"},
831 {"OpenDefaultComponent", (PyCFunction)Cm_OpenDefaultComponent, 1,
832 "(OSType componentType, OSType componentSubType) -> (ComponentInstance _rv)"},
833 {"RegisterComponentResourceFile", (PyCFunction)Cm_RegisterComponentResourceFile, 1,
834 "(short resRefNum, short global) -> (long _rv)"},
835 {NULL, NULL, 0}
841 void initCm()
843 PyObject *m;
844 PyObject *d;
849 m = Py_InitModule("Cm", Cm_methods);
850 d = PyModule_GetDict(m);
851 Cm_Error = PyMac_GetOSErrException();
852 if (Cm_Error == NULL ||
853 PyDict_SetItemString(d, "Error", Cm_Error) != 0)
854 Py_FatalError("can't initialize Cm.Error");
855 ComponentInstance_Type.ob_type = &PyType_Type;
856 Py_INCREF(&ComponentInstance_Type);
857 if (PyDict_SetItemString(d, "ComponentInstanceType", (PyObject *)&ComponentInstance_Type) != 0)
858 Py_FatalError("can't initialize ComponentInstanceType");
859 Component_Type.ob_type = &PyType_Type;
860 Py_INCREF(&Component_Type);
861 if (PyDict_SetItemString(d, "ComponentType", (PyObject *)&Component_Type) != 0)
862 Py_FatalError("can't initialize ComponentType");
865 /* ========================= End module Cm ========================== */