mirror of https://github.com/python/cpython.git
Component mgr support
This commit is contained in:
parent
41058c0d0b
commit
b996856d12
|
@ -0,0 +1,45 @@
|
|||
"""cmtest - List all components in the system"""
|
||||
|
||||
import Cm
|
||||
import Res
|
||||
import sys
|
||||
|
||||
def getstr255(r):
|
||||
"""Get string from str255 resource"""
|
||||
if not r.data: return ''
|
||||
len = ord(r.data[0])
|
||||
return r.data[1:1+len]
|
||||
|
||||
def getinfo(c):
|
||||
"""Return (type, subtype, creator, fl1, fl2, name, description) for component"""
|
||||
h1 = Res.Resource('')
|
||||
h2 = Res.Resource('')
|
||||
h3 = Res.Resource('')
|
||||
type, subtype, creator, fl1, fl2 = c.GetComponentInfo(h1, h2, h3)
|
||||
name = getstr255(h1)
|
||||
description = getstr255(h2)
|
||||
return type, subtype, creator, fl1, fl2, name, description
|
||||
|
||||
def getallcomponents():
|
||||
"""Return list with info for all components, sorted"""
|
||||
any = ('\0\0\0\0', '\0\0\0\0', '\0\0\0\0', 0, 0)
|
||||
c = None
|
||||
rv = []
|
||||
while 1:
|
||||
try:
|
||||
c = Cm.FindNextComponent(c, any)
|
||||
except Cm.Error:
|
||||
break
|
||||
rv.append(getinfo(c))
|
||||
rv.sort()
|
||||
return rv
|
||||
|
||||
def main():
|
||||
"""Print info for all components"""
|
||||
info = getallcomponents()
|
||||
for type, subtype, creator, f1, f2, name, description in info:
|
||||
print '%4.4s %4.4s %4.4s %s 0x%x 0x%x'%(type, subtype, creator, name, f1, f2)
|
||||
print ' ', description
|
||||
sys.exit(1)
|
||||
|
||||
main()
|
|
@ -0,0 +1,23 @@
|
|||
# Generated from 'Sap:CodeWarrior7:Metrowerks CodeWarrior:MacOS Support:Headers:Universal Headers:Components.h'
|
||||
|
||||
kAppleManufacturer = 'appl'
|
||||
kComponentResourceType = 'thng'
|
||||
kAnyComponentType = 0
|
||||
kAnyComponentSubType = 0
|
||||
kAnyComponentManufacturer = 0
|
||||
kAnyComponentFlagsMask = 0
|
||||
cmpWantsRegisterMessage = 1L << 31
|
||||
kComponentOpenSelect = -1
|
||||
kComponentCloseSelect = -2
|
||||
kComponentCanDoSelect = -3
|
||||
kComponentVersionSelect = -4
|
||||
kComponentRegisterSelect = -5
|
||||
kComponentTargetSelect = -6
|
||||
kComponentUnregisterSelect = -7
|
||||
defaultComponentIdentical = 0
|
||||
defaultComponentAnyFlags = 1
|
||||
defaultComponentAnyManufacturer = 2
|
||||
defaultComponentAnySubType = 4
|
||||
registerComponentGlobal = 1
|
||||
registerComponentNoDuplicates = 2
|
||||
registerComponentAfterExisting = 4
|
|
@ -0,0 +1,158 @@
|
|||
# Generated from 'Sap:CodeWarrior7:Metrowerks CodeWarrior:MacOS Support:Headers:Universal Headers:Components.h'
|
||||
|
||||
f = Function(Component, 'RegisterComponentResource',
|
||||
(ComponentResourceHandle, 'tr', InMode),
|
||||
(short, 'global', InMode),
|
||||
)
|
||||
functions.append(f)
|
||||
|
||||
f = Method(OSErr, 'UnregisterComponent',
|
||||
(Component, 'aComponent', InMode),
|
||||
)
|
||||
c_methods.append(f)
|
||||
|
||||
f = Function(Component, 'FindNextComponent',
|
||||
(Component, 'aComponent', InMode),
|
||||
(ComponentDescription, 'looking', InMode),
|
||||
)
|
||||
functions.append(f)
|
||||
|
||||
f = Function(long, 'CountComponents',
|
||||
(ComponentDescription, 'looking', InMode),
|
||||
)
|
||||
functions.append(f)
|
||||
|
||||
f = Method(OSErr, 'GetComponentInfo',
|
||||
(Component, 'aComponent', InMode),
|
||||
(ComponentDescription, 'cd', OutMode),
|
||||
(Handle, 'componentName', InMode),
|
||||
(Handle, 'componentInfo', InMode),
|
||||
(Handle, 'componentIcon', InMode),
|
||||
)
|
||||
c_methods.append(f)
|
||||
|
||||
f = Function(long, 'GetComponentListModSeed',
|
||||
)
|
||||
functions.append(f)
|
||||
|
||||
f = Method(ComponentInstance, 'OpenComponent',
|
||||
(Component, 'aComponent', InMode),
|
||||
)
|
||||
c_methods.append(f)
|
||||
|
||||
f = Method(OSErr, 'CloseComponent',
|
||||
(ComponentInstance, 'aComponentInstance', InMode),
|
||||
)
|
||||
ci_methods.append(f)
|
||||
|
||||
f = Method(OSErr, 'GetComponentInstanceError',
|
||||
(ComponentInstance, 'aComponentInstance', InMode),
|
||||
)
|
||||
ci_methods.append(f)
|
||||
|
||||
f = Method(long, 'ComponentFunctionImplemented',
|
||||
(ComponentInstance, 'ci', InMode),
|
||||
(short, 'ftnNumber', InMode),
|
||||
)
|
||||
ci_methods.append(f)
|
||||
|
||||
f = Method(long, 'GetComponentVersion',
|
||||
(ComponentInstance, 'ci', InMode),
|
||||
)
|
||||
ci_methods.append(f)
|
||||
|
||||
f = Method(long, 'ComponentSetTarget',
|
||||
(ComponentInstance, 'ci', InMode),
|
||||
(ComponentInstance, 'target', InMode),
|
||||
)
|
||||
ci_methods.append(f)
|
||||
|
||||
f = Method(void, 'SetComponentInstanceError',
|
||||
(ComponentInstance, 'aComponentInstance', InMode),
|
||||
(OSErr, 'theError', InMode),
|
||||
)
|
||||
ci_methods.append(f)
|
||||
|
||||
f = Method(long, 'GetComponentRefcon',
|
||||
(Component, 'aComponent', InMode),
|
||||
)
|
||||
c_methods.append(f)
|
||||
|
||||
f = Method(void, 'SetComponentRefcon',
|
||||
(Component, 'aComponent', InMode),
|
||||
(long, 'theRefcon', InMode),
|
||||
)
|
||||
c_methods.append(f)
|
||||
|
||||
f = Method(short, 'OpenComponentResFile',
|
||||
(Component, 'aComponent', InMode),
|
||||
)
|
||||
c_methods.append(f)
|
||||
|
||||
f = Function(OSErr, 'CloseComponentResFile',
|
||||
(short, 'refnum', InMode),
|
||||
)
|
||||
functions.append(f)
|
||||
|
||||
f = Method(Handle, 'GetComponentInstanceStorage',
|
||||
(ComponentInstance, 'aComponentInstance', InMode),
|
||||
)
|
||||
ci_methods.append(f)
|
||||
|
||||
f = Method(void, 'SetComponentInstanceStorage',
|
||||
(ComponentInstance, 'aComponentInstance', InMode),
|
||||
(Handle, 'theStorage', InMode),
|
||||
)
|
||||
ci_methods.append(f)
|
||||
|
||||
f = Method(long, 'GetComponentInstanceA5',
|
||||
(ComponentInstance, 'aComponentInstance', InMode),
|
||||
)
|
||||
ci_methods.append(f)
|
||||
|
||||
f = Method(void, 'SetComponentInstanceA5',
|
||||
(ComponentInstance, 'aComponentInstance', InMode),
|
||||
(long, 'theA5', InMode),
|
||||
)
|
||||
ci_methods.append(f)
|
||||
|
||||
f = Method(long, 'CountComponentInstances',
|
||||
(Component, 'aComponent', InMode),
|
||||
)
|
||||
c_methods.append(f)
|
||||
|
||||
f = Method(OSErr, 'SetDefaultComponent',
|
||||
(Component, 'aComponent', InMode),
|
||||
(short, 'flags', InMode),
|
||||
)
|
||||
c_methods.append(f)
|
||||
|
||||
f = Function(ComponentInstance, 'OpenDefaultComponent',
|
||||
(OSType, 'componentType', InMode),
|
||||
(OSType, 'componentSubType', InMode),
|
||||
)
|
||||
functions.append(f)
|
||||
|
||||
f = Method(Component, 'CaptureComponent',
|
||||
(Component, 'capturedComponent', InMode),
|
||||
(Component, 'capturingComponent', InMode),
|
||||
)
|
||||
c_methods.append(f)
|
||||
|
||||
f = Method(OSErr, 'UncaptureComponent',
|
||||
(Component, 'aComponent', InMode),
|
||||
)
|
||||
c_methods.append(f)
|
||||
|
||||
f = Function(long, 'RegisterComponentResourceFile',
|
||||
(short, 'resRefNum', InMode),
|
||||
(short, 'global', InMode),
|
||||
)
|
||||
functions.append(f)
|
||||
|
||||
f = Method(OSErr, 'GetComponentIconSuite',
|
||||
(Component, 'aComponent', InMode),
|
||||
(Handle, 'iconSuite', OutMode),
|
||||
)
|
||||
c_methods.append(f)
|
||||
|
|
@ -0,0 +1,766 @@
|
|||
|
||||
/* =========================== Module Cm ============================ */
|
||||
|
||||
#include "Python.h"
|
||||
|
||||
|
||||
|
||||
#define SystemSevenOrLater 1
|
||||
|
||||
#include "macglue.h"
|
||||
#include <Memory.h>
|
||||
#include <Dialogs.h>
|
||||
#include <Menus.h>
|
||||
#include <Controls.h>
|
||||
|
||||
extern PyObject *ResObj_New(Handle);
|
||||
extern PyObject *ResObj_OptNew(Handle);
|
||||
extern int ResObj_Convert(PyObject *, Handle *);
|
||||
|
||||
extern PyObject *WinObj_New(WindowPtr);
|
||||
extern int WinObj_Convert(PyObject *, WindowPtr *);
|
||||
extern PyTypeObject Window_Type;
|
||||
#define WinObj_Check(x) ((x)->ob_type == &Window_Type)
|
||||
|
||||
extern PyObject *DlgObj_New(DialogPtr);
|
||||
extern int DlgObj_Convert(PyObject *, DialogPtr *);
|
||||
extern PyTypeObject Dialog_Type;
|
||||
#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
|
||||
|
||||
extern PyObject *MenuObj_New(MenuHandle);
|
||||
extern int MenuObj_Convert(PyObject *, MenuHandle *);
|
||||
|
||||
extern PyObject *CtlObj_New(ControlHandle);
|
||||
extern int CtlObj_Convert(PyObject *, ControlHandle *);
|
||||
|
||||
extern PyObject *GrafObj_New(GrafPtr);
|
||||
extern int GrafObj_Convert(PyObject *, GrafPtr *);
|
||||
|
||||
extern PyObject *BMObj_New(BitMapPtr);
|
||||
extern int BMObj_Convert(PyObject *, BitMapPtr *);
|
||||
|
||||
extern PyObject *WinObj_WhichWindow(WindowPtr);
|
||||
|
||||
#include <Components.h>
|
||||
|
||||
/*
|
||||
** Parse/generate ComponentDescriptor records
|
||||
*/
|
||||
PyObject *CmpDesc_New(itself)
|
||||
ComponentDescription *itself;
|
||||
{
|
||||
|
||||
return Py_BuildValue("O&O&O&ll",
|
||||
PyMac_BuildOSType, itself->componentType,
|
||||
PyMac_BuildOSType, itself->componentSubType,
|
||||
PyMac_BuildOSType, itself->componentManufacturer,
|
||||
itself->componentFlags, itself->componentFlagsMask);
|
||||
}
|
||||
|
||||
CmpDesc_Convert(v, p_itself)
|
||||
PyObject *v;
|
||||
ComponentDescription *p_itself;
|
||||
{
|
||||
return PyArg_ParseTuple(v, "O&O&O&ll",
|
||||
PyMac_GetOSType, &p_itself->componentType,
|
||||
PyMac_GetOSType, &p_itself->componentSubType,
|
||||
PyMac_GetOSType, &p_itself->componentManufacturer,
|
||||
&p_itself->componentFlags, &p_itself->componentFlagsMask);
|
||||
}
|
||||
|
||||
|
||||
static PyObject *Cm_Error;
|
||||
|
||||
/* ----------------- Object type ComponentInstance ------------------ */
|
||||
|
||||
PyTypeObject ComponentInstance_Type;
|
||||
|
||||
#define CmpInstObj_Check(x) ((x)->ob_type == &ComponentInstance_Type)
|
||||
|
||||
typedef struct ComponentInstanceObject {
|
||||
PyObject_HEAD
|
||||
ComponentInstance ob_itself;
|
||||
} ComponentInstanceObject;
|
||||
|
||||
PyObject *CmpInstObj_New(itself)
|
||||
ComponentInstance itself;
|
||||
{
|
||||
ComponentInstanceObject *it;
|
||||
if (itself == NULL) {
|
||||
PyErr_SetString(Cm_Error,"NULL ComponentInstance");
|
||||
return NULL;
|
||||
}
|
||||
it = PyObject_NEW(ComponentInstanceObject, &ComponentInstance_Type);
|
||||
if (it == NULL) return NULL;
|
||||
it->ob_itself = itself;
|
||||
return (PyObject *)it;
|
||||
}
|
||||
CmpInstObj_Convert(v, p_itself)
|
||||
PyObject *v;
|
||||
ComponentInstance *p_itself;
|
||||
{
|
||||
if (!CmpInstObj_Check(v))
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "ComponentInstance required");
|
||||
return 0;
|
||||
}
|
||||
*p_itself = ((ComponentInstanceObject *)v)->ob_itself;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void CmpInstObj_dealloc(self)
|
||||
ComponentInstanceObject *self;
|
||||
{
|
||||
/* Cleanup of self->ob_itself goes here */
|
||||
PyMem_DEL(self);
|
||||
}
|
||||
|
||||
static PyObject *CmpInstObj_CloseComponent(_self, _args)
|
||||
ComponentInstanceObject *_self;
|
||||
PyObject *_args;
|
||||
{
|
||||
PyObject *_res = NULL;
|
||||
OSErr _err;
|
||||
if (!PyArg_ParseTuple(_args, ""))
|
||||
return NULL;
|
||||
_err = CloseComponent(_self->ob_itself);
|
||||
if (_err != noErr) return PyMac_Error(_err);
|
||||
Py_INCREF(Py_None);
|
||||
_res = Py_None;
|
||||
return _res;
|
||||
}
|
||||
|
||||
static PyObject *CmpInstObj_GetComponentInstanceError(_self, _args)
|
||||
ComponentInstanceObject *_self;
|
||||
PyObject *_args;
|
||||
{
|
||||
PyObject *_res = NULL;
|
||||
OSErr _err;
|
||||
if (!PyArg_ParseTuple(_args, ""))
|
||||
return NULL;
|
||||
_err = GetComponentInstanceError(_self->ob_itself);
|
||||
if (_err != noErr) return PyMac_Error(_err);
|
||||
Py_INCREF(Py_None);
|
||||
_res = Py_None;
|
||||
return _res;
|
||||
}
|
||||
|
||||
static PyObject *CmpInstObj_ComponentFunctionImplemented(_self, _args)
|
||||
ComponentInstanceObject *_self;
|
||||
PyObject *_args;
|
||||
{
|
||||
PyObject *_res = NULL;
|
||||
long _rv;
|
||||
short ftnNumber;
|
||||
if (!PyArg_ParseTuple(_args, "h",
|
||||
&ftnNumber))
|
||||
return NULL;
|
||||
_rv = ComponentFunctionImplemented(_self->ob_itself,
|
||||
ftnNumber);
|
||||
_res = Py_BuildValue("l",
|
||||
_rv);
|
||||
return _res;
|
||||
}
|
||||
|
||||
static PyObject *CmpInstObj_GetComponentVersion(_self, _args)
|
||||
ComponentInstanceObject *_self;
|
||||
PyObject *_args;
|
||||
{
|
||||
PyObject *_res = NULL;
|
||||
long _rv;
|
||||
if (!PyArg_ParseTuple(_args, ""))
|
||||
return NULL;
|
||||
_rv = GetComponentVersion(_self->ob_itself);
|
||||
_res = Py_BuildValue("l",
|
||||
_rv);
|
||||
return _res;
|
||||
}
|
||||
|
||||
static PyObject *CmpInstObj_ComponentSetTarget(_self, _args)
|
||||
ComponentInstanceObject *_self;
|
||||
PyObject *_args;
|
||||
{
|
||||
PyObject *_res = NULL;
|
||||
long _rv;
|
||||
ComponentInstance target;
|
||||
if (!PyArg_ParseTuple(_args, "O&",
|
||||
CmpInstObj_Convert, &target))
|
||||
return NULL;
|
||||
_rv = ComponentSetTarget(_self->ob_itself,
|
||||
target);
|
||||
_res = Py_BuildValue("l",
|
||||
_rv);
|
||||
return _res;
|
||||
}
|
||||
|
||||
static PyObject *CmpInstObj_SetComponentInstanceError(_self, _args)
|
||||
ComponentInstanceObject *_self;
|
||||
PyObject *_args;
|
||||
{
|
||||
PyObject *_res = NULL;
|
||||
OSErr theError;
|
||||
if (!PyArg_ParseTuple(_args, "h",
|
||||
&theError))
|
||||
return NULL;
|
||||
SetComponentInstanceError(_self->ob_itself,
|
||||
theError);
|
||||
Py_INCREF(Py_None);
|
||||
_res = Py_None;
|
||||
return _res;
|
||||
}
|
||||
|
||||
static PyObject *CmpInstObj_GetComponentInstanceStorage(_self, _args)
|
||||
ComponentInstanceObject *_self;
|
||||
PyObject *_args;
|
||||
{
|
||||
PyObject *_res = NULL;
|
||||
Handle _rv;
|
||||
if (!PyArg_ParseTuple(_args, ""))
|
||||
return NULL;
|
||||
_rv = GetComponentInstanceStorage(_self->ob_itself);
|
||||
_res = Py_BuildValue("O&",
|
||||
ResObj_New, _rv);
|
||||
return _res;
|
||||
}
|
||||
|
||||
static PyObject *CmpInstObj_SetComponentInstanceStorage(_self, _args)
|
||||
ComponentInstanceObject *_self;
|
||||
PyObject *_args;
|
||||
{
|
||||
PyObject *_res = NULL;
|
||||
Handle theStorage;
|
||||
if (!PyArg_ParseTuple(_args, "O&",
|
||||
ResObj_Convert, &theStorage))
|
||||
return NULL;
|
||||
SetComponentInstanceStorage(_self->ob_itself,
|
||||
theStorage);
|
||||
Py_INCREF(Py_None);
|
||||
_res = Py_None;
|
||||
return _res;
|
||||
}
|
||||
|
||||
static PyObject *CmpInstObj_GetComponentInstanceA5(_self, _args)
|
||||
ComponentInstanceObject *_self;
|
||||
PyObject *_args;
|
||||
{
|
||||
PyObject *_res = NULL;
|
||||
long _rv;
|
||||
if (!PyArg_ParseTuple(_args, ""))
|
||||
return NULL;
|
||||
_rv = GetComponentInstanceA5(_self->ob_itself);
|
||||
_res = Py_BuildValue("l",
|
||||
_rv);
|
||||
return _res;
|
||||
}
|
||||
|
||||
static PyObject *CmpInstObj_SetComponentInstanceA5(_self, _args)
|
||||
ComponentInstanceObject *_self;
|
||||
PyObject *_args;
|
||||
{
|
||||
PyObject *_res = NULL;
|
||||
long theA5;
|
||||
if (!PyArg_ParseTuple(_args, "l",
|
||||
&theA5))
|
||||
return NULL;
|
||||
SetComponentInstanceA5(_self->ob_itself,
|
||||
theA5);
|
||||
Py_INCREF(Py_None);
|
||||
_res = Py_None;
|
||||
return _res;
|
||||
}
|
||||
|
||||
static PyMethodDef CmpInstObj_methods[] = {
|
||||
{"CloseComponent", (PyCFunction)CmpInstObj_CloseComponent, 1,
|
||||
"() -> None"},
|
||||
{"GetComponentInstanceError", (PyCFunction)CmpInstObj_GetComponentInstanceError, 1,
|
||||
"() -> None"},
|
||||
{"ComponentFunctionImplemented", (PyCFunction)CmpInstObj_ComponentFunctionImplemented, 1,
|
||||
"(short ftnNumber) -> (long _rv)"},
|
||||
{"GetComponentVersion", (PyCFunction)CmpInstObj_GetComponentVersion, 1,
|
||||
"() -> (long _rv)"},
|
||||
{"ComponentSetTarget", (PyCFunction)CmpInstObj_ComponentSetTarget, 1,
|
||||
"(ComponentInstance target) -> (long _rv)"},
|
||||
{"SetComponentInstanceError", (PyCFunction)CmpInstObj_SetComponentInstanceError, 1,
|
||||
"(OSErr theError) -> None"},
|
||||
{"GetComponentInstanceStorage", (PyCFunction)CmpInstObj_GetComponentInstanceStorage, 1,
|
||||
"() -> (Handle _rv)"},
|
||||
{"SetComponentInstanceStorage", (PyCFunction)CmpInstObj_SetComponentInstanceStorage, 1,
|
||||
"(Handle theStorage) -> None"},
|
||||
{"GetComponentInstanceA5", (PyCFunction)CmpInstObj_GetComponentInstanceA5, 1,
|
||||
"() -> (long _rv)"},
|
||||
{"SetComponentInstanceA5", (PyCFunction)CmpInstObj_SetComponentInstanceA5, 1,
|
||||
"(long theA5) -> None"},
|
||||
{NULL, NULL, 0}
|
||||
};
|
||||
|
||||
PyMethodChain CmpInstObj_chain = { CmpInstObj_methods, NULL };
|
||||
|
||||
static PyObject *CmpInstObj_getattr(self, name)
|
||||
ComponentInstanceObject *self;
|
||||
char *name;
|
||||
{
|
||||
return Py_FindMethodInChain(&CmpInstObj_chain, (PyObject *)self, name);
|
||||
}
|
||||
|
||||
#define CmpInstObj_setattr NULL
|
||||
|
||||
PyTypeObject ComponentInstance_Type = {
|
||||
PyObject_HEAD_INIT(&PyType_Type)
|
||||
0, /*ob_size*/
|
||||
"ComponentInstance", /*tp_name*/
|
||||
sizeof(ComponentInstanceObject), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
/* methods */
|
||||
(destructor) CmpInstObj_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
(getattrfunc) CmpInstObj_getattr, /*tp_getattr*/
|
||||
(setattrfunc) CmpInstObj_setattr, /*tp_setattr*/
|
||||
};
|
||||
|
||||
/* --------------- End object type ComponentInstance ---------------- */
|
||||
|
||||
|
||||
/* --------------------- Object type Component ---------------------- */
|
||||
|
||||
PyTypeObject Component_Type;
|
||||
|
||||
#define CmpObj_Check(x) ((x)->ob_type == &Component_Type)
|
||||
|
||||
typedef struct ComponentObject {
|
||||
PyObject_HEAD
|
||||
Component ob_itself;
|
||||
} ComponentObject;
|
||||
|
||||
PyObject *CmpObj_New(itself)
|
||||
Component itself;
|
||||
{
|
||||
ComponentObject *it;
|
||||
if (itself == NULL) {
|
||||
/* XXXX Or should we return None? */
|
||||
PyErr_SetString(Cm_Error,"No such component");
|
||||
return NULL;
|
||||
}
|
||||
it = PyObject_NEW(ComponentObject, &Component_Type);
|
||||
if (it == NULL) return NULL;
|
||||
it->ob_itself = itself;
|
||||
return (PyObject *)it;
|
||||
}
|
||||
CmpObj_Convert(v, p_itself)
|
||||
PyObject *v;
|
||||
Component *p_itself;
|
||||
{
|
||||
if ( v == Py_None ) {
|
||||
*p_itself = 0;
|
||||
return 1;
|
||||
}
|
||||
if (!CmpObj_Check(v))
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "Component required");
|
||||
return 0;
|
||||
}
|
||||
*p_itself = ((ComponentObject *)v)->ob_itself;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void CmpObj_dealloc(self)
|
||||
ComponentObject *self;
|
||||
{
|
||||
/* Cleanup of self->ob_itself goes here */
|
||||
PyMem_DEL(self);
|
||||
}
|
||||
|
||||
static PyObject *CmpObj_UnregisterComponent(_self, _args)
|
||||
ComponentObject *_self;
|
||||
PyObject *_args;
|
||||
{
|
||||
PyObject *_res = NULL;
|
||||
OSErr _err;
|
||||
if (!PyArg_ParseTuple(_args, ""))
|
||||
return NULL;
|
||||
_err = UnregisterComponent(_self->ob_itself);
|
||||
if (_err != noErr) return PyMac_Error(_err);
|
||||
Py_INCREF(Py_None);
|
||||
_res = Py_None;
|
||||
return _res;
|
||||
}
|
||||
|
||||
static PyObject *CmpObj_GetComponentInfo(_self, _args)
|
||||
ComponentObject *_self;
|
||||
PyObject *_args;
|
||||
{
|
||||
PyObject *_res = NULL;
|
||||
OSErr _err;
|
||||
ComponentDescription cd;
|
||||
Handle componentName;
|
||||
Handle componentInfo;
|
||||
Handle componentIcon;
|
||||
if (!PyArg_ParseTuple(_args, "O&O&O&",
|
||||
ResObj_Convert, &componentName,
|
||||
ResObj_Convert, &componentInfo,
|
||||
ResObj_Convert, &componentIcon))
|
||||
return NULL;
|
||||
_err = GetComponentInfo(_self->ob_itself,
|
||||
&cd,
|
||||
componentName,
|
||||
componentInfo,
|
||||
componentIcon);
|
||||
if (_err != noErr) return PyMac_Error(_err);
|
||||
_res = Py_BuildValue("O&",
|
||||
CmpDesc_New, &cd);
|
||||
return _res;
|
||||
}
|
||||
|
||||
static PyObject *CmpObj_OpenComponent(_self, _args)
|
||||
ComponentObject *_self;
|
||||
PyObject *_args;
|
||||
{
|
||||
PyObject *_res = NULL;
|
||||
ComponentInstance _rv;
|
||||
if (!PyArg_ParseTuple(_args, ""))
|
||||
return NULL;
|
||||
_rv = OpenComponent(_self->ob_itself);
|
||||
_res = Py_BuildValue("O&",
|
||||
CmpInstObj_New, _rv);
|
||||
return _res;
|
||||
}
|
||||
|
||||
static PyObject *CmpObj_GetComponentRefcon(_self, _args)
|
||||
ComponentObject *_self;
|
||||
PyObject *_args;
|
||||
{
|
||||
PyObject *_res = NULL;
|
||||
long _rv;
|
||||
if (!PyArg_ParseTuple(_args, ""))
|
||||
return NULL;
|
||||
_rv = GetComponentRefcon(_self->ob_itself);
|
||||
_res = Py_BuildValue("l",
|
||||
_rv);
|
||||
return _res;
|
||||
}
|
||||
|
||||
static PyObject *CmpObj_SetComponentRefcon(_self, _args)
|
||||
ComponentObject *_self;
|
||||
PyObject *_args;
|
||||
{
|
||||
PyObject *_res = NULL;
|
||||
long theRefcon;
|
||||
if (!PyArg_ParseTuple(_args, "l",
|
||||
&theRefcon))
|
||||
return NULL;
|
||||
SetComponentRefcon(_self->ob_itself,
|
||||
theRefcon);
|
||||
Py_INCREF(Py_None);
|
||||
_res = Py_None;
|
||||
return _res;
|
||||
}
|
||||
|
||||
static PyObject *CmpObj_OpenComponentResFile(_self, _args)
|
||||
ComponentObject *_self;
|
||||
PyObject *_args;
|
||||
{
|
||||
PyObject *_res = NULL;
|
||||
short _rv;
|
||||
if (!PyArg_ParseTuple(_args, ""))
|
||||
return NULL;
|
||||
_rv = OpenComponentResFile(_self->ob_itself);
|
||||
_res = Py_BuildValue("h",
|
||||
_rv);
|
||||
return _res;
|
||||
}
|
||||
|
||||
static PyObject *CmpObj_CountComponentInstances(_self, _args)
|
||||
ComponentObject *_self;
|
||||
PyObject *_args;
|
||||
{
|
||||
PyObject *_res = NULL;
|
||||
long _rv;
|
||||
if (!PyArg_ParseTuple(_args, ""))
|
||||
return NULL;
|
||||
_rv = CountComponentInstances(_self->ob_itself);
|
||||
_res = Py_BuildValue("l",
|
||||
_rv);
|
||||
return _res;
|
||||
}
|
||||
|
||||
static PyObject *CmpObj_SetDefaultComponent(_self, _args)
|
||||
ComponentObject *_self;
|
||||
PyObject *_args;
|
||||
{
|
||||
PyObject *_res = NULL;
|
||||
OSErr _err;
|
||||
short flags;
|
||||
if (!PyArg_ParseTuple(_args, "h",
|
||||
&flags))
|
||||
return NULL;
|
||||
_err = SetDefaultComponent(_self->ob_itself,
|
||||
flags);
|
||||
if (_err != noErr) return PyMac_Error(_err);
|
||||
Py_INCREF(Py_None);
|
||||
_res = Py_None;
|
||||
return _res;
|
||||
}
|
||||
|
||||
static PyObject *CmpObj_CaptureComponent(_self, _args)
|
||||
ComponentObject *_self;
|
||||
PyObject *_args;
|
||||
{
|
||||
PyObject *_res = NULL;
|
||||
Component _rv;
|
||||
Component capturingComponent;
|
||||
if (!PyArg_ParseTuple(_args, "O&",
|
||||
CmpObj_Convert, &capturingComponent))
|
||||
return NULL;
|
||||
_rv = CaptureComponent(_self->ob_itself,
|
||||
capturingComponent);
|
||||
_res = Py_BuildValue("O&",
|
||||
CmpObj_New, _rv);
|
||||
return _res;
|
||||
}
|
||||
|
||||
static PyObject *CmpObj_UncaptureComponent(_self, _args)
|
||||
ComponentObject *_self;
|
||||
PyObject *_args;
|
||||
{
|
||||
PyObject *_res = NULL;
|
||||
OSErr _err;
|
||||
if (!PyArg_ParseTuple(_args, ""))
|
||||
return NULL;
|
||||
_err = UncaptureComponent(_self->ob_itself);
|
||||
if (_err != noErr) return PyMac_Error(_err);
|
||||
Py_INCREF(Py_None);
|
||||
_res = Py_None;
|
||||
return _res;
|
||||
}
|
||||
|
||||
static PyObject *CmpObj_GetComponentIconSuite(_self, _args)
|
||||
ComponentObject *_self;
|
||||
PyObject *_args;
|
||||
{
|
||||
PyObject *_res = NULL;
|
||||
OSErr _err;
|
||||
Handle iconSuite;
|
||||
if (!PyArg_ParseTuple(_args, ""))
|
||||
return NULL;
|
||||
_err = GetComponentIconSuite(_self->ob_itself,
|
||||
&iconSuite);
|
||||
if (_err != noErr) return PyMac_Error(_err);
|
||||
_res = Py_BuildValue("O&",
|
||||
ResObj_New, iconSuite);
|
||||
return _res;
|
||||
}
|
||||
|
||||
static PyMethodDef CmpObj_methods[] = {
|
||||
{"UnregisterComponent", (PyCFunction)CmpObj_UnregisterComponent, 1,
|
||||
"() -> None"},
|
||||
{"GetComponentInfo", (PyCFunction)CmpObj_GetComponentInfo, 1,
|
||||
"(Handle componentName, Handle componentInfo, Handle componentIcon) -> (ComponentDescription cd)"},
|
||||
{"OpenComponent", (PyCFunction)CmpObj_OpenComponent, 1,
|
||||
"() -> (ComponentInstance _rv)"},
|
||||
{"GetComponentRefcon", (PyCFunction)CmpObj_GetComponentRefcon, 1,
|
||||
"() -> (long _rv)"},
|
||||
{"SetComponentRefcon", (PyCFunction)CmpObj_SetComponentRefcon, 1,
|
||||
"(long theRefcon) -> None"},
|
||||
{"OpenComponentResFile", (PyCFunction)CmpObj_OpenComponentResFile, 1,
|
||||
"() -> (short _rv)"},
|
||||
{"CountComponentInstances", (PyCFunction)CmpObj_CountComponentInstances, 1,
|
||||
"() -> (long _rv)"},
|
||||
{"SetDefaultComponent", (PyCFunction)CmpObj_SetDefaultComponent, 1,
|
||||
"(short flags) -> None"},
|
||||
{"CaptureComponent", (PyCFunction)CmpObj_CaptureComponent, 1,
|
||||
"(Component capturingComponent) -> (Component _rv)"},
|
||||
{"UncaptureComponent", (PyCFunction)CmpObj_UncaptureComponent, 1,
|
||||
"() -> None"},
|
||||
{"GetComponentIconSuite", (PyCFunction)CmpObj_GetComponentIconSuite, 1,
|
||||
"() -> (Handle iconSuite)"},
|
||||
{NULL, NULL, 0}
|
||||
};
|
||||
|
||||
PyMethodChain CmpObj_chain = { CmpObj_methods, NULL };
|
||||
|
||||
static PyObject *CmpObj_getattr(self, name)
|
||||
ComponentObject *self;
|
||||
char *name;
|
||||
{
|
||||
return Py_FindMethodInChain(&CmpObj_chain, (PyObject *)self, name);
|
||||
}
|
||||
|
||||
#define CmpObj_setattr NULL
|
||||
|
||||
PyTypeObject Component_Type = {
|
||||
PyObject_HEAD_INIT(&PyType_Type)
|
||||
0, /*ob_size*/
|
||||
"Component", /*tp_name*/
|
||||
sizeof(ComponentObject), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
/* methods */
|
||||
(destructor) CmpObj_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
(getattrfunc) CmpObj_getattr, /*tp_getattr*/
|
||||
(setattrfunc) CmpObj_setattr, /*tp_setattr*/
|
||||
};
|
||||
|
||||
/* ------------------- End object type Component -------------------- */
|
||||
|
||||
|
||||
static PyObject *Cm_RegisterComponentResource(_self, _args)
|
||||
PyObject *_self;
|
||||
PyObject *_args;
|
||||
{
|
||||
PyObject *_res = NULL;
|
||||
Component _rv;
|
||||
ComponentResourceHandle tr;
|
||||
short global;
|
||||
if (!PyArg_ParseTuple(_args, "O&h",
|
||||
ResObj_Convert, &tr,
|
||||
&global))
|
||||
return NULL;
|
||||
_rv = RegisterComponentResource(tr,
|
||||
global);
|
||||
_res = Py_BuildValue("O&",
|
||||
CmpObj_New, _rv);
|
||||
return _res;
|
||||
}
|
||||
|
||||
static PyObject *Cm_FindNextComponent(_self, _args)
|
||||
PyObject *_self;
|
||||
PyObject *_args;
|
||||
{
|
||||
PyObject *_res = NULL;
|
||||
Component _rv;
|
||||
Component aComponent;
|
||||
ComponentDescription looking;
|
||||
if (!PyArg_ParseTuple(_args, "O&O&",
|
||||
CmpObj_Convert, &aComponent,
|
||||
CmpDesc_Convert, &looking))
|
||||
return NULL;
|
||||
_rv = FindNextComponent(aComponent,
|
||||
&looking);
|
||||
_res = Py_BuildValue("O&",
|
||||
CmpObj_New, _rv);
|
||||
return _res;
|
||||
}
|
||||
|
||||
static PyObject *Cm_CountComponents(_self, _args)
|
||||
PyObject *_self;
|
||||
PyObject *_args;
|
||||
{
|
||||
PyObject *_res = NULL;
|
||||
long _rv;
|
||||
ComponentDescription looking;
|
||||
if (!PyArg_ParseTuple(_args, "O&",
|
||||
CmpDesc_Convert, &looking))
|
||||
return NULL;
|
||||
_rv = CountComponents(&looking);
|
||||
_res = Py_BuildValue("l",
|
||||
_rv);
|
||||
return _res;
|
||||
}
|
||||
|
||||
static PyObject *Cm_GetComponentListModSeed(_self, _args)
|
||||
PyObject *_self;
|
||||
PyObject *_args;
|
||||
{
|
||||
PyObject *_res = NULL;
|
||||
long _rv;
|
||||
if (!PyArg_ParseTuple(_args, ""))
|
||||
return NULL;
|
||||
_rv = GetComponentListModSeed();
|
||||
_res = Py_BuildValue("l",
|
||||
_rv);
|
||||
return _res;
|
||||
}
|
||||
|
||||
static PyObject *Cm_CloseComponentResFile(_self, _args)
|
||||
PyObject *_self;
|
||||
PyObject *_args;
|
||||
{
|
||||
PyObject *_res = NULL;
|
||||
OSErr _err;
|
||||
short refnum;
|
||||
if (!PyArg_ParseTuple(_args, "h",
|
||||
&refnum))
|
||||
return NULL;
|
||||
_err = CloseComponentResFile(refnum);
|
||||
if (_err != noErr) return PyMac_Error(_err);
|
||||
Py_INCREF(Py_None);
|
||||
_res = Py_None;
|
||||
return _res;
|
||||
}
|
||||
|
||||
static PyObject *Cm_OpenDefaultComponent(_self, _args)
|
||||
PyObject *_self;
|
||||
PyObject *_args;
|
||||
{
|
||||
PyObject *_res = NULL;
|
||||
ComponentInstance _rv;
|
||||
OSType componentType;
|
||||
OSType componentSubType;
|
||||
if (!PyArg_ParseTuple(_args, "O&O&",
|
||||
PyMac_GetOSType, &componentType,
|
||||
PyMac_GetOSType, &componentSubType))
|
||||
return NULL;
|
||||
_rv = OpenDefaultComponent(componentType,
|
||||
componentSubType);
|
||||
_res = Py_BuildValue("O&",
|
||||
CmpInstObj_New, _rv);
|
||||
return _res;
|
||||
}
|
||||
|
||||
static PyObject *Cm_RegisterComponentResourceFile(_self, _args)
|
||||
PyObject *_self;
|
||||
PyObject *_args;
|
||||
{
|
||||
PyObject *_res = NULL;
|
||||
long _rv;
|
||||
short resRefNum;
|
||||
short global;
|
||||
if (!PyArg_ParseTuple(_args, "hh",
|
||||
&resRefNum,
|
||||
&global))
|
||||
return NULL;
|
||||
_rv = RegisterComponentResourceFile(resRefNum,
|
||||
global);
|
||||
_res = Py_BuildValue("l",
|
||||
_rv);
|
||||
return _res;
|
||||
}
|
||||
|
||||
static PyMethodDef Cm_methods[] = {
|
||||
{"RegisterComponentResource", (PyCFunction)Cm_RegisterComponentResource, 1,
|
||||
"(ComponentResourceHandle tr, short global) -> (Component _rv)"},
|
||||
{"FindNextComponent", (PyCFunction)Cm_FindNextComponent, 1,
|
||||
"(Component aComponent, ComponentDescription looking) -> (Component _rv)"},
|
||||
{"CountComponents", (PyCFunction)Cm_CountComponents, 1,
|
||||
"(ComponentDescription looking) -> (long _rv)"},
|
||||
{"GetComponentListModSeed", (PyCFunction)Cm_GetComponentListModSeed, 1,
|
||||
"() -> (long _rv)"},
|
||||
{"CloseComponentResFile", (PyCFunction)Cm_CloseComponentResFile, 1,
|
||||
"(short refnum) -> None"},
|
||||
{"OpenDefaultComponent", (PyCFunction)Cm_OpenDefaultComponent, 1,
|
||||
"(OSType componentType, OSType componentSubType) -> (ComponentInstance _rv)"},
|
||||
{"RegisterComponentResourceFile", (PyCFunction)Cm_RegisterComponentResourceFile, 1,
|
||||
"(short resRefNum, short global) -> (long _rv)"},
|
||||
{NULL, NULL, 0}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
void initCm()
|
||||
{
|
||||
PyObject *m;
|
||||
PyObject *d;
|
||||
|
||||
|
||||
|
||||
|
||||
m = Py_InitModule("Cm", Cm_methods);
|
||||
d = PyModule_GetDict(m);
|
||||
Cm_Error = PyMac_GetOSErrException();
|
||||
if (Cm_Error == NULL ||
|
||||
PyDict_SetItemString(d, "Error", Cm_Error) != 0)
|
||||
Py_FatalError("can't initialize Cm.Error");
|
||||
}
|
||||
|
||||
/* ========================= End module Cm ========================== */
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
# Scan an Apple header file, generating a Python file of generator calls.
|
||||
|
||||
import addpack
|
||||
addpack.addpack(':tools:bgen:bgen')
|
||||
from scantools import Scanner
|
||||
|
||||
LONG = "Components"
|
||||
SHORT = "Cm"
|
||||
|
||||
def main():
|
||||
input = "Components.h"
|
||||
output = SHORT + "gen.py"
|
||||
defsoutput = LONG + ".py"
|
||||
scanner = MyScanner(input, output, defsoutput)
|
||||
scanner.scan()
|
||||
scanner.close()
|
||||
print "=== Done scanning and generating, now importing the generated code... ==="
|
||||
exec "import " + SHORT + "support"
|
||||
print "=== Done. It's up to you to compile it now! ==="
|
||||
|
||||
class MyScanner(Scanner):
|
||||
|
||||
def destination(self, type, name, arglist):
|
||||
classname = "Function"
|
||||
listname = "functions"
|
||||
if arglist:
|
||||
t, n, m = arglist[0]
|
||||
#
|
||||
# FindNextComponent is a special case, since it call also be called
|
||||
# with None as the argument. Hence, we make it a function
|
||||
#
|
||||
if t == "Component" and m == "InMode" and name != "FindNextComponent":
|
||||
classname = "Method"
|
||||
listname = "c_methods"
|
||||
elif t == "ComponentInstance" and m == "InMode":
|
||||
classname = "Method"
|
||||
listname = "ci_methods"
|
||||
return classname, listname
|
||||
|
||||
def makeblacklistnames(self):
|
||||
return [
|
||||
# "GetComponentInfo" # XXXX I dont know how the Handle args are expected...
|
||||
]
|
||||
|
||||
def makeblacklisttypes(self):
|
||||
return [
|
||||
"ResourceSpec",
|
||||
"ComponentResource",
|
||||
"ComponentPlatformInfo",
|
||||
"ComponentResourceExtension",
|
||||
"ComponentPlatformInfoArray",
|
||||
"ExtComponentResource",
|
||||
"ComponentParameters",
|
||||
|
||||
"ComponentRoutineUPP",
|
||||
]
|
||||
|
||||
def makerepairinstructions(self):
|
||||
return [
|
||||
([('ComponentDescription', 'looking', 'OutMode')],
|
||||
[('ComponentDescription', '*', 'InMode')]),
|
||||
]
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
|
@ -0,0 +1,108 @@
|
|||
# This script generates a Python interface for an Apple Macintosh Manager.
|
||||
# It uses the "bgen" package to generate C code.
|
||||
# The function specifications are generated by scanning the mamager's header file,
|
||||
# using the "scantools" package (customized for this particular manager).
|
||||
|
||||
import string
|
||||
|
||||
# Declarations that change for each manager
|
||||
MACHEADERFILE = 'Components.h' # The Apple header file
|
||||
MODNAME = 'Cm' # The name of the module
|
||||
|
||||
# The following is *usually* unchanged but may still require tuning
|
||||
MODPREFIX = MODNAME # The prefix for module-wide routines
|
||||
C_OBJECTPREFIX = 'CmpObj' # The prefix for object methods
|
||||
CI_OBJECTPREFIX = 'CmpInstObj'
|
||||
INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner
|
||||
OUTPUTFILE = MODNAME + "module.c" # The file generated by this program
|
||||
|
||||
from macsupport import *
|
||||
|
||||
# Create the type objects
|
||||
|
||||
includestuff = includestuff + """
|
||||
#include <%s>""" % MACHEADERFILE + """
|
||||
|
||||
/*
|
||||
** Parse/generate ComponentDescriptor records
|
||||
*/
|
||||
PyObject *CmpDesc_New(itself)
|
||||
ComponentDescription *itself;
|
||||
{
|
||||
|
||||
return Py_BuildValue("O&O&O&ll",
|
||||
PyMac_BuildOSType, itself->componentType,
|
||||
PyMac_BuildOSType, itself->componentSubType,
|
||||
PyMac_BuildOSType, itself->componentManufacturer,
|
||||
itself->componentFlags, itself->componentFlagsMask);
|
||||
}
|
||||
|
||||
CmpDesc_Convert(v, p_itself)
|
||||
PyObject *v;
|
||||
ComponentDescription *p_itself;
|
||||
{
|
||||
return PyArg_ParseTuple(v, "O&O&O&ll",
|
||||
PyMac_GetOSType, &p_itself->componentType,
|
||||
PyMac_GetOSType, &p_itself->componentSubType,
|
||||
PyMac_GetOSType, &p_itself->componentManufacturer,
|
||||
&p_itself->componentFlags, &p_itself->componentFlagsMask);
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
ComponentDescription = OpaqueType('ComponentDescription', 'CmpDesc')
|
||||
Component = OpaqueByValueType('Component', C_OBJECTPREFIX)
|
||||
ComponentInstance = OpaqueByValueType('ComponentInstance', CI_OBJECTPREFIX)
|
||||
ComponentResult = Type("ComponentResult", "l")
|
||||
|
||||
ComponentResourceHandle = OpaqueByValueType("ComponentResourceHandle", "ResObj")
|
||||
|
||||
class MyCIObjectDefinition(GlobalObjectDefinition):
|
||||
def outputCheckNewArg(self):
|
||||
Output("""if (itself == NULL) {
|
||||
PyErr_SetString(Cm_Error,"NULL ComponentInstance");
|
||||
return NULL;
|
||||
}""")
|
||||
|
||||
class MyCObjectDefinition(GlobalObjectDefinition):
|
||||
def outputCheckNewArg(self):
|
||||
Output("""if (itself == NULL) {
|
||||
/* XXXX Or should we return None? */
|
||||
PyErr_SetString(Cm_Error,"No such component");
|
||||
return NULL;
|
||||
}""")
|
||||
|
||||
def outputCheckConvertArg(self):
|
||||
Output("""if ( v == Py_None ) {
|
||||
*p_itself = 0;
|
||||
return 1;
|
||||
}""")
|
||||
|
||||
# Create the generator groups and link them
|
||||
module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
|
||||
ci_object = MyCIObjectDefinition('ComponentInstance', CI_OBJECTPREFIX,
|
||||
'ComponentInstance')
|
||||
c_object = MyCObjectDefinition('Component', C_OBJECTPREFIX, 'Component')
|
||||
module.addobject(ci_object)
|
||||
module.addobject(c_object)
|
||||
|
||||
# Create the generator classes used to populate the lists
|
||||
Function = OSErrFunctionGenerator
|
||||
Method = OSErrMethodGenerator
|
||||
|
||||
# Create and populate the lists
|
||||
functions = []
|
||||
c_methods = []
|
||||
ci_methods = []
|
||||
execfile(INPUTFILE)
|
||||
|
||||
# add the populated lists to the generator groups
|
||||
# (in a different wordl the scan program would generate this)
|
||||
for f in functions: module.add(f)
|
||||
for f in c_methods: c_object.add(f)
|
||||
for f in ci_methods: ci_object.add(f)
|
||||
|
||||
# generate output (open the output file as late as possible)
|
||||
SetOutputFileName(OUTPUTFILE)
|
||||
module.generate()
|
||||
|
Loading…
Reference in New Issue