blob: 6a13aeabae5255332a6228000414c053b6d41a0f [file] [log] [blame]
Jack Jansenee1c85c2003-03-06 23:02:59 +00001/*
Ronald Oussoren1ea79912009-03-04 22:49:36 +00002** An interface to the application scripting related functions of the OSA API.
Jack Jansenee1c85c2003-03-06 23:02:59 +00003**
Ronald Oussoren1ea79912009-03-04 22:49:36 +00004** 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.
Jack Jansenee1c85c2003-03-06 23:02:59 +000011*/
12#include "Python.h"
Jack Jansen7107c1a2003-11-20 13:31:00 +000013#include "pymactoolbox.h"
Jack Jansenee1c85c2003-03-06 23:02:59 +000014
Jack Jansen86f25fb2003-03-06 23:02:04 +000015#include <Carbon/Carbon.h>
Jack Jansen86f25fb2003-03-06 23:02:04 +000016
Ronald Oussoren5640ce22008-06-05 12:58:24 +000017#ifndef __LP64__
Jack Jansenee1c85c2003-03-06 23:02:59 +000018static PyObject *
19PyOSA_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;
Jack Jansen86f25fb2003-03-06 23:02:04 +000026 OSAError err;
Jack Jansenee1c85c2003-03-06 23:02:59 +000027 long modeFlags = 0;
Jack Jansen86f25fb2003-03-06 23:02:04 +000028
Jack Jansenee1c85c2003-03-06 23:02:59 +000029 if (!PyArg_ParseTuple(args, "O&|i", PyMac_GetFSSpec, &fss, &modeFlags))
30 return NULL;
Jack Jansen86f25fb2003-03-06 23:02:04 +000031
Ronald Oussoren1ea79912009-03-04 22:49:36 +000032 /*
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 */
Jack Jansenee1c85c2003-03-06 23:02:59 +000039 defaultComponent = OpenDefaultComponent (kOSAComponentType, 'ascr');
40 err = GetComponentInstanceError (defaultComponent);
41 if (err) return PyMac_Error(err);
Jack Jansen86f25fb2003-03-06 23:02:04 +000042 err = OSAGetAppTerminology (
43 defaultComponent,
Ronald Oussoren1ea79912009-03-04 22:49:36 +000044 kOSAModeNull,
Jack Jansenee1c85c2003-03-06 23:02:59 +000045 &fss,
Jack Jansen86f25fb2003-03-06 23:02:04 +000046 defaultTerminology,
47 &didLaunch,
Jack Jansenee1c85c2003-03-06 23:02:59 +000048 &theDesc
Jack Jansen86f25fb2003-03-06 23:02:04 +000049 );
Jack Jansenee1c85c2003-03-06 23:02:59 +000050 if (err) return PyMac_Error(err);
51 return Py_BuildValue("O&i", AEDesc_New, &theDesc, didLaunch);
52}
Jack Jansen86f25fb2003-03-06 23:02:04 +000053
Jack Jansenee1c85c2003-03-06 23:02:59 +000054static PyObject *
55PyOSA_GetSysTerminology(PyObject* self, PyObject* args)
56{
57 AEDesc theDesc = {0,0};
Jack Jansenee1c85c2003-03-06 23:02:59 +000058 ComponentInstance defaultComponent = NULL;
59 SInt16 defaultTerminology = 0;
Jack Jansenee1c85c2003-03-06 23:02:59 +000060 OSAError err;
Jack Jansenee1c85c2003-03-06 23:02:59 +000061
Ronald Oussoren1ea79912009-03-04 22:49:36 +000062 /* Accept any args for sake of backwards compatibility, then ignore them. */
63
Jack Jansenee1c85c2003-03-06 23:02:59 +000064 defaultComponent = OpenDefaultComponent (kOSAComponentType, 'ascr');
65 err = GetComponentInstanceError (defaultComponent);
66 if (err) return PyMac_Error(err);
Ronald Oussoren1ea79912009-03-04 22:49:36 +000067 err = OSAGetSysTerminology (
Jack Jansen86f25fb2003-03-06 23:02:04 +000068 defaultComponent,
Ronald Oussoren1ea79912009-03-04 22:49:36 +000069 kOSAModeNull,
Jack Jansen86f25fb2003-03-06 23:02:04 +000070 defaultTerminology,
Jack Jansenee1c85c2003-03-06 23:02:59 +000071 &theDesc
72 );
73 if (err) return PyMac_Error(err);
Ronald Oussoren1ea79912009-03-04 22:49:36 +000074 return Py_BuildValue("O&", AEDesc_New, &theDesc);
Jack Jansen86f25fb2003-03-06 23:02:04 +000075}
Ronald Oussoren5640ce22008-06-05 12:58:24 +000076#endif /* !__LP64__ */
Jack Jansen86f25fb2003-03-06 23:02:04 +000077
78/*
79 * List of methods defined in the module
80 */
Jack Jansenee1c85c2003-03-06 23:02:59 +000081static struct PyMethodDef OSATerminology_methods[] =
Jack Jansen86f25fb2003-03-06 23:02:04 +000082{
Ronald Oussoren5640ce22008-06-05 12:58:24 +000083#ifndef __LP64__
Jack Jansenee1c85c2003-03-06 23:02:59 +000084 {"GetAppTerminology",
85 (PyCFunction) PyOSA_GetAppTerminology,
86 METH_VARARGS,
Ronald Oussoren1ea79912009-03-04 22:49:36 +000087 "Get an application's terminology. GetAppTerminology(path) --> AEDesc"},
Jack Jansenee1c85c2003-03-06 23:02:59 +000088 {"GetSysTerminology",
89 (PyCFunction) PyOSA_GetSysTerminology,
90 METH_VARARGS,
Ronald Oussoren1ea79912009-03-04 22:49:36 +000091 "Get the AppleScript language's terminology. GetSysTerminology() --> AEDesc"},
Ronald Oussoren5640ce22008-06-05 12:58:24 +000092#endif /* !__LP64__ */
Jack Jansenee1c85c2003-03-06 23:02:59 +000093 {NULL, (PyCFunction) NULL, 0, NULL}
Jack Jansen86f25fb2003-03-06 23:02:04 +000094};
95
Jack Jansen86f25fb2003-03-06 23:02:04 +000096void
Jack Jansenee1c85c2003-03-06 23:02:59 +000097initOSATerminology(void)
Jack Jansen86f25fb2003-03-06 23:02:04 +000098{
Benjamin Peterson23681932008-05-12 21:42:13 +000099 if (PyErr_WarnPy3k("In 3.x, OSATerminology is removed.", 1) < 0)
100 return;
Jack Jansenee1c85c2003-03-06 23:02:59 +0000101 Py_InitModule("OSATerminology", OSATerminology_methods);
Ronald Oussoren5640ce22008-06-05 12:58:24 +0000102}