1 | # This script generates a Python interface for an Apple Macintosh Manager.
|
---|
2 | # It uses the "bgen" package to generate C code.
|
---|
3 | # The function specifications are generated by scanning the mamager's header file,
|
---|
4 | # using the "scantools" package (customized for this particular manager).
|
---|
5 |
|
---|
6 | #error missing SetActionFilter
|
---|
7 |
|
---|
8 | import string
|
---|
9 |
|
---|
10 | # Declarations that change for each manager
|
---|
11 | MODNAME = '_Mlte' # The name of the module
|
---|
12 |
|
---|
13 | # The following is *usually* unchanged but may still require tuning
|
---|
14 | MODPREFIX = 'Mlte' # The prefix for module-wide routines
|
---|
15 | INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner
|
---|
16 | OUTPUTFILE = MODNAME + "module.c" # The file generated by this program
|
---|
17 |
|
---|
18 | from macsupport import *
|
---|
19 |
|
---|
20 | # Create the type objects
|
---|
21 |
|
---|
22 | includestuff = includestuff + """
|
---|
23 | #include <Carbon/Carbon.h>
|
---|
24 |
|
---|
25 | /* For now we declare them forward here. They'll go to mactoolbox later */
|
---|
26 | static PyObject *TXNObj_New(TXNObject);
|
---|
27 | static int TXNObj_Convert(PyObject *, TXNObject *);
|
---|
28 | static PyObject *TXNFontMenuObj_New(TXNFontMenuObject);
|
---|
29 | static int TXNFontMenuObj_Convert(PyObject *, TXNFontMenuObject *);
|
---|
30 |
|
---|
31 | // ADD declarations
|
---|
32 | #ifdef NOTYET_USE_TOOLBOX_OBJECT_GLUE
|
---|
33 | //extern PyObject *_CFTypeRefObj_New(CFTypeRef);
|
---|
34 | //extern int _CFTypeRefObj_Convert(PyObject *, CFTypeRef *);
|
---|
35 |
|
---|
36 | //#define CFTypeRefObj_New _CFTypeRefObj_New
|
---|
37 | //#define CFTypeRefObj_Convert _CFTypeRefObj_Convert
|
---|
38 | #endif
|
---|
39 |
|
---|
40 | /*
|
---|
41 | ** Parse an optional fsspec
|
---|
42 | */
|
---|
43 | static int
|
---|
44 | OptFSSpecPtr_Convert(PyObject *v, FSSpec **p_itself)
|
---|
45 | {
|
---|
46 | static FSSpec fss;
|
---|
47 | if (v == Py_None)
|
---|
48 | {
|
---|
49 | *p_itself = NULL;
|
---|
50 | return 1;
|
---|
51 | }
|
---|
52 | *p_itself = &fss;
|
---|
53 | return PyMac_GetFSSpec(v, *p_itself);
|
---|
54 | }
|
---|
55 |
|
---|
56 | /*
|
---|
57 | ** Parse an optional rect
|
---|
58 | */
|
---|
59 | static int
|
---|
60 | OptRectPtr_Convert(PyObject *v, Rect **p_itself)
|
---|
61 | {
|
---|
62 | static Rect r;
|
---|
63 |
|
---|
64 | if (v == Py_None)
|
---|
65 | {
|
---|
66 | *p_itself = NULL;
|
---|
67 | return 1;
|
---|
68 | }
|
---|
69 | *p_itself = &r;
|
---|
70 | return PyMac_GetRect(v, *p_itself);
|
---|
71 | }
|
---|
72 |
|
---|
73 | /*
|
---|
74 | ** Parse an optional GWorld
|
---|
75 | */
|
---|
76 | static int
|
---|
77 | OptGWorldObj_Convert(PyObject *v, GWorldPtr *p_itself)
|
---|
78 | {
|
---|
79 | if (v == Py_None)
|
---|
80 | {
|
---|
81 | *p_itself = NULL;
|
---|
82 | return 1;
|
---|
83 | }
|
---|
84 | return GWorldObj_Convert(v, p_itself);
|
---|
85 | }
|
---|
86 |
|
---|
87 | """
|
---|
88 |
|
---|
89 | initstuff = initstuff + """
|
---|
90 | // PyMac_INIT_TOOLBOX_OBJECT_NEW(xxxx);
|
---|
91 | """
|
---|
92 | TXNObject = OpaqueByValueType("TXNObject", "TXNObj")
|
---|
93 | TXNFontMenuObject = OpaqueByValueType("TXNFontMenuObject", "TXNFontMenuObj")
|
---|
94 |
|
---|
95 | TXNFrameID = Type("TXNFrameID", "l")
|
---|
96 | TXNVersionValue = Type("TXNVersionValue", "l")
|
---|
97 | TXNFeatureBits = Type("TXNFeatureBits", "l")
|
---|
98 | TXNInitOptions = Type("TXNInitOptions", "l")
|
---|
99 | TXNFrameOptions = Type("TXNFrameOptions", "l")
|
---|
100 | TXNContinuousFlags = Type("TXNContinuousFlags", "l")
|
---|
101 | TXNMatchOptions = Type("TXNMatchOptions", "l")
|
---|
102 | TXNFileType = OSTypeType("TXNFileType")
|
---|
103 | TXNFrameType = Type("TXNFrameType", "l")
|
---|
104 | TXNDataType = OSTypeType("TXNDataType")
|
---|
105 | TXNControlTag = OSTypeType("TXNControlTag")
|
---|
106 | TXNActionKey = Type("TXNActionKey", "l")
|
---|
107 | TXNTabType = Type("TXNTabType", "b")
|
---|
108 | TXNScrollBarState = Type("TXNScrollBarState", "l")
|
---|
109 | TXNOffset = Type("TXNOffset", "l")
|
---|
110 | TXNObjectRefcon = FakeType("(TXNObjectRefcon)0") # XXXX For now...
|
---|
111 | TXNErrors = OSErrType("TXNErrors", "l")
|
---|
112 | TXNTypeRunAttributes = OSTypeType("TXNTypeRunAttributes")
|
---|
113 | TXNTypeRunAttributeSizes = Type("TXNTypeRunAttributeSizes", "l")
|
---|
114 | TXNPermanentTextEncodingType = Type("TXNPermanentTextEncodingType", "l")
|
---|
115 | TXTNTag = OSTypeType("TXTNTag")
|
---|
116 | TXNBackgroundType = Type("TXNBackgroundType", "l")
|
---|
117 | DragReference = OpaqueByValueType("DragReference", "DragObj")
|
---|
118 | DragTrackingMessage = Type("DragTrackingMessage", "h")
|
---|
119 | RgnHandle = OpaqueByValueType("RgnHandle", "ResObj")
|
---|
120 | OptRgnHandle = OpaqueByValueType("RgnHandle", "OptResObj")
|
---|
121 | GWorldPtr = OpaqueByValueType("GWorldPtr", "GWorldObj")
|
---|
122 | OptGWorldPtr = OpaqueByValueType("GWorldPtr", "OptGWorldObj")
|
---|
123 | MlteInBuffer = VarInputBufferType('void *', 'ByteCount', 'l')
|
---|
124 |
|
---|
125 | OptFSSpecPtr = OpaqueByValueType("FSSpec *", "OptFSSpecPtr")
|
---|
126 | OptRectPtr = OpaqueByValueType("Rect *", "OptRectPtr")
|
---|
127 |
|
---|
128 | UniChar = Type("UniChar", "h") # XXXX For now...
|
---|
129 | # ADD object type here
|
---|
130 |
|
---|
131 | execfile("mltetypetest.py")
|
---|
132 |
|
---|
133 | # Our (opaque) objects
|
---|
134 |
|
---|
135 | class TXNObjDefinition(PEP253Mixin, GlobalObjectDefinition):
|
---|
136 | def outputCheckNewArg(self):
|
---|
137 | Output("if (itself == NULL) return PyMac_Error(resNotFound);")
|
---|
138 |
|
---|
139 | class TXNFontMenuObjDefinition(PEP253Mixin, GlobalObjectDefinition):
|
---|
140 | def outputCheckNewArg(self):
|
---|
141 | Output("if (itself == NULL) return PyMac_Error(resNotFound);")
|
---|
142 |
|
---|
143 |
|
---|
144 | # ADD object class here
|
---|
145 |
|
---|
146 | # From here on it's basically all boiler plate...
|
---|
147 |
|
---|
148 | # Create the generator groups and link them
|
---|
149 | module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
|
---|
150 | TXNObject_object = TXNObjDefinition("TXNObject", "TXNObj", "TXNObject")
|
---|
151 | TXNFontMenuObject_object = TXNFontMenuObjDefinition("TXNFontMenuObject", "TXNFontMenuObj", "TXNFontMenuObject")
|
---|
152 |
|
---|
153 | # ADD object here
|
---|
154 |
|
---|
155 | module.addobject(TXNObject_object)
|
---|
156 | module.addobject(TXNFontMenuObject_object)
|
---|
157 | # ADD addobject call here
|
---|
158 |
|
---|
159 | # Create the generator classes used to populate the lists
|
---|
160 | Function = OSErrWeakLinkFunctionGenerator
|
---|
161 | Method = OSErrWeakLinkMethodGenerator
|
---|
162 |
|
---|
163 | # Create and populate the lists
|
---|
164 | functions = []
|
---|
165 | TXNObject_methods = []
|
---|
166 | TXNFontMenuObject_methods = []
|
---|
167 |
|
---|
168 | # ADD _methods initializer here
|
---|
169 | execfile(INPUTFILE)
|
---|
170 |
|
---|
171 |
|
---|
172 | # add the populated lists to the generator groups
|
---|
173 | # (in a different wordl the scan program would generate this)
|
---|
174 | for f in functions: module.add(f)
|
---|
175 | for f in TXNObject_methods: TXNObject_object.add(f)
|
---|
176 | for f in TXNFontMenuObject_methods: TXNFontMenuObject_object.add(f)
|
---|
177 |
|
---|
178 | # ADD Manual generators here
|
---|
179 | inittextension_body = """
|
---|
180 | OSStatus _err;
|
---|
181 | TXNMacOSPreferredFontDescription * iDefaultFonts = NULL;
|
---|
182 | ItemCount iCountDefaultFonts = 0;
|
---|
183 | TXNInitOptions iUsageFlags;
|
---|
184 | PyMac_PRECHECK(TXNInitTextension);
|
---|
185 | if (!PyArg_ParseTuple(_args, "l", &iUsageFlags))
|
---|
186 | return NULL;
|
---|
187 | _err = TXNInitTextension(iDefaultFonts,
|
---|
188 | iCountDefaultFonts,
|
---|
189 | iUsageFlags);
|
---|
190 | if (_err != noErr) return PyMac_Error(_err);
|
---|
191 | Py_INCREF(Py_None);
|
---|
192 | _res = Py_None;
|
---|
193 | return _res;
|
---|
194 | """
|
---|
195 |
|
---|
196 | f = ManualGenerator("TXNInitTextension", inittextension_body);
|
---|
197 | f.docstring = lambda: "(TXNInitOptions) -> None"
|
---|
198 | module.add(f)
|
---|
199 |
|
---|
200 | # generate output (open the output file as late as possible)
|
---|
201 | SetOutputFileName(OUTPUTFILE)
|
---|
202 | module.generate()
|
---|