1 /*
2 ** An interface to the application scripting related functions of the OSA API.
3 **
4 ** GetAppTerminology - given an FSSpec/posix path to an application,
5 ** returns its aevt (scripting terminology) resource(s)
6 **
7 ** GetSysTerminology - returns the AppleScript language component's
8 ** aeut (scripting terminology) resource
9 **
10 ** Written by Donovan Preston and slightly modified by Jack and HAS.
11 */
12 #include "Python.h"
13 #include "pymactoolbox.h"
14
15 #include <Carbon/Carbon.h>
16
17 #if APPLE_SUPPORTS_QUICKTIME
18 static PyObject *
PyOSA_GetAppTerminology(PyObject * self,PyObject * args)19 PyOSA_GetAppTerminology(PyObject* self, PyObject* args)
20 {
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;
28
29 if (!PyArg_ParseTuple(args, "O&|i", PyMac_GetFSSpec, &fss, &modeFlags))
30 return NULL;
31
32 /*
33 ** Note that we have to use the AppleScript component here. Who knows why
34 ** OSAGetAppTerminology should require a scripting component in the
35 ** first place, but it does. Note: doesn't work with the generic scripting
36 ** component, which is unfortunate as the AS component is currently very
37 ** slow (~1 sec?) to load, but we just have to live with this.
38 */
39 defaultComponent = OpenDefaultComponent (kOSAComponentType, 'ascr');
40 err = GetComponentInstanceError (defaultComponent);
41 if (err) return PyMac_Error(err);
42 err = OSAGetAppTerminology (
43 defaultComponent,
44 kOSAModeNull,
45 &fss,
46 defaultTerminology,
47 &didLaunch,
48 &theDesc
49 );
50 if (err) return PyMac_Error(err);
51 return Py_BuildValue("O&i", AEDesc_New, &theDesc, didLaunch);
52 }
53
54 static PyObject *
PyOSA_GetSysTerminology(PyObject * self,PyObject * args)55 PyOSA_GetSysTerminology(PyObject* self, PyObject* args)
56 {
57 AEDesc theDesc = {0,0};
58 ComponentInstance defaultComponent = NULL;
59 SInt16 defaultTerminology = 0;
60 OSAError err;
61
62 /* Accept any args for sake of backwards compatibility, then ignore them. */
63
64 defaultComponent = OpenDefaultComponent (kOSAComponentType, 'ascr');
65 err = GetComponentInstanceError (defaultComponent);
66 if (err) return PyMac_Error(err);
67 err = OSAGetSysTerminology (
68 defaultComponent,
69 kOSAModeNull,
70 defaultTerminology,
71 &theDesc
72 );
73 if (err) return PyMac_Error(err);
74 return Py_BuildValue("O&", AEDesc_New, &theDesc);
75 }
76 #endif /* APPLE_SUPPORTS_QUICKTIME */
77
78 /*
79 * List of methods defined in the module
80 */
81 static struct PyMethodDef OSATerminology_methods[] =
82 {
83 #if APPLE_SUPPORTS_QUICKTIME
84 {"GetAppTerminology",
85 (PyCFunction) PyOSA_GetAppTerminology,
86 METH_VARARGS,
87 "Get an application's terminology. GetAppTerminology(path) --> AEDesc"},
88 {"GetSysTerminology",
89 (PyCFunction) PyOSA_GetSysTerminology,
90 METH_VARARGS,
91 "Get the AppleScript language's terminology. GetSysTerminology() --> AEDesc"},
92 #endif /* APPLE_SUPPORTS_QUICKTIME */
93 {NULL, (PyCFunction) NULL, 0, NULL}
94 };
95
96 void
initOSATerminology(void)97 initOSATerminology(void)
98 {
99 if (PyErr_WarnPy3k("In 3.x, the OSATerminology module is removed.", 1) < 0)
100 return;
101 Py_InitModule("OSATerminology", OSATerminology_methods);
102 }
103