blob: 2d8b1e2db7639d91f0181550a8d04be44788e3ae [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"
10#include "macglue.h"
11
12#ifdef WITHOUT_FRAMEWORKS
13#include <OpenScripting.h>
14#else
Jack Jansen86f25fb2003-03-06 23:02:04 +000015#include <Carbon/Carbon.h>
Jack Jansenee1c85c2003-03-06 23:02:59 +000016#endif
Jack Jansen86f25fb2003-03-06 23:02:04 +000017
Jack Jansenee1c85c2003-03-06 23:02:59 +000018static PyObject *
19PyOSA_GetAppTerminology(PyObject* self, PyObject* args)
20{
21 AEDesc theDesc = {0,0};
22 FSSpec fss;
23 ComponentInstance defaultComponent = NULL;
24 SInt16 defaultTerminology = 0;
25 Boolean didLaunch = 0;
Jack Jansen86f25fb2003-03-06 23:02:04 +000026 OSAError err;
Jack Jansenee1c85c2003-03-06 23:02:59 +000027 long modeFlags = 0;
Jack Jansen86f25fb2003-03-06 23:02:04 +000028
Jack Jansenee1c85c2003-03-06 23:02:59 +000029 if (!PyArg_ParseTuple(args, "O&|i", PyMac_GetFSSpec, &fss, &modeFlags))
30 return NULL;
Jack Jansen86f25fb2003-03-06 23:02:04 +000031
Jack Jansenee1c85c2003-03-06 23:02:59 +000032 defaultComponent = OpenDefaultComponent (kOSAComponentType, 'ascr');
33 err = GetComponentInstanceError (defaultComponent);
34 if (err) return PyMac_Error(err);
Jack Jansen86f25fb2003-03-06 23:02:04 +000035 err = OSAGetCurrentDialect(defaultComponent, &defaultTerminology);
Jack Jansenee1c85c2003-03-06 23:02:59 +000036 if (err) return PyMac_Error(err);
Jack Jansen86f25fb2003-03-06 23:02:04 +000037 err = OSAGetAppTerminology (
38 defaultComponent,
Jack Jansenee1c85c2003-03-06 23:02:59 +000039 modeFlags,
40 &fss,
Jack Jansen86f25fb2003-03-06 23:02:04 +000041 defaultTerminology,
42 &didLaunch,
Jack Jansenee1c85c2003-03-06 23:02:59 +000043 &theDesc
Jack Jansen86f25fb2003-03-06 23:02:04 +000044 );
Jack Jansenee1c85c2003-03-06 23:02:59 +000045 if (err) return PyMac_Error(err);
46 return Py_BuildValue("O&i", AEDesc_New, &theDesc, didLaunch);
47}
Jack Jansen86f25fb2003-03-06 23:02:04 +000048
Jack Jansenee1c85c2003-03-06 23:02:59 +000049static PyObject *
50PyOSA_GetSysTerminology(PyObject* self, PyObject* args)
51{
52 AEDesc theDesc = {0,0};
53 FSSpec fss;
54 ComponentInstance defaultComponent = NULL;
55 SInt16 defaultTerminology = 0;
56 Boolean didLaunch = 0;
57 OSAError err;
58 long modeFlags = 0;
59
60 if (!PyArg_ParseTuple(args, "O&|i", PyMac_GetFSSpec, &fss, &modeFlags))
61 return NULL;
62
63 defaultComponent = OpenDefaultComponent (kOSAComponentType, 'ascr');
64 err = GetComponentInstanceError (defaultComponent);
65 if (err) return PyMac_Error(err);
66 err = OSAGetCurrentDialect(defaultComponent, &defaultTerminology);
67 if (err) return PyMac_Error(err);
68 err = OSAGetAppTerminology (
Jack Jansen86f25fb2003-03-06 23:02:04 +000069 defaultComponent,
Jack Jansenee1c85c2003-03-06 23:02:59 +000070 modeFlags,
71 &fss,
Jack Jansen86f25fb2003-03-06 23:02:04 +000072 defaultTerminology,
73 &didLaunch,
Jack Jansenee1c85c2003-03-06 23:02:59 +000074 &theDesc
75 );
76 if (err) return PyMac_Error(err);
77 return Py_BuildValue("O&i", AEDesc_New, &theDesc, didLaunch);
Jack Jansen86f25fb2003-03-06 23:02:04 +000078}
79
80/*
81 * List of methods defined in the module
82 */
Jack Jansenee1c85c2003-03-06 23:02:59 +000083static struct PyMethodDef OSATerminology_methods[] =
Jack Jansen86f25fb2003-03-06 23:02:04 +000084{
Jack Jansenee1c85c2003-03-06 23:02:59 +000085 {"GetAppTerminology",
86 (PyCFunction) PyOSA_GetAppTerminology,
87 METH_VARARGS,
88 "Get an applications terminology, as an AEDesc object."},
89 {"GetSysTerminology",
90 (PyCFunction) PyOSA_GetSysTerminology,
91 METH_VARARGS,
92 "Get an applications system terminology, as an AEDesc object."},
93 {NULL, (PyCFunction) NULL, 0, NULL}
Jack Jansen86f25fb2003-03-06 23:02:04 +000094};
95
96
97void
Jack Jansenee1c85c2003-03-06 23:02:59 +000098initOSATerminology(void)
Jack Jansen86f25fb2003-03-06 23:02:04 +000099{
Jack Jansenee1c85c2003-03-06 23:02:59 +0000100 Py_InitModule("OSATerminology", OSATerminology_methods);
Jack Jansen86f25fb2003-03-06 23:02:04 +0000101}