blob: e56a0db205bbc9ac6ea27bdd9fdbcc42d406874e [file] [log] [blame]
Jack Jansenee1c85c2003-03-06 23:02:59 +00001/*
2** This module is a one-trick pony: given an FSSpec it gets the aeut
3** resources. It was written by Donovan Preston and slightly modified
4** by Jack.
5**
6** It should be considered a placeholder, it will probably be replaced
7** by a full interface to OpenScripting.
8*/
9#include "Python.h"
Jack Jansen7107c1a2003-11-20 13:31:00 +000010#include "pymactoolbox.h"
Jack Jansenee1c85c2003-03-06 23:02:59 +000011
Jack Jansen86f25fb2003-03-06 23:02:04 +000012#include <Carbon/Carbon.h>
Jack Jansen86f25fb2003-03-06 23:02:04 +000013
Ronald Oussoren5640ce22008-06-05 12:58:24 +000014#ifndef __LP64__
Jack Jansenee1c85c2003-03-06 23:02:59 +000015static PyObject *
16PyOSA_GetAppTerminology(PyObject* self, PyObject* args)
17{
18 AEDesc theDesc = {0,0};
19 FSSpec fss;
20 ComponentInstance defaultComponent = NULL;
21 SInt16 defaultTerminology = 0;
22 Boolean didLaunch = 0;
Jack Jansen86f25fb2003-03-06 23:02:04 +000023 OSAError err;
Jack Jansenee1c85c2003-03-06 23:02:59 +000024 long modeFlags = 0;
Jack Jansen86f25fb2003-03-06 23:02:04 +000025
Jack Jansenee1c85c2003-03-06 23:02:59 +000026 if (!PyArg_ParseTuple(args, "O&|i", PyMac_GetFSSpec, &fss, &modeFlags))
27 return NULL;
Jack Jansen86f25fb2003-03-06 23:02:04 +000028
Jack Jansenee1c85c2003-03-06 23:02:59 +000029 defaultComponent = OpenDefaultComponent (kOSAComponentType, 'ascr');
30 err = GetComponentInstanceError (defaultComponent);
31 if (err) return PyMac_Error(err);
Jack Jansen86f25fb2003-03-06 23:02:04 +000032 err = OSAGetAppTerminology (
33 defaultComponent,
Jack Jansenee1c85c2003-03-06 23:02:59 +000034 modeFlags,
35 &fss,
Jack Jansen86f25fb2003-03-06 23:02:04 +000036 defaultTerminology,
37 &didLaunch,
Jack Jansenee1c85c2003-03-06 23:02:59 +000038 &theDesc
Jack Jansen86f25fb2003-03-06 23:02:04 +000039 );
Jack Jansenee1c85c2003-03-06 23:02:59 +000040 if (err) return PyMac_Error(err);
41 return Py_BuildValue("O&i", AEDesc_New, &theDesc, didLaunch);
42}
Jack Jansen86f25fb2003-03-06 23:02:04 +000043
Jack Jansenee1c85c2003-03-06 23:02:59 +000044static PyObject *
45PyOSA_GetSysTerminology(PyObject* self, PyObject* args)
46{
47 AEDesc theDesc = {0,0};
48 FSSpec fss;
49 ComponentInstance defaultComponent = NULL;
50 SInt16 defaultTerminology = 0;
51 Boolean didLaunch = 0;
52 OSAError err;
53 long modeFlags = 0;
54
55 if (!PyArg_ParseTuple(args, "O&|i", PyMac_GetFSSpec, &fss, &modeFlags))
56 return NULL;
57
58 defaultComponent = OpenDefaultComponent (kOSAComponentType, 'ascr');
59 err = GetComponentInstanceError (defaultComponent);
60 if (err) return PyMac_Error(err);
Jack Jansenee1c85c2003-03-06 23:02:59 +000061 err = OSAGetAppTerminology (
Jack Jansen86f25fb2003-03-06 23:02:04 +000062 defaultComponent,
Jack Jansenee1c85c2003-03-06 23:02:59 +000063 modeFlags,
64 &fss,
Jack Jansen86f25fb2003-03-06 23:02:04 +000065 defaultTerminology,
66 &didLaunch,
Jack Jansenee1c85c2003-03-06 23:02:59 +000067 &theDesc
68 );
69 if (err) return PyMac_Error(err);
70 return Py_BuildValue("O&i", AEDesc_New, &theDesc, didLaunch);
Jack Jansen86f25fb2003-03-06 23:02:04 +000071}
Ronald Oussoren5640ce22008-06-05 12:58:24 +000072#endif /* !__LP64__ */
Jack Jansen86f25fb2003-03-06 23:02:04 +000073
74/*
75 * List of methods defined in the module
76 */
Jack Jansenee1c85c2003-03-06 23:02:59 +000077static struct PyMethodDef OSATerminology_methods[] =
Jack Jansen86f25fb2003-03-06 23:02:04 +000078{
Ronald Oussoren5640ce22008-06-05 12:58:24 +000079#ifndef __LP64__
Jack Jansenee1c85c2003-03-06 23:02:59 +000080 {"GetAppTerminology",
81 (PyCFunction) PyOSA_GetAppTerminology,
82 METH_VARARGS,
83 "Get an applications terminology, as an AEDesc object."},
84 {"GetSysTerminology",
85 (PyCFunction) PyOSA_GetSysTerminology,
86 METH_VARARGS,
87 "Get an applications system terminology, as an AEDesc object."},
Ronald Oussoren5640ce22008-06-05 12:58:24 +000088#endif /* !__LP64__ */
Jack Jansenee1c85c2003-03-06 23:02:59 +000089 {NULL, (PyCFunction) NULL, 0, NULL}
Jack Jansen86f25fb2003-03-06 23:02:04 +000090};
91
Jack Jansen86f25fb2003-03-06 23:02:04 +000092void
Jack Jansenee1c85c2003-03-06 23:02:59 +000093initOSATerminology(void)
Jack Jansen86f25fb2003-03-06 23:02:04 +000094{
Benjamin Peterson23681932008-05-12 21:42:13 +000095 if (PyErr_WarnPy3k("In 3.x, OSATerminology is removed.", 1) < 0)
96 return;
Jack Jansenee1c85c2003-03-06 23:02:59 +000097 Py_InitModule("OSATerminology", OSATerminology_methods);
Ronald Oussoren5640ce22008-06-05 12:58:24 +000098}