Jack Jansen | ee1c85c | 2003-03-06 23:02:59 +0000 | [diff] [blame] | 1 | /* |
Ronald Oussoren | 1ea7991 | 2009-03-04 22:49:36 +0000 | [diff] [blame] | 2 | ** An interface to the application scripting related functions of the OSA API. |
Jack Jansen | ee1c85c | 2003-03-06 23:02:59 +0000 | [diff] [blame] | 3 | ** |
Ronald Oussoren | 1ea7991 | 2009-03-04 22:49:36 +0000 | [diff] [blame] | 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. |
Jack Jansen | ee1c85c | 2003-03-06 23:02:59 +0000 | [diff] [blame] | 11 | */ |
| 12 | #include "Python.h" |
Jack Jansen | 7107c1a | 2003-11-20 13:31:00 +0000 | [diff] [blame] | 13 | #include "pymactoolbox.h" |
Jack Jansen | ee1c85c | 2003-03-06 23:02:59 +0000 | [diff] [blame] | 14 | |
Jack Jansen | 86f25fb | 2003-03-06 23:02:04 +0000 | [diff] [blame] | 15 | #include <Carbon/Carbon.h> |
Jack Jansen | 86f25fb | 2003-03-06 23:02:04 +0000 | [diff] [blame] | 16 | |
Ronald Oussoren | 5640ce2 | 2008-06-05 12:58:24 +0000 | [diff] [blame] | 17 | #ifndef __LP64__ |
Jack Jansen | ee1c85c | 2003-03-06 23:02:59 +0000 | [diff] [blame] | 18 | static PyObject * |
| 19 | PyOSA_GetAppTerminology(PyObject* self, PyObject* args) |
| 20 | { |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 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); |
Jack Jansen | ee1c85c | 2003-03-06 23:02:59 +0000 | [diff] [blame] | 52 | } |
Jack Jansen | 86f25fb | 2003-03-06 23:02:04 +0000 | [diff] [blame] | 53 | |
Jack Jansen | ee1c85c | 2003-03-06 23:02:59 +0000 | [diff] [blame] | 54 | static PyObject * |
| 55 | PyOSA_GetSysTerminology(PyObject* self, PyObject* args) |
| 56 | { |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 57 | AEDesc theDesc = {0,0}; |
| 58 | ComponentInstance defaultComponent = NULL; |
| 59 | SInt16 defaultTerminology = 0; |
| 60 | OSAError err; |
Ronald Oussoren | 1ea7991 | 2009-03-04 22:49:36 +0000 | [diff] [blame] | 61 | |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 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); |
Jack Jansen | 86f25fb | 2003-03-06 23:02:04 +0000 | [diff] [blame] | 75 | } |
Ronald Oussoren | 5640ce2 | 2008-06-05 12:58:24 +0000 | [diff] [blame] | 76 | #endif /* !__LP64__ */ |
Jack Jansen | 86f25fb | 2003-03-06 23:02:04 +0000 | [diff] [blame] | 77 | |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 78 | /* |
Jack Jansen | 86f25fb | 2003-03-06 23:02:04 +0000 | [diff] [blame] | 79 | * List of methods defined in the module |
| 80 | */ |
Jack Jansen | ee1c85c | 2003-03-06 23:02:59 +0000 | [diff] [blame] | 81 | static struct PyMethodDef OSATerminology_methods[] = |
Jack Jansen | 86f25fb | 2003-03-06 23:02:04 +0000 | [diff] [blame] | 82 | { |
Ronald Oussoren | 5640ce2 | 2008-06-05 12:58:24 +0000 | [diff] [blame] | 83 | #ifndef __LP64__ |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 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"}, |
Ronald Oussoren | 5640ce2 | 2008-06-05 12:58:24 +0000 | [diff] [blame] | 92 | #endif /* !__LP64__ */ |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 93 | {NULL, (PyCFunction) NULL, 0, NULL} |
Jack Jansen | 86f25fb | 2003-03-06 23:02:04 +0000 | [diff] [blame] | 94 | }; |
| 95 | |
Jack Jansen | 86f25fb | 2003-03-06 23:02:04 +0000 | [diff] [blame] | 96 | void |
Jack Jansen | ee1c85c | 2003-03-06 23:02:59 +0000 | [diff] [blame] | 97 | initOSATerminology(void) |
Jack Jansen | 86f25fb | 2003-03-06 23:02:04 +0000 | [diff] [blame] | 98 | { |
Antoine Pitrou | c83ea13 | 2010-05-09 14:46:46 +0000 | [diff] [blame] | 99 | if (PyErr_WarnPy3k("In 3.x, the OSATerminology module is removed.", 1) < 0) |
| 100 | return; |
| 101 | Py_InitModule("OSATerminology", OSATerminology_methods); |
Ronald Oussoren | 5640ce2 | 2008-06-05 12:58:24 +0000 | [diff] [blame] | 102 | } |