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