PageRenderTime 40ms CodeModel.GetById 16ms app.highlight 19ms RepoModel.GetById 1ms app.codeStats 0ms

/Mac/Modules/mlte/mltesupport.py

http://unladen-swallow.googlecode.com/
Python | 202 lines | 187 code | 7 blank | 8 comment | 0 complexity | 7c4a01d4845b11ba50616ff744c3db32 MD5 | raw file
  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
  8import string
  9
 10# Declarations that change for each manager
 11MODNAME = '_Mlte'                               # The name of the module
 12
 13# The following is *usually* unchanged but may still require tuning
 14MODPREFIX = 'Mlte'                      # The prefix for module-wide routines
 15INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner
 16OUTPUTFILE = MODNAME + "module.c"       # The file generated by this program
 17
 18from macsupport import *
 19
 20# Create the type objects
 21
 22includestuff = includestuff + """
 23#include <Carbon/Carbon.h>
 24
 25/* For now we declare them forward here. They'll go to mactoolbox later */
 26static PyObject *TXNObj_New(TXNObject);
 27static int TXNObj_Convert(PyObject *, TXNObject *);
 28static PyObject *TXNFontMenuObj_New(TXNFontMenuObject);
 29static 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*/
 43static int
 44OptFSSpecPtr_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*/
 59static int
 60OptRectPtr_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*/
 76static int
 77OptGWorldObj_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
 89initstuff = initstuff + """
 90//      PyMac_INIT_TOOLBOX_OBJECT_NEW(xxxx);
 91"""
 92TXNObject = OpaqueByValueType("TXNObject", "TXNObj")
 93TXNFontMenuObject = OpaqueByValueType("TXNFontMenuObject", "TXNFontMenuObj")
 94
 95TXNFrameID = Type("TXNFrameID", "l")
 96TXNVersionValue = Type("TXNVersionValue", "l")
 97TXNFeatureBits = Type("TXNFeatureBits", "l")
 98TXNInitOptions = Type("TXNInitOptions", "l")
 99TXNFrameOptions = Type("TXNFrameOptions", "l")
100TXNContinuousFlags = Type("TXNContinuousFlags", "l")
101TXNMatchOptions = Type("TXNMatchOptions", "l")
102TXNFileType = OSTypeType("TXNFileType")
103TXNFrameType = Type("TXNFrameType", "l")
104TXNDataType = OSTypeType("TXNDataType")
105TXNControlTag = OSTypeType("TXNControlTag")
106TXNActionKey = Type("TXNActionKey", "l")
107TXNTabType = Type("TXNTabType", "b")
108TXNScrollBarState = Type("TXNScrollBarState", "l")
109TXNOffset = Type("TXNOffset", "l")
110TXNObjectRefcon = FakeType("(TXNObjectRefcon)0") # XXXX For now...
111TXNErrors = OSErrType("TXNErrors", "l")
112TXNTypeRunAttributes = OSTypeType("TXNTypeRunAttributes")
113TXNTypeRunAttributeSizes = Type("TXNTypeRunAttributeSizes", "l")
114TXNPermanentTextEncodingType = Type("TXNPermanentTextEncodingType", "l")
115TXTNTag = OSTypeType("TXTNTag")
116TXNBackgroundType = Type("TXNBackgroundType", "l")
117DragReference = OpaqueByValueType("DragReference", "DragObj")
118DragTrackingMessage = Type("DragTrackingMessage", "h")
119RgnHandle = OpaqueByValueType("RgnHandle", "ResObj")
120OptRgnHandle = OpaqueByValueType("RgnHandle", "OptResObj")
121GWorldPtr = OpaqueByValueType("GWorldPtr", "GWorldObj")
122OptGWorldPtr = OpaqueByValueType("GWorldPtr", "OptGWorldObj")
123MlteInBuffer = VarInputBufferType('void *', 'ByteCount', 'l')
124
125OptFSSpecPtr = OpaqueByValueType("FSSpec *", "OptFSSpecPtr")
126OptRectPtr = OpaqueByValueType("Rect *", "OptRectPtr")
127
128UniChar = Type("UniChar", "h") # XXXX For now...
129# ADD object type here
130
131execfile("mltetypetest.py")
132
133# Our (opaque) objects
134
135class TXNObjDefinition(PEP253Mixin, GlobalObjectDefinition):
136    def outputCheckNewArg(self):
137        Output("if (itself == NULL) return PyMac_Error(resNotFound);")
138
139class 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
149module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
150TXNObject_object = TXNObjDefinition("TXNObject", "TXNObj", "TXNObject")
151TXNFontMenuObject_object = TXNFontMenuObjDefinition("TXNFontMenuObject", "TXNFontMenuObj", "TXNFontMenuObject")
152
153# ADD object here
154
155module.addobject(TXNObject_object)
156module.addobject(TXNFontMenuObject_object)
157# ADD addobject call here
158
159# Create the generator classes used to populate the lists
160Function = OSErrWeakLinkFunctionGenerator
161Method = OSErrWeakLinkMethodGenerator
162
163# Create and populate the lists
164functions = []
165TXNObject_methods = []
166TXNFontMenuObject_methods = []
167
168# ADD _methods initializer here
169execfile(INPUTFILE)
170
171
172# add the populated lists to the generator groups
173# (in a different wordl the scan program would generate this)
174for f in functions: module.add(f)
175for f in TXNObject_methods: TXNObject_object.add(f)
176for f in TXNFontMenuObject_methods: TXNFontMenuObject_object.add(f)
177
178# ADD Manual generators here
179inittextension_body = """
180OSStatus _err;
181TXNMacOSPreferredFontDescription * iDefaultFonts = NULL;
182ItemCount iCountDefaultFonts = 0;
183TXNInitOptions iUsageFlags;
184PyMac_PRECHECK(TXNInitTextension);
185if (!PyArg_ParseTuple(_args, "l", &iUsageFlags))
186        return NULL;
187_err = TXNInitTextension(iDefaultFonts,
188                         iCountDefaultFonts,
189                         iUsageFlags);
190if (_err != noErr) return PyMac_Error(_err);
191Py_INCREF(Py_None);
192_res = Py_None;
193return _res;
194"""
195
196f = ManualGenerator("TXNInitTextension", inittextension_body);
197f.docstring = lambda: "(TXNInitOptions) -> None"
198module.add(f)
199
200# generate output (open the output file as late as possible)
201SetOutputFileName(OUTPUTFILE)
202module.generate()