Maintain backwards compatibility with python < 2.3 by dynamically
[python/dscho.git] / Mac / Modules / OSATerminology.c
blob2d8b1e2db7639d91f0181550a8d04be44788e3ae
1 /*
2 ** This module is a one-trick pony: given an FSSpec it gets the aeut
3 ** resources. It was written by Donovan Preston and slightly modified
4 ** by Jack.
5 **
6 ** It should be considered a placeholder, it will probably be replaced
7 ** by a full interface to OpenScripting.
8 */
9 #include "Python.h"
10 #include "macglue.h"
12 #ifdef WITHOUT_FRAMEWORKS
13 #include <OpenScripting.h>
14 #else
15 #include <Carbon/Carbon.h>
16 #endif
18 static PyObject *
19 PyOSA_GetAppTerminology(PyObject* self, PyObject* args)
21 AEDesc theDesc = {0,0};
22 FSSpec fss;
23 ComponentInstance defaultComponent = NULL;
24 SInt16 defaultTerminology = 0;
25 Boolean didLaunch = 0;
26 OSAError err;
27 long modeFlags = 0;
29 if (!PyArg_ParseTuple(args, "O&|i", PyMac_GetFSSpec, &fss, &modeFlags))
30 return NULL;
32 defaultComponent = OpenDefaultComponent (kOSAComponentType, 'ascr');
33 err = GetComponentInstanceError (defaultComponent);
34 if (err) return PyMac_Error(err);
35 err = OSAGetCurrentDialect(defaultComponent, &defaultTerminology);
36 if (err) return PyMac_Error(err);
37 err = OSAGetAppTerminology (
38 defaultComponent,
39 modeFlags,
40 &fss,
41 defaultTerminology,
42 &didLaunch,
43 &theDesc
45 if (err) return PyMac_Error(err);
46 return Py_BuildValue("O&i", AEDesc_New, &theDesc, didLaunch);
49 static PyObject *
50 PyOSA_GetSysTerminology(PyObject* self, PyObject* args)
52 AEDesc theDesc = {0,0};
53 FSSpec fss;
54 ComponentInstance defaultComponent = NULL;
55 SInt16 defaultTerminology = 0;
56 Boolean didLaunch = 0;
57 OSAError err;
58 long modeFlags = 0;
60 if (!PyArg_ParseTuple(args, "O&|i", PyMac_GetFSSpec, &fss, &modeFlags))
61 return NULL;
63 defaultComponent = OpenDefaultComponent (kOSAComponentType, 'ascr');
64 err = GetComponentInstanceError (defaultComponent);
65 if (err) return PyMac_Error(err);
66 err = OSAGetCurrentDialect(defaultComponent, &defaultTerminology);
67 if (err) return PyMac_Error(err);
68 err = OSAGetAppTerminology (
69 defaultComponent,
70 modeFlags,
71 &fss,
72 defaultTerminology,
73 &didLaunch,
74 &theDesc
76 if (err) return PyMac_Error(err);
77 return Py_BuildValue("O&i", AEDesc_New, &theDesc, didLaunch);
80 /*
81 * List of methods defined in the module
83 static struct PyMethodDef OSATerminology_methods[] =
85 {"GetAppTerminology",
86 (PyCFunction) PyOSA_GetAppTerminology,
87 METH_VARARGS,
88 "Get an applications terminology, as an AEDesc object."},
89 {"GetSysTerminology",
90 (PyCFunction) PyOSA_GetSysTerminology,
91 METH_VARARGS,
92 "Get an applications system terminology, as an AEDesc object."},
93 {NULL, (PyCFunction) NULL, 0, NULL}
97 void
98 initOSATerminology(void)
100 Py_InitModule("OSATerminology", OSATerminology_methods);