1
# Scan an Apple header file, generating a Python file of generator calls.
4
from bgenlocations import TOOLBOXDIR, BGENDIR
5
sys.path.append(BGENDIR)
7
from scantools import Scanner
12
defsoutput = TOOLBOXDIR + "QuickDraw.py"
13
scanner = MyScanner(input, output, defsoutput)
17
# Grmpf. Universal Headers have Text-stuff in a different include file...
18
input = "QuickDrawText.h"
19
output = "@qdgentext.py"
20
defsoutput = "@QuickDrawText.py"
23
scanner = MyScanner(input, output, defsoutput)
30
print "=== Copying QuickDrawText stuff into main files... ==="
31
ifp = open("@qdgentext.py")
32
ofp = open("qdgen.py", "a")
36
ifp = open("@QuickDrawText.py")
37
ofp = open(TOOLBOXDIR + "QuickDraw.py", "a")
42
print "=== Testing definitions output code ==="
43
execfile(defsoutput, {}, {})
44
print "=== Done scanning and generating, now importing the generated code... ==="
46
print "=== Done. It's up to you to compile it now! ==="
48
class MyScanner(Scanner):
50
def destination(self, type, name, arglist):
51
classname = "Function"
52
listname = "functions"
55
if t in ('GrafPtr', 'CGrafPtr') and m == 'InMode':
57
listname = "gr_methods"
58
elif t == 'BitMapPtr' and m == 'InMode':
60
listname = "bm_methods"
61
## elif t == "PolyHandle" and m == "InMode":
62
## classname = "Method"
63
## listname = "p_methods"
64
## elif t == "RgnHandle" and m == "InMode":
65
## classname = "Method"
66
## listname = "r_methods"
67
return classname, listname
70
def writeinitialdefs(self):
71
self.defsfile.write("""
72
def FOUR_CHAR_CODE(x): return x
83
def makeblacklistnames(self):
97
'StdOpcode', # XXXX Missing from library...
98
# The following are for non-macos use:
102
'GetPortNativeWindow',
103
'GetNativeWindowPort',
104
'NativeRegionToMacRegion',
105
'MacRegionToNativeRegion',
110
'HandleToRgn', # Funny signature
112
# Need Cm, which we don't want to drag in just yet
113
'OpenCursorComponent',
114
'CloseCursorComponent',
115
'SetCursorComponent',
116
'CursorComponentChanged',
117
'CursorComponentSetData',
120
def makeblacklisttypes(self):
122
"QDRegionBitsRef", # Should do this, but too lazy now.
123
'CIconHandle', # Obsolete
127
'ColorComplementProcPtr',
128
'ColorComplementUPP',
129
'ColorSearchProcPtr',
132
'DeviceLoopDrawingProcPtr',
135
'OpenCPicParams_ptr',
143
def makerepairinstructions(self):
145
([('void_ptr', 'textBuf', 'InMode'),
146
('short', 'firstByte', 'InMode'),
147
('short', 'byteCount', 'InMode')],
148
[('TextThingie', '*', '*'), ('*', '*', '*'), ('*', '*', '*')]),
150
# GetPen and SetPt use a point-pointer as output-only:
151
('GetPen', [('Point', '*', 'OutMode')], [('*', '*', 'OutMode')]),
152
('SetPt', [('Point', '*', 'OutMode')], [('*', '*', 'OutMode')]),
154
# All others use it as input/output:
155
([('Point', '*', 'OutMode')],
156
[('*', '*', 'InOutMode')]),
158
# InsetRect, OffsetRect
159
([('Rect', 'r', 'OutMode'),
160
('short', 'dh', 'InMode'),
161
('short', 'dv', 'InMode')],
162
[('Rect', 'r', 'InOutMode'),
163
('short', 'dh', 'InMode'),
164
('short', 'dv', 'InMode')]),
167
([('Rect', 'r', 'OutMode'),
168
('Rect_ptr', 'srcRect', 'InMode'),
169
('Rect_ptr', 'dstRect', 'InMode')],
170
[('Rect', 'r', 'InOutMode'),
171
('Rect_ptr', 'srcRect', 'InMode'),
172
('Rect_ptr', 'dstRect', 'InMode')]),
174
# CopyBits and friends
175
([('RgnHandle', 'maskRgn', 'InMode')],
176
[('OptRgnHandle', 'maskRgn', 'InMode')]),
178
('QDFlushPortBuffer',
179
[('RgnHandle', '*', 'InMode')],
180
[('OptRgnHandle', '*', 'InMode')]),
182
# Accessors with reference argument also returned.
183
([('Rect_ptr', 'GetPortBounds', 'ReturnMode')],
184
[('void', '*', 'ReturnMode')]),
186
([('RGBColor_ptr', 'GetPortForeColor', 'ReturnMode')],
187
[('void', '*', 'ReturnMode')]),
189
([('RGBColor_ptr', 'GetPortBackColor', 'ReturnMode')],
190
[('void', '*', 'ReturnMode')]),
192
([('RGBColor_ptr', 'GetPortOpColor', 'ReturnMode')],
193
[('void', '*', 'ReturnMode')]),
195
([('RGBColor_ptr', 'GetPortHiliteColor', 'ReturnMode')],
196
[('void', '*', 'ReturnMode')]),
198
([('Point_ptr', 'GetPortPenSize', 'ReturnMode')],
199
[('void', '*', 'ReturnMode')]),
201
([('Point_ptr', 'GetPortPenLocation', 'ReturnMode')],
202
[('void', '*', 'ReturnMode')]),
204
([('Rect_ptr', 'GetPixBounds', 'ReturnMode')],
205
[('void', '*', 'ReturnMode')]),
207
([('BitMap_ptr', 'GetQDGlobalsScreenBits', 'ReturnMode')],
208
[('void', '*', 'ReturnMode')]),
210
([('Cursor_ptr', 'GetQDGlobalsArrow', 'ReturnMode')],
211
[('void', '*', 'ReturnMode')]),
213
([('Rect_ptr', 'GetRegionBounds', 'ReturnMode')],
214
[('void', '*', 'ReturnMode')]),
216
([('Pattern_ptr', '*', 'ReturnMode')],
217
[('void', '*', 'ReturnMode')]),
219
([('Point_ptr', 'QDLocalToGlobalPoint', 'ReturnMode')],
220
[('void', '*', 'ReturnMode')]),
222
([('Rect_ptr', 'QDLocalToGlobalRect', 'ReturnMode')],
223
[('void', '*', 'ReturnMode')]),
225
([('Point_ptr', 'QDGlobalToLocalPoint', 'ReturnMode')],
226
[('void', '*', 'ReturnMode')]),
228
([('Rect_ptr', 'QDGlobalToLocalRect', 'ReturnMode')],
229
[('void', '*', 'ReturnMode')]),
233
if __name__ == "__main__":