2 /* =========================== Module _Cm =========================== */
9 #include "pywintoolbox.h"
12 #include "pymactoolbox.h"
15 /* Macro to test whether a weak-loaded CFM function exists */
16 #define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
17 PyErr_SetString(PyExc_NotImplementedError, \
18 "Not available in this shared library/OS version"); \
23 #ifdef WITHOUT_FRAMEWORKS
24 #include <Components.h>
26 #include <Carbon/Carbon.h>
29 #ifdef USE_TOOLBOX_OBJECT_GLUE
30 extern PyObject
*_CmpObj_New(Component
);
31 extern int _CmpObj_Convert(PyObject
*, Component
*);
32 extern PyObject
*_CmpInstObj_New(ComponentInstance
);
33 extern int _CmpInstObj_Convert(PyObject
*, ComponentInstance
*);
35 #define CmpObj_New _CmpObj_New
36 #define CmpObj_Convert _CmpObj_Convert
37 #define CmpInstObj_New _CmpInstObj_New
38 #define CmpInstObj_Convert _CmpInstObj_Convert
42 ** Parse/generate ComponentDescriptor records
45 CmpDesc_New(ComponentDescription
*itself
)
48 return Py_BuildValue("O&O&O&ll",
49 PyMac_BuildOSType
, itself
->componentType
,
50 PyMac_BuildOSType
, itself
->componentSubType
,
51 PyMac_BuildOSType
, itself
->componentManufacturer
,
52 itself
->componentFlags
, itself
->componentFlagsMask
);
56 CmpDesc_Convert(PyObject
*v
, ComponentDescription
*p_itself
)
58 return PyArg_ParseTuple(v
, "O&O&O&ll",
59 PyMac_GetOSType
, &p_itself
->componentType
,
60 PyMac_GetOSType
, &p_itself
->componentSubType
,
61 PyMac_GetOSType
, &p_itself
->componentManufacturer
,
62 &p_itself
->componentFlags
, &p_itself
->componentFlagsMask
);
66 static PyObject
*Cm_Error
;
68 /* ----------------- Object type ComponentInstance ------------------ */
70 PyTypeObject ComponentInstance_Type
;
72 #define CmpInstObj_Check(x) ((x)->ob_type == &ComponentInstance_Type)
74 typedef struct ComponentInstanceObject
{
76 ComponentInstance ob_itself
;
77 } ComponentInstanceObject
;
79 PyObject
*CmpInstObj_New(ComponentInstance itself
)
81 ComponentInstanceObject
*it
;
83 PyErr_SetString(Cm_Error
,"NULL ComponentInstance");
86 it
= PyObject_NEW(ComponentInstanceObject
, &ComponentInstance_Type
);
87 if (it
== NULL
) return NULL
;
88 it
->ob_itself
= itself
;
89 return (PyObject
*)it
;
91 int CmpInstObj_Convert(PyObject
*v
, ComponentInstance
*p_itself
)
93 if (!CmpInstObj_Check(v
))
95 PyErr_SetString(PyExc_TypeError
, "ComponentInstance required");
98 *p_itself
= ((ComponentInstanceObject
*)v
)->ob_itself
;
102 static void CmpInstObj_dealloc(ComponentInstanceObject
*self
)
104 /* Cleanup of self->ob_itself goes here */
108 static PyObject
*CmpInstObj_CloseComponent(ComponentInstanceObject
*_self
, PyObject
*_args
)
110 PyObject
*_res
= NULL
;
112 #ifndef CloseComponent
113 PyMac_PRECHECK(CloseComponent
);
115 if (!PyArg_ParseTuple(_args
, ""))
117 _err
= CloseComponent(_self
->ob_itself
);
118 if (_err
!= noErr
) return PyMac_Error(_err
);
124 static PyObject
*CmpInstObj_GetComponentInstanceError(ComponentInstanceObject
*_self
, PyObject
*_args
)
126 PyObject
*_res
= NULL
;
128 #ifndef GetComponentInstanceError
129 PyMac_PRECHECK(GetComponentInstanceError
);
131 if (!PyArg_ParseTuple(_args
, ""))
133 _err
= GetComponentInstanceError(_self
->ob_itself
);
134 if (_err
!= noErr
) return PyMac_Error(_err
);
140 static PyObject
*CmpInstObj_SetComponentInstanceError(ComponentInstanceObject
*_self
, PyObject
*_args
)
142 PyObject
*_res
= NULL
;
144 #ifndef SetComponentInstanceError
145 PyMac_PRECHECK(SetComponentInstanceError
);
147 if (!PyArg_ParseTuple(_args
, "h",
150 SetComponentInstanceError(_self
->ob_itself
,
157 static PyObject
*CmpInstObj_GetComponentInstanceStorage(ComponentInstanceObject
*_self
, PyObject
*_args
)
159 PyObject
*_res
= NULL
;
161 #ifndef GetComponentInstanceStorage
162 PyMac_PRECHECK(GetComponentInstanceStorage
);
164 if (!PyArg_ParseTuple(_args
, ""))
166 _rv
= GetComponentInstanceStorage(_self
->ob_itself
);
167 _res
= Py_BuildValue("O&",
172 static PyObject
*CmpInstObj_SetComponentInstanceStorage(ComponentInstanceObject
*_self
, PyObject
*_args
)
174 PyObject
*_res
= NULL
;
176 #ifndef SetComponentInstanceStorage
177 PyMac_PRECHECK(SetComponentInstanceStorage
);
179 if (!PyArg_ParseTuple(_args
, "O&",
180 ResObj_Convert
, &theStorage
))
182 SetComponentInstanceStorage(_self
->ob_itself
,
189 #if !TARGET_API_MAC_CARBON
191 static PyObject
*CmpInstObj_GetComponentInstanceA5(ComponentInstanceObject
*_self
, PyObject
*_args
)
193 PyObject
*_res
= NULL
;
195 #ifndef GetComponentInstanceA5
196 PyMac_PRECHECK(GetComponentInstanceA5
);
198 if (!PyArg_ParseTuple(_args
, ""))
200 _rv
= GetComponentInstanceA5(_self
->ob_itself
);
201 _res
= Py_BuildValue("l",
207 #if !TARGET_API_MAC_CARBON
209 static PyObject
*CmpInstObj_SetComponentInstanceA5(ComponentInstanceObject
*_self
, PyObject
*_args
)
211 PyObject
*_res
= NULL
;
213 #ifndef SetComponentInstanceA5
214 PyMac_PRECHECK(SetComponentInstanceA5
);
216 if (!PyArg_ParseTuple(_args
, "l",
219 SetComponentInstanceA5(_self
->ob_itself
,
227 static PyObject
*CmpInstObj_ComponentFunctionImplemented(ComponentInstanceObject
*_self
, PyObject
*_args
)
229 PyObject
*_res
= NULL
;
232 #ifndef ComponentFunctionImplemented
233 PyMac_PRECHECK(ComponentFunctionImplemented
);
235 if (!PyArg_ParseTuple(_args
, "h",
238 _rv
= ComponentFunctionImplemented(_self
->ob_itself
,
240 _res
= Py_BuildValue("l",
245 static PyObject
*CmpInstObj_GetComponentVersion(ComponentInstanceObject
*_self
, PyObject
*_args
)
247 PyObject
*_res
= NULL
;
249 #ifndef GetComponentVersion
250 PyMac_PRECHECK(GetComponentVersion
);
252 if (!PyArg_ParseTuple(_args
, ""))
254 _rv
= GetComponentVersion(_self
->ob_itself
);
255 _res
= Py_BuildValue("l",
260 static PyObject
*CmpInstObj_ComponentSetTarget(ComponentInstanceObject
*_self
, PyObject
*_args
)
262 PyObject
*_res
= NULL
;
264 ComponentInstance target
;
265 #ifndef ComponentSetTarget
266 PyMac_PRECHECK(ComponentSetTarget
);
268 if (!PyArg_ParseTuple(_args
, "O&",
269 CmpInstObj_Convert
, &target
))
271 _rv
= ComponentSetTarget(_self
->ob_itself
,
273 _res
= Py_BuildValue("l",
278 static PyMethodDef CmpInstObj_methods
[] = {
279 {"CloseComponent", (PyCFunction
)CmpInstObj_CloseComponent
, 1,
281 {"GetComponentInstanceError", (PyCFunction
)CmpInstObj_GetComponentInstanceError
, 1,
283 {"SetComponentInstanceError", (PyCFunction
)CmpInstObj_SetComponentInstanceError
, 1,
284 "(OSErr theError) -> None"},
285 {"GetComponentInstanceStorage", (PyCFunction
)CmpInstObj_GetComponentInstanceStorage
, 1,
286 "() -> (Handle _rv)"},
287 {"SetComponentInstanceStorage", (PyCFunction
)CmpInstObj_SetComponentInstanceStorage
, 1,
288 "(Handle theStorage) -> None"},
290 #if !TARGET_API_MAC_CARBON
291 {"GetComponentInstanceA5", (PyCFunction
)CmpInstObj_GetComponentInstanceA5
, 1,
295 #if !TARGET_API_MAC_CARBON
296 {"SetComponentInstanceA5", (PyCFunction
)CmpInstObj_SetComponentInstanceA5
, 1,
297 "(long theA5) -> None"},
299 {"ComponentFunctionImplemented", (PyCFunction
)CmpInstObj_ComponentFunctionImplemented
, 1,
300 "(short ftnNumber) -> (long _rv)"},
301 {"GetComponentVersion", (PyCFunction
)CmpInstObj_GetComponentVersion
, 1,
303 {"ComponentSetTarget", (PyCFunction
)CmpInstObj_ComponentSetTarget
, 1,
304 "(ComponentInstance target) -> (long _rv)"},
308 PyMethodChain CmpInstObj_chain
= { CmpInstObj_methods
, NULL
};
310 static PyObject
*CmpInstObj_getattr(ComponentInstanceObject
*self
, char *name
)
312 return Py_FindMethodInChain(&CmpInstObj_chain
, (PyObject
*)self
, name
);
315 #define CmpInstObj_setattr NULL
317 #define CmpInstObj_compare NULL
319 #define CmpInstObj_repr NULL
321 #define CmpInstObj_hash NULL
323 PyTypeObject ComponentInstance_Type
= {
324 PyObject_HEAD_INIT(NULL
)
326 "_Cm.ComponentInstance", /*tp_name*/
327 sizeof(ComponentInstanceObject
), /*tp_basicsize*/
330 (destructor
) CmpInstObj_dealloc
, /*tp_dealloc*/
332 (getattrfunc
) CmpInstObj_getattr
, /*tp_getattr*/
333 (setattrfunc
) CmpInstObj_setattr
, /*tp_setattr*/
334 (cmpfunc
) CmpInstObj_compare
, /*tp_compare*/
335 (reprfunc
) CmpInstObj_repr
, /*tp_repr*/
336 (PyNumberMethods
*)0, /* tp_as_number */
337 (PySequenceMethods
*)0, /* tp_as_sequence */
338 (PyMappingMethods
*)0, /* tp_as_mapping */
339 (hashfunc
) CmpInstObj_hash
, /*tp_hash*/
342 /* --------------- End object type ComponentInstance ---------------- */
345 /* --------------------- Object type Component ---------------------- */
347 PyTypeObject Component_Type
;
349 #define CmpObj_Check(x) ((x)->ob_type == &Component_Type)
351 typedef struct ComponentObject
{
356 PyObject
*CmpObj_New(Component itself
)
359 if (itself
== NULL
) {
360 /* XXXX Or should we return None? */
361 PyErr_SetString(Cm_Error
,"No such component");
364 it
= PyObject_NEW(ComponentObject
, &Component_Type
);
365 if (it
== NULL
) return NULL
;
366 it
->ob_itself
= itself
;
367 return (PyObject
*)it
;
369 int CmpObj_Convert(PyObject
*v
, Component
*p_itself
)
371 if ( v
== Py_None
) {
375 if (!CmpObj_Check(v
))
377 PyErr_SetString(PyExc_TypeError
, "Component required");
380 *p_itself
= ((ComponentObject
*)v
)->ob_itself
;
384 static void CmpObj_dealloc(ComponentObject
*self
)
386 /* Cleanup of self->ob_itself goes here */
390 static PyObject
*CmpObj_UnregisterComponent(ComponentObject
*_self
, PyObject
*_args
)
392 PyObject
*_res
= NULL
;
394 #ifndef UnregisterComponent
395 PyMac_PRECHECK(UnregisterComponent
);
397 if (!PyArg_ParseTuple(_args
, ""))
399 _err
= UnregisterComponent(_self
->ob_itself
);
400 if (_err
!= noErr
) return PyMac_Error(_err
);
406 static PyObject
*CmpObj_GetComponentInfo(ComponentObject
*_self
, PyObject
*_args
)
408 PyObject
*_res
= NULL
;
410 ComponentDescription cd
;
411 Handle componentName
;
412 Handle componentInfo
;
413 Handle componentIcon
;
414 #ifndef GetComponentInfo
415 PyMac_PRECHECK(GetComponentInfo
);
417 if (!PyArg_ParseTuple(_args
, "O&O&O&",
418 ResObj_Convert
, &componentName
,
419 ResObj_Convert
, &componentInfo
,
420 ResObj_Convert
, &componentIcon
))
422 _err
= GetComponentInfo(_self
->ob_itself
,
427 if (_err
!= noErr
) return PyMac_Error(_err
);
428 _res
= Py_BuildValue("O&",
433 static PyObject
*CmpObj_OpenComponent(ComponentObject
*_self
, PyObject
*_args
)
435 PyObject
*_res
= NULL
;
436 ComponentInstance _rv
;
437 #ifndef OpenComponent
438 PyMac_PRECHECK(OpenComponent
);
440 if (!PyArg_ParseTuple(_args
, ""))
442 _rv
= OpenComponent(_self
->ob_itself
);
443 _res
= Py_BuildValue("O&",
444 CmpInstObj_New
, _rv
);
448 static PyObject
*CmpObj_ResolveComponentAlias(ComponentObject
*_self
, PyObject
*_args
)
450 PyObject
*_res
= NULL
;
452 #ifndef ResolveComponentAlias
453 PyMac_PRECHECK(ResolveComponentAlias
);
455 if (!PyArg_ParseTuple(_args
, ""))
457 _rv
= ResolveComponentAlias(_self
->ob_itself
);
458 _res
= Py_BuildValue("O&",
463 static PyObject
*CmpObj_GetComponentPublicIndString(ComponentObject
*_self
, PyObject
*_args
)
465 PyObject
*_res
= NULL
;
470 #ifndef GetComponentPublicIndString
471 PyMac_PRECHECK(GetComponentPublicIndString
);
473 if (!PyArg_ParseTuple(_args
, "O&hh",
474 PyMac_GetStr255
, theString
,
478 _err
= GetComponentPublicIndString(_self
->ob_itself
,
482 if (_err
!= noErr
) return PyMac_Error(_err
);
488 static PyObject
*CmpObj_GetComponentRefcon(ComponentObject
*_self
, PyObject
*_args
)
490 PyObject
*_res
= NULL
;
492 #ifndef GetComponentRefcon
493 PyMac_PRECHECK(GetComponentRefcon
);
495 if (!PyArg_ParseTuple(_args
, ""))
497 _rv
= GetComponentRefcon(_self
->ob_itself
);
498 _res
= Py_BuildValue("l",
503 static PyObject
*CmpObj_SetComponentRefcon(ComponentObject
*_self
, PyObject
*_args
)
505 PyObject
*_res
= NULL
;
507 #ifndef SetComponentRefcon
508 PyMac_PRECHECK(SetComponentRefcon
);
510 if (!PyArg_ParseTuple(_args
, "l",
513 SetComponentRefcon(_self
->ob_itself
,
520 static PyObject
*CmpObj_OpenComponentResFile(ComponentObject
*_self
, PyObject
*_args
)
522 PyObject
*_res
= NULL
;
524 #ifndef OpenComponentResFile
525 PyMac_PRECHECK(OpenComponentResFile
);
527 if (!PyArg_ParseTuple(_args
, ""))
529 _rv
= OpenComponentResFile(_self
->ob_itself
);
530 _res
= Py_BuildValue("h",
535 static PyObject
*CmpObj_GetComponentResource(ComponentObject
*_self
, PyObject
*_args
)
537 PyObject
*_res
= NULL
;
542 #ifndef GetComponentResource
543 PyMac_PRECHECK(GetComponentResource
);
545 if (!PyArg_ParseTuple(_args
, "O&h",
546 PyMac_GetOSType
, &resType
,
549 _err
= GetComponentResource(_self
->ob_itself
,
553 if (_err
!= noErr
) return PyMac_Error(_err
);
554 _res
= Py_BuildValue("O&",
555 ResObj_New
, theResource
);
559 static PyObject
*CmpObj_GetComponentIndString(ComponentObject
*_self
, PyObject
*_args
)
561 PyObject
*_res
= NULL
;
566 #ifndef GetComponentIndString
567 PyMac_PRECHECK(GetComponentIndString
);
569 if (!PyArg_ParseTuple(_args
, "O&hh",
570 PyMac_GetStr255
, theString
,
574 _err
= GetComponentIndString(_self
->ob_itself
,
578 if (_err
!= noErr
) return PyMac_Error(_err
);
584 static PyObject
*CmpObj_CountComponentInstances(ComponentObject
*_self
, PyObject
*_args
)
586 PyObject
*_res
= NULL
;
588 #ifndef CountComponentInstances
589 PyMac_PRECHECK(CountComponentInstances
);
591 if (!PyArg_ParseTuple(_args
, ""))
593 _rv
= CountComponentInstances(_self
->ob_itself
);
594 _res
= Py_BuildValue("l",
599 static PyObject
*CmpObj_SetDefaultComponent(ComponentObject
*_self
, PyObject
*_args
)
601 PyObject
*_res
= NULL
;
604 #ifndef SetDefaultComponent
605 PyMac_PRECHECK(SetDefaultComponent
);
607 if (!PyArg_ParseTuple(_args
, "h",
610 _err
= SetDefaultComponent(_self
->ob_itself
,
612 if (_err
!= noErr
) return PyMac_Error(_err
);
618 static PyObject
*CmpObj_CaptureComponent(ComponentObject
*_self
, PyObject
*_args
)
620 PyObject
*_res
= NULL
;
622 Component capturingComponent
;
623 #ifndef CaptureComponent
624 PyMac_PRECHECK(CaptureComponent
);
626 if (!PyArg_ParseTuple(_args
, "O&",
627 CmpObj_Convert
, &capturingComponent
))
629 _rv
= CaptureComponent(_self
->ob_itself
,
631 _res
= Py_BuildValue("O&",
636 static PyObject
*CmpObj_UncaptureComponent(ComponentObject
*_self
, PyObject
*_args
)
638 PyObject
*_res
= NULL
;
640 #ifndef UncaptureComponent
641 PyMac_PRECHECK(UncaptureComponent
);
643 if (!PyArg_ParseTuple(_args
, ""))
645 _err
= UncaptureComponent(_self
->ob_itself
);
646 if (_err
!= noErr
) return PyMac_Error(_err
);
652 static PyObject
*CmpObj_GetComponentIconSuite(ComponentObject
*_self
, PyObject
*_args
)
654 PyObject
*_res
= NULL
;
657 #ifndef GetComponentIconSuite
658 PyMac_PRECHECK(GetComponentIconSuite
);
660 if (!PyArg_ParseTuple(_args
, ""))
662 _err
= GetComponentIconSuite(_self
->ob_itself
,
664 if (_err
!= noErr
) return PyMac_Error(_err
);
665 _res
= Py_BuildValue("O&",
666 ResObj_New
, iconSuite
);
670 static PyMethodDef CmpObj_methods
[] = {
671 {"UnregisterComponent", (PyCFunction
)CmpObj_UnregisterComponent
, 1,
673 {"GetComponentInfo", (PyCFunction
)CmpObj_GetComponentInfo
, 1,
674 "(Handle componentName, Handle componentInfo, Handle componentIcon) -> (ComponentDescription cd)"},
675 {"OpenComponent", (PyCFunction
)CmpObj_OpenComponent
, 1,
676 "() -> (ComponentInstance _rv)"},
677 {"ResolveComponentAlias", (PyCFunction
)CmpObj_ResolveComponentAlias
, 1,
678 "() -> (Component _rv)"},
679 {"GetComponentPublicIndString", (PyCFunction
)CmpObj_GetComponentPublicIndString
, 1,
680 "(Str255 theString, short strListID, short index) -> None"},
681 {"GetComponentRefcon", (PyCFunction
)CmpObj_GetComponentRefcon
, 1,
683 {"SetComponentRefcon", (PyCFunction
)CmpObj_SetComponentRefcon
, 1,
684 "(long theRefcon) -> None"},
685 {"OpenComponentResFile", (PyCFunction
)CmpObj_OpenComponentResFile
, 1,
686 "() -> (short _rv)"},
687 {"GetComponentResource", (PyCFunction
)CmpObj_GetComponentResource
, 1,
688 "(OSType resType, short resID) -> (Handle theResource)"},
689 {"GetComponentIndString", (PyCFunction
)CmpObj_GetComponentIndString
, 1,
690 "(Str255 theString, short strListID, short index) -> None"},
691 {"CountComponentInstances", (PyCFunction
)CmpObj_CountComponentInstances
, 1,
693 {"SetDefaultComponent", (PyCFunction
)CmpObj_SetDefaultComponent
, 1,
694 "(short flags) -> None"},
695 {"CaptureComponent", (PyCFunction
)CmpObj_CaptureComponent
, 1,
696 "(Component capturingComponent) -> (Component _rv)"},
697 {"UncaptureComponent", (PyCFunction
)CmpObj_UncaptureComponent
, 1,
699 {"GetComponentIconSuite", (PyCFunction
)CmpObj_GetComponentIconSuite
, 1,
700 "() -> (Handle iconSuite)"},
704 PyMethodChain CmpObj_chain
= { CmpObj_methods
, NULL
};
706 static PyObject
*CmpObj_getattr(ComponentObject
*self
, char *name
)
708 return Py_FindMethodInChain(&CmpObj_chain
, (PyObject
*)self
, name
);
711 #define CmpObj_setattr NULL
713 #define CmpObj_compare NULL
715 #define CmpObj_repr NULL
717 #define CmpObj_hash NULL
719 PyTypeObject Component_Type
= {
720 PyObject_HEAD_INIT(NULL
)
722 "_Cm.Component", /*tp_name*/
723 sizeof(ComponentObject
), /*tp_basicsize*/
726 (destructor
) CmpObj_dealloc
, /*tp_dealloc*/
728 (getattrfunc
) CmpObj_getattr
, /*tp_getattr*/
729 (setattrfunc
) CmpObj_setattr
, /*tp_setattr*/
730 (cmpfunc
) CmpObj_compare
, /*tp_compare*/
731 (reprfunc
) CmpObj_repr
, /*tp_repr*/
732 (PyNumberMethods
*)0, /* tp_as_number */
733 (PySequenceMethods
*)0, /* tp_as_sequence */
734 (PyMappingMethods
*)0, /* tp_as_mapping */
735 (hashfunc
) CmpObj_hash
, /*tp_hash*/
738 /* ------------------- End object type Component -------------------- */
741 static PyObject
*Cm_RegisterComponentResource(PyObject
*_self
, PyObject
*_args
)
743 PyObject
*_res
= NULL
;
745 ComponentResourceHandle cr
;
747 #ifndef RegisterComponentResource
748 PyMac_PRECHECK(RegisterComponentResource
);
750 if (!PyArg_ParseTuple(_args
, "O&h",
754 _rv
= RegisterComponentResource(cr
,
756 _res
= Py_BuildValue("O&",
761 static PyObject
*Cm_FindNextComponent(PyObject
*_self
, PyObject
*_args
)
763 PyObject
*_res
= NULL
;
765 Component aComponent
;
766 ComponentDescription looking
;
767 #ifndef FindNextComponent
768 PyMac_PRECHECK(FindNextComponent
);
770 if (!PyArg_ParseTuple(_args
, "O&O&",
771 CmpObj_Convert
, &aComponent
,
772 CmpDesc_Convert
, &looking
))
774 _rv
= FindNextComponent(aComponent
,
776 _res
= Py_BuildValue("O&",
781 static PyObject
*Cm_CountComponents(PyObject
*_self
, PyObject
*_args
)
783 PyObject
*_res
= NULL
;
785 ComponentDescription looking
;
786 #ifndef CountComponents
787 PyMac_PRECHECK(CountComponents
);
789 if (!PyArg_ParseTuple(_args
, "O&",
790 CmpDesc_Convert
, &looking
))
792 _rv
= CountComponents(&looking
);
793 _res
= Py_BuildValue("l",
798 static PyObject
*Cm_GetComponentListModSeed(PyObject
*_self
, PyObject
*_args
)
800 PyObject
*_res
= NULL
;
802 #ifndef GetComponentListModSeed
803 PyMac_PRECHECK(GetComponentListModSeed
);
805 if (!PyArg_ParseTuple(_args
, ""))
807 _rv
= GetComponentListModSeed();
808 _res
= Py_BuildValue("l",
813 static PyObject
*Cm_CloseComponentResFile(PyObject
*_self
, PyObject
*_args
)
815 PyObject
*_res
= NULL
;
818 #ifndef CloseComponentResFile
819 PyMac_PRECHECK(CloseComponentResFile
);
821 if (!PyArg_ParseTuple(_args
, "h",
824 _err
= CloseComponentResFile(refnum
);
825 if (_err
!= noErr
) return PyMac_Error(_err
);
831 static PyObject
*Cm_OpenDefaultComponent(PyObject
*_self
, PyObject
*_args
)
833 PyObject
*_res
= NULL
;
834 ComponentInstance _rv
;
835 OSType componentType
;
836 OSType componentSubType
;
837 #ifndef OpenDefaultComponent
838 PyMac_PRECHECK(OpenDefaultComponent
);
840 if (!PyArg_ParseTuple(_args
, "O&O&",
841 PyMac_GetOSType
, &componentType
,
842 PyMac_GetOSType
, &componentSubType
))
844 _rv
= OpenDefaultComponent(componentType
,
846 _res
= Py_BuildValue("O&",
847 CmpInstObj_New
, _rv
);
851 static PyObject
*Cm_RegisterComponentResourceFile(PyObject
*_self
, PyObject
*_args
)
853 PyObject
*_res
= NULL
;
857 #ifndef RegisterComponentResourceFile
858 PyMac_PRECHECK(RegisterComponentResourceFile
);
860 if (!PyArg_ParseTuple(_args
, "hh",
864 _rv
= RegisterComponentResourceFile(resRefNum
,
866 _res
= Py_BuildValue("l",
871 static PyMethodDef Cm_methods
[] = {
872 {"RegisterComponentResource", (PyCFunction
)Cm_RegisterComponentResource
, 1,
873 "(ComponentResourceHandle cr, short global) -> (Component _rv)"},
874 {"FindNextComponent", (PyCFunction
)Cm_FindNextComponent
, 1,
875 "(Component aComponent, ComponentDescription looking) -> (Component _rv)"},
876 {"CountComponents", (PyCFunction
)Cm_CountComponents
, 1,
877 "(ComponentDescription looking) -> (long _rv)"},
878 {"GetComponentListModSeed", (PyCFunction
)Cm_GetComponentListModSeed
, 1,
880 {"CloseComponentResFile", (PyCFunction
)Cm_CloseComponentResFile
, 1,
881 "(short refnum) -> None"},
882 {"OpenDefaultComponent", (PyCFunction
)Cm_OpenDefaultComponent
, 1,
883 "(OSType componentType, OSType componentSubType) -> (ComponentInstance _rv)"},
884 {"RegisterComponentResourceFile", (PyCFunction
)Cm_RegisterComponentResourceFile
, 1,
885 "(short resRefNum, short global) -> (long _rv)"},
899 PyMac_INIT_TOOLBOX_OBJECT_NEW(Component
, CmpObj_New
);
900 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(Component
, CmpObj_Convert
);
901 PyMac_INIT_TOOLBOX_OBJECT_NEW(ComponentInstance
, CmpInstObj_New
);
902 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(ComponentInstance
, CmpInstObj_Convert
);
905 m
= Py_InitModule("_Cm", Cm_methods
);
906 d
= PyModule_GetDict(m
);
907 Cm_Error
= PyMac_GetOSErrException();
908 if (Cm_Error
== NULL
||
909 PyDict_SetItemString(d
, "Error", Cm_Error
) != 0)
911 ComponentInstance_Type
.ob_type
= &PyType_Type
;
912 Py_INCREF(&ComponentInstance_Type
);
913 if (PyDict_SetItemString(d
, "ComponentInstanceType", (PyObject
*)&ComponentInstance_Type
) != 0)
914 Py_FatalError("can't initialize ComponentInstanceType");
915 Component_Type
.ob_type
= &PyType_Type
;
916 Py_INCREF(&Component_Type
);
917 if (PyDict_SetItemString(d
, "ComponentType", (PyObject
*)&Component_Type
) != 0)
918 Py_FatalError("can't initialize ComponentType");
921 /* ========================= End module _Cm ========================= */