Teach Windows build and installer about new _symtable module/DLL.
[python/dscho.git] / Mac / Modules / drag / dragsupport.py
blobd90acc998deeeb1a30aa7622948b15922bc64387
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).
6 import string
8 # Declarations that change for each manager
9 MACHEADERFILE = 'Drag.h' # The Apple header file
10 MODNAME = 'Drag' # The name of the module
11 OBJECTNAME = 'DragObj' # The basic name of the objects used here
13 # The following is *usually* unchanged but may still require tuning
14 MODPREFIX = MODNAME # The prefix for module-wide routines
15 OBJECTTYPE = 'DragRef' # The C type used to represent them
16 OBJECTPREFIX = MODPREFIX + 'Obj' # The prefix for object methods
17 INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner
18 OUTPUTFILE = MODNAME + "module.c" # The file generated by this program
20 from macsupport import *
22 # Create the type objects
24 DragRef = OpaqueByValueType(OBJECTTYPE, OBJECTPREFIX)
25 DragItemRef = Type("ItemReference", "l")
26 # Old names
27 DragReference = DragRef
28 ItemReference = DragItemRef
30 PixMapHandle = OpaqueByValueType("PixMapHandle", "ResObj")
31 RgnHandle = OpaqueByValueType("RgnHandle", "ResObj")
32 AEDesc = OpaqueType('AEDesc')
33 AEDesc_ptr = AEDesc
34 RGBColor = OpaqueType("RGBColor", "QdRGB")
36 FlavorType = OSTypeType("FlavorType")
37 DragAttributes = Type("DragAttributes", "l")
38 DragBehaviors = Type("DragBehaviors", "l")
39 DragImageFlags = Type("DragImageFlags", "l")
40 DragImageTranslucency = Type("DragImageTranslucency", "l")
41 DragRegionMessage = Type("DragRegionMessage", "h")
42 ZoomAcceleration = Type("ZoomAcceleration", "h")
43 FlavorFlags = Type("FlavorFlags", "l")
44 DragTrackingMessage = Type("DragTrackingMessage", "h")
46 includestuff = includestuff + """
47 #include <%s>""" % MACHEADERFILE + """
49 /* Callback glue routines */
50 DragTrackingHandlerUPP dragglue_TrackingHandlerUPP;
51 DragReceiveHandlerUPP dragglue_ReceiveHandlerUPP;
52 DragSendDataUPP dragglue_SendDataUPP;
53 #if 0
54 DragInputUPP dragglue_InputUPP;
55 DragDrawingUPP dragglue_DrawingUPP;
56 #endif
57 """
59 finalstuff = finalstuff + """
60 static pascal OSErr
61 dragglue_TrackingHandler(DragTrackingMessage theMessage, WindowPtr theWindow,
62 void *handlerRefCon, DragReference theDrag)
64 PyObject *args, *rv;
65 int i;
67 args = Py_BuildValue("hO&O&", theMessage, DragObj_New, theDrag, WinObj_WhichWindow, theWindow);
68 if ( args == NULL )
69 return -1;
70 rv = PyEval_CallObject((PyObject *)handlerRefCon, args);
71 Py_DECREF(args);
72 if ( rv == NULL ) {
73 fprintf(stderr, "Drag: Exception in TrackingHandler\\n");
74 return -1;
76 i = -1;
77 if ( rv == Py_None )
78 i = 0;
79 else
80 PyArg_Parse(rv, "l", &i);
81 Py_DECREF(rv);
82 return i;
85 static pascal OSErr
86 dragglue_ReceiveHandler(WindowPtr theWindow, void *handlerRefCon,
87 DragReference theDrag)
89 PyObject *args, *rv;
90 int i;
92 args = Py_BuildValue("O&O&", DragObj_New, theDrag, WinObj_WhichWindow, theWindow);
93 if ( args == NULL )
94 return -1;
95 rv = PyEval_CallObject((PyObject *)handlerRefCon, args);
96 Py_DECREF(args);
97 if ( rv == NULL ) {
98 fprintf(stderr, "Drag: Exception in ReceiveHandler\\n");
99 return -1;
101 i = -1;
102 if ( rv == Py_None )
103 i = 0;
104 else
105 PyArg_Parse(rv, "l", &i);
106 Py_DECREF(rv);
107 return i;
110 static pascal OSErr
111 dragglue_SendData(FlavorType theType, void *dragSendRefCon,
112 ItemReference theItem, DragReference theDrag)
114 DragObjObject *self = (DragObjObject *)dragSendRefCon;
115 PyObject *args, *rv;
116 int i;
118 if ( self->sendproc == NULL )
119 return -1;
120 args = Py_BuildValue("O&l", PyMac_BuildOSType, theType, theItem);
121 if ( args == NULL )
122 return -1;
123 rv = PyEval_CallObject(self->sendproc, args);
124 Py_DECREF(args);
125 if ( rv == NULL ) {
126 fprintf(stderr, "Drag: Exception in SendDataHandler\\n");
127 return -1;
129 i = -1;
130 if ( rv == Py_None )
131 i = 0;
132 else
133 PyArg_Parse(rv, "l", &i);
134 Py_DECREF(rv);
135 return i;
138 #if 0
139 static pascal OSErr
140 dragglue_Input(Point *mouse, short *modifiers,
141 void *dragSendRefCon, DragReference theDrag)
143 return 0;
146 static pascal OSErr
147 dragglue_Drawing(xxxx
148 void *dragSendRefCon, DragReference theDrag)
150 return 0;
152 #endif
156 variablestuff = """
157 dragglue_TrackingHandlerUPP = NewDragTrackingHandlerProc(dragglue_TrackingHandler);
158 dragglue_ReceiveHandlerUPP = NewDragReceiveHandlerProc(dragglue_ReceiveHandler);
159 dragglue_SendDataUPP = NewDragSendDataProc(dragglue_SendData);
160 #if 0
161 dragglue_InputUPP = NewDragInputProc(dragglue_Input);
162 dragglue_DrawingUPP = NewDragDrawingProc(dragglue_Drawing);
163 #endif
164 """
166 class MyObjectDefinition(GlobalObjectDefinition):
167 def outputCheckNewArg(self):
168 Output("""if (itself == NULL) {
169 PyErr_SetString(Drag_Error,"Cannot create null Drag");
170 return NULL;
171 }""")
172 def outputFreeIt(self, itselfname):
173 ## Output("DisposeDrag(%s);", itselfname)
174 Output("Py_XDECREF(self->sendproc);")
175 ## Output("Py_XDECREF(self->inputproc);")
176 ## Output("Py_XDECREF(self->drawingproc);")
178 def outputStructMembers(self):
179 GlobalObjectDefinition.outputStructMembers(self)
180 Output("PyObject *sendproc;")
181 ## Output("PyObject *inputproc;")
182 ## Output("PyObject *drawingproc;")
184 def outputInitStructMembers(self):
185 GlobalObjectDefinition.outputInitStructMembers(self)
186 Output("it->sendproc = NULL;")
187 ## Output("it->inputproc = NULL;")
188 ## Output("it->drawingproc = NULL;")
191 # Create the generator groups and link them
192 module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff, variablestuff)
193 object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE)
194 module.addobject(object)
196 # Create the generator classes used to populate the lists
197 Function = OSErrFunctionGenerator
198 Method = OSErrMethodGenerator
200 # Create and populate the lists
201 functions = []
202 methods = []
203 execfile(INPUTFILE)
205 # add the populated lists to the generator groups
206 for f in functions: module.add(f)
207 for f in methods: object.add(f)
209 # Manual generators for the callbacks
211 installtracking_body = """
212 PyObject *callback;
213 WindowPtr theWindow = NULL;
214 OSErr _err;
216 if ( !PyArg_ParseTuple(_args, "O|O&", &callback, WinObj_Convert, &theWindow) )
217 return NULL;
218 Py_INCREF(callback); /* Cannot decref later, too bad */
219 _err = InstallTrackingHandler(dragglue_TrackingHandlerUPP, theWindow, (void *)callback);
220 if (_err != noErr) return PyMac_Error(_err);
221 Py_INCREF(Py_None);
222 return Py_None;
224 installtracking = ManualGenerator("InstallTrackingHandler", installtracking_body)
225 module.add(installtracking)
227 installreceive_body = """
228 PyObject *callback;
229 WindowPtr theWindow = NULL;
230 OSErr _err;
232 if ( !PyArg_ParseTuple(_args, "O|O&", &callback, WinObj_Convert, &theWindow) )
233 return NULL;
234 Py_INCREF(callback); /* Cannot decref later, too bad */
235 _err = InstallReceiveHandler(dragglue_ReceiveHandlerUPP, theWindow, (void *)callback);
236 if (_err != noErr) return PyMac_Error(_err);
237 Py_INCREF(Py_None);
238 return Py_None;
240 installreceive = ManualGenerator("InstallReceiveHandler", installreceive_body)
241 module.add(installreceive)
243 removetracking_body = """
244 WindowPtr theWindow = NULL;
245 OSErr _err;
247 if ( !PyArg_ParseTuple(_args, "|O&", WinObj_Convert, &theWindow) )
248 return NULL;
249 _err = RemoveTrackingHandler(dragglue_TrackingHandlerUPP, theWindow);
250 if (_err != noErr) return PyMac_Error(_err);
251 Py_INCREF(Py_None);
252 return Py_None;
254 removetracking = ManualGenerator("RemoveTrackingHandler", removetracking_body)
255 module.add(removetracking)
257 removereceive_body = """
258 WindowPtr theWindow = NULL;
259 OSErr _err;
261 if ( !PyArg_ParseTuple(_args, "|O&", WinObj_Convert, &theWindow) )
262 return NULL;
263 _err = RemoveReceiveHandler(dragglue_ReceiveHandlerUPP, theWindow);
264 if (_err != noErr) return PyMac_Error(_err);
265 Py_INCREF(Py_None);
266 return Py_None;
268 removereceive = ManualGenerator("RemoveReceiveHandler", removereceive_body)
269 module.add(removereceive)
271 # generate output (open the output file as late as possible)
272 SetOutputFileName(OUTPUTFILE)
273 module.generate()