blob: 85ad425717477a2e44e1f5d9e0abe427dd819247 [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
Jack Jansenee1c85c2003-03-06 23:02:59 +000014static PyObject *
15PyOSA_GetAppTerminology(PyObject* self, PyObject* args)
16{
17 AEDesc theDesc = {0,0};
18 FSSpec fss;
19 ComponentInstance defaultComponent = NULL;
20 SInt16 defaultTerminology = 0;
21 Boolean didLaunch = 0;
Jack Jansen86f25fb2003-03-06 23:02:04 +000022 OSAError err;
Jack Jansenee1c85c2003-03-06 23:02:59 +000023 long modeFlags = 0;
Jack Jansen86f25fb2003-03-06 23:02:04 +000024
Jack Jansenee1c85c2003-03-06 23:02:59 +000025 if (!PyArg_ParseTuple(args, "O&|i", PyMac_GetFSSpec, &fss, &modeFlags))
26 return NULL;
Jack Jansen86f25fb2003-03-06 23:02:04 +000027
Jack Jansenee1c85c2003-03-06 23:02:59 +000028 defaultComponent = OpenDefaultComponent (kOSAComponentType, 'ascr');
29 err = GetComponentInstanceError (defaultComponent);
30 if (err) return PyMac_Error(err);
Jack Jansen86f25fb2003-03-06 23:02:04 +000031 err = OSAGetAppTerminology (
32 defaultComponent,
Jack Jansenee1c85c2003-03-06 23:02:59 +000033 modeFlags,
34 &fss,
Jack Jansen86f25fb2003-03-06 23:02:04 +000035 defaultTerminology,
36 &didLaunch,
Jack Jansenee1c85c2003-03-06 23:02:59 +000037 &theDesc
Jack Jansen86f25fb2003-03-06 23:02:04 +000038 );
Jack Jansenee1c85c2003-03-06 23:02:59 +000039 if (err) return PyMac_Error(err);
40 return Py_BuildValue("O&i", AEDesc_New, &theDesc, didLaunch);
41}
Jack Jansen86f25fb2003-03-06 23:02:04 +000042
Jack Jansenee1c85c2003-03-06 23:02:59 +000043static PyObject *
44PyOSA_GetSysTerminology(PyObject* self, PyObject* args)
45{
46 AEDesc theDesc = {0,0};
47 FSSpec fss;
48 ComponentInstance defaultComponent = NULL;
49 SInt16 defaultTerminology = 0;
50 Boolean didLaunch = 0;
51 OSAError err;
52 long modeFlags = 0;
53
54 if (!PyArg_ParseTuple(args, "O&|i", PyMac_GetFSSpec, &fss, &modeFlags))
55 return NULL;
56
57 defaultComponent = OpenDefaultComponent (kOSAComponentType, 'ascr');
58 err = GetComponentInstanceError (defaultComponent);
59 if (err) return PyMac_Error(err);
Jack Jansenee1c85c2003-03-06 23:02:59 +000060 err = OSAGetAppTerminology (
Jack Jansen86f25fb2003-03-06 23:02:04 +000061 defaultComponent,
Jack Jansenee1c85c2003-03-06 23:02:59 +000062 modeFlags,
63 &fss,
Jack Jansen86f25fb2003-03-06 23:02:04 +000064 defaultTerminology,
65 &didLaunch,
Jack Jansenee1c85c2003-03-06 23:02:59 +000066 &theDesc
67 );
68 if (err) return PyMac_Error(err);
69 return Py_BuildValue("O&i", AEDesc_New, &theDesc, didLaunch);
Jack Jansen86f25fb2003-03-06 23:02:04 +000070}
71
72/*
73 * List of methods defined in the module
74 */
Jack Jansenee1c85c2003-03-06 23:02:59 +000075static struct PyMethodDef OSATerminology_methods[] =
Jack Jansen86f25fb2003-03-06 23:02:04 +000076{
Jack Jansenee1c85c2003-03-06 23:02:59 +000077 {"GetAppTerminology",
78 (PyCFunction) PyOSA_GetAppTerminology,
79 METH_VARARGS,
80 "Get an applications terminology, as an AEDesc object."},
81 {"GetSysTerminology",
82 (PyCFunction) PyOSA_GetSysTerminology,
83 METH_VARARGS,
84 "Get an applications system terminology, as an AEDesc object."},
85 {NULL, (PyCFunction) NULL, 0, NULL}
Jack Jansen86f25fb2003-03-06 23:02:04 +000086};
87
88
89void
Jack Jansenee1c85c2003-03-06 23:02:59 +000090initOSATerminology(void)
Jack Jansen86f25fb2003-03-06 23:02:04 +000091{
Jack Jansenee1c85c2003-03-06 23:02:59 +000092 Py_InitModule("OSATerminology", OSATerminology_methods);
Jack Jansen86f25fb2003-03-06 23:02:04 +000093}