2003-03-06 19:02:59 -04:00
|
|
|
/*
|
2009-03-04 18:49:36 -04:00
|
|
|
** An interface to the application scripting related functions of the OSA API.
|
2003-03-06 19:02:59 -04:00
|
|
|
**
|
2009-03-04 18:49:36 -04:00
|
|
|
** GetAppTerminology - given an FSSpec/posix path to an application,
|
|
|
|
** returns its aevt (scripting terminology) resource(s)
|
|
|
|
**
|
|
|
|
** GetSysTerminology - returns the AppleScript language component's
|
|
|
|
** aeut (scripting terminology) resource
|
|
|
|
**
|
|
|
|
** Written by Donovan Preston and slightly modified by Jack and HAS.
|
2003-03-06 19:02:59 -04:00
|
|
|
*/
|
|
|
|
#include "Python.h"
|
2003-11-20 09:31:00 -04:00
|
|
|
#include "pymactoolbox.h"
|
2003-03-06 19:02:59 -04:00
|
|
|
|
2003-03-06 19:02:04 -04:00
|
|
|
#include <Carbon/Carbon.h>
|
|
|
|
|
2008-06-05 09:58:24 -03:00
|
|
|
#ifndef __LP64__
|
2003-03-06 19:02:59 -04:00
|
|
|
static PyObject *
|
|
|
|
PyOSA_GetAppTerminology(PyObject* self, PyObject* args)
|
|
|
|
{
|
|
|
|
AEDesc theDesc = {0,0};
|
|
|
|
FSSpec fss;
|
|
|
|
ComponentInstance defaultComponent = NULL;
|
|
|
|
SInt16 defaultTerminology = 0;
|
|
|
|
Boolean didLaunch = 0;
|
2003-03-06 19:02:04 -04:00
|
|
|
OSAError err;
|
2003-03-06 19:02:59 -04:00
|
|
|
long modeFlags = 0;
|
2003-03-06 19:02:04 -04:00
|
|
|
|
2003-03-06 19:02:59 -04:00
|
|
|
if (!PyArg_ParseTuple(args, "O&|i", PyMac_GetFSSpec, &fss, &modeFlags))
|
|
|
|
return NULL;
|
2003-03-06 19:02:04 -04:00
|
|
|
|
2009-03-04 18:49:36 -04:00
|
|
|
/*
|
|
|
|
** Note that we have to use the AppleScript component here. Who knows why
|
|
|
|
** OSAGetAppTerminology should require a scripting component in the
|
|
|
|
** first place, but it does. Note: doesn't work with the generic scripting
|
|
|
|
** component, which is unfortunate as the AS component is currently very
|
|
|
|
** slow (~1 sec?) to load, but we just have to live with this.
|
|
|
|
*/
|
2003-03-06 19:02:59 -04:00
|
|
|
defaultComponent = OpenDefaultComponent (kOSAComponentType, 'ascr');
|
|
|
|
err = GetComponentInstanceError (defaultComponent);
|
|
|
|
if (err) return PyMac_Error(err);
|
2003-03-06 19:02:04 -04:00
|
|
|
err = OSAGetAppTerminology (
|
|
|
|
defaultComponent,
|
2009-03-04 18:49:36 -04:00
|
|
|
kOSAModeNull,
|
2003-03-06 19:02:59 -04:00
|
|
|
&fss,
|
2003-03-06 19:02:04 -04:00
|
|
|
defaultTerminology,
|
|
|
|
&didLaunch,
|
2003-03-06 19:02:59 -04:00
|
|
|
&theDesc
|
2003-03-06 19:02:04 -04:00
|
|
|
);
|
2003-03-06 19:02:59 -04:00
|
|
|
if (err) return PyMac_Error(err);
|
|
|
|
return Py_BuildValue("O&i", AEDesc_New, &theDesc, didLaunch);
|
|
|
|
}
|
2003-03-06 19:02:04 -04:00
|
|
|
|
2003-03-06 19:02:59 -04:00
|
|
|
static PyObject *
|
|
|
|
PyOSA_GetSysTerminology(PyObject* self, PyObject* args)
|
|
|
|
{
|
|
|
|
AEDesc theDesc = {0,0};
|
|
|
|
ComponentInstance defaultComponent = NULL;
|
|
|
|
SInt16 defaultTerminology = 0;
|
|
|
|
OSAError err;
|
|
|
|
|
2009-03-04 18:49:36 -04:00
|
|
|
/* Accept any args for sake of backwards compatibility, then ignore them. */
|
|
|
|
|
2003-03-06 19:02:59 -04:00
|
|
|
defaultComponent = OpenDefaultComponent (kOSAComponentType, 'ascr');
|
|
|
|
err = GetComponentInstanceError (defaultComponent);
|
|
|
|
if (err) return PyMac_Error(err);
|
2009-03-04 18:49:36 -04:00
|
|
|
err = OSAGetSysTerminology (
|
2003-03-06 19:02:04 -04:00
|
|
|
defaultComponent,
|
2009-03-04 18:49:36 -04:00
|
|
|
kOSAModeNull,
|
2003-03-06 19:02:04 -04:00
|
|
|
defaultTerminology,
|
2003-03-06 19:02:59 -04:00
|
|
|
&theDesc
|
|
|
|
);
|
|
|
|
if (err) return PyMac_Error(err);
|
2009-03-04 18:49:36 -04:00
|
|
|
return Py_BuildValue("O&", AEDesc_New, &theDesc);
|
2003-03-06 19:02:04 -04:00
|
|
|
}
|
2008-06-05 09:58:24 -03:00
|
|
|
#endif /* !__LP64__ */
|
2003-03-06 19:02:04 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* List of methods defined in the module
|
|
|
|
*/
|
2003-03-06 19:02:59 -04:00
|
|
|
static struct PyMethodDef OSATerminology_methods[] =
|
2003-03-06 19:02:04 -04:00
|
|
|
{
|
2008-06-05 09:58:24 -03:00
|
|
|
#ifndef __LP64__
|
2003-03-06 19:02:59 -04:00
|
|
|
{"GetAppTerminology",
|
|
|
|
(PyCFunction) PyOSA_GetAppTerminology,
|
|
|
|
METH_VARARGS,
|
2009-03-04 18:49:36 -04:00
|
|
|
"Get an application's terminology. GetAppTerminology(path) --> AEDesc"},
|
2003-03-06 19:02:59 -04:00
|
|
|
{"GetSysTerminology",
|
|
|
|
(PyCFunction) PyOSA_GetSysTerminology,
|
|
|
|
METH_VARARGS,
|
2009-03-04 18:49:36 -04:00
|
|
|
"Get the AppleScript language's terminology. GetSysTerminology() --> AEDesc"},
|
2008-06-05 09:58:24 -03:00
|
|
|
#endif /* !__LP64__ */
|
2003-03-06 19:02:59 -04:00
|
|
|
{NULL, (PyCFunction) NULL, 0, NULL}
|
2003-03-06 19:02:04 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
2003-03-06 19:02:59 -04:00
|
|
|
initOSATerminology(void)
|
2003-03-06 19:02:04 -04:00
|
|
|
{
|
2008-05-12 18:42:13 -03:00
|
|
|
if (PyErr_WarnPy3k("In 3.x, OSATerminology is removed.", 1) < 0)
|
|
|
|
return;
|
2003-03-06 19:02:59 -04:00
|
|
|
Py_InitModule("OSATerminology", OSATerminology_methods);
|
2008-06-05 09:58:24 -03:00
|
|
|
}
|