Add forgotten initialization. Fixes bug #120994, "Traceback with
[python/dscho.git] / Mac / Modules / qd / qdscan.py
blob7d2b57b713a9d90c3c6947b510bbfa8f4e837af6
1 # Scan an Apple header file, generating a Python file of generator calls.
3 import sys
4 import os
5 BGENDIR=os.path.join(sys.prefix, ':Tools:bgen:bgen')
6 sys.path.append(BGENDIR)
8 from scantools import Scanner
9 from bgenlocations import TOOLBOXDIR
11 def main():
12 input = "QuickDraw.h"
13 output = "qdgen.py"
14 defsoutput = TOOLBOXDIR + "QuickDraw.py"
15 scanner = MyScanner(input, output, defsoutput)
16 scanner.scan()
17 scanner.close()
19 # Grmpf. Universal Headers have Text-stuff in a different include file...
20 input = "QuickDrawText.h"
21 output = "@qdgentext.py"
22 defsoutput = "@QuickDrawText.py"
23 have_extra = 0
24 try:
25 scanner = MyScanner(input, output, defsoutput)
26 scanner.scan()
27 scanner.close()
28 have_extra = 1
29 except IOError:
30 pass
31 if have_extra:
32 print "=== Copying QuickDrawText stuff into main files... ==="
33 ifp = open("@qdgentext.py")
34 ofp = open("qdgen.py", "a")
35 ofp.write(ifp.read())
36 ifp.close()
37 ofp.close()
38 ifp = open("@QuickDrawText.py")
39 ofp = open(TOOLBOXDIR + "QuickDraw.py", "a")
40 ofp.write(ifp.read())
41 ifp.close()
42 ofp.close()
44 print "=== Done scanning and generating, now importing the generated code... ==="
45 import qdsupport
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"
53 if arglist:
54 t, n, m = arglist[0]
55 ## elif t == "PolyHandle" and m == "InMode":
56 ## classname = "Method"
57 ## listname = "p_methods"
58 ## elif t == "RgnHandle" and m == "InMode":
59 ## classname = "Method"
60 ## listname = "r_methods"
61 return classname, listname
64 def writeinitialdefs(self):
65 self.defsfile.write("""
66 def FOUR_CHAR_CODE(x): return x
67 normal = 0
68 bold = 1
69 italic = 2
70 underline = 4
71 outline = 8
72 shadow = 0x10
73 condense = 0x20
74 extend = 0x40
75 """)
77 def makeblacklistnames(self):
78 return [
79 'InitGraf',
80 'StuffHex',
81 'StdLine',
82 'StdComment',
83 'StdGetPic',
84 'OpenPort',
85 'InitPort',
86 'ClosePort',
87 'OpenCPort',
88 'InitCPort',
89 'CloseCPort',
90 'BitMapToRegionGlue',
91 'StdOpcode', # XXXX Missing from library...
92 # The following are for non-macos use:
93 'LockPortBits',
94 'UnlockPortBits',
95 'UpdatePort',
96 'GetPortNativeWindow',
97 'GetNativeWindowPort',
98 'NativeRegionToMacRegion',
99 'MacRegionToNativeRegion',
100 'GetPortHWND',
101 'GetHWNDPort',
102 'GetPICTFromDIB',
103 'GetPortBitMapForCopyBits', # Something funny in the declaration
107 def makegreylist(self):
108 return [
109 ('#if !TARGET_API_MAC_CARBON', [
111 ('#if TARGET_API_MAC_CARBON', [
115 def makeblacklisttypes(self):
116 return [
117 'CIconHandle', # Obsolete
118 'CQDProcs',
119 'CQDProcsPtr',
120 'CSpecArray',
121 'ColorComplementProcPtr',
122 'ColorComplementUPP',
123 'ColorSearchProcPtr',
124 'ColorSearchUPP',
125 'ConstPatternParam',
126 'DeviceLoopDrawingProcPtr',
127 'DeviceLoopFlags',
128 'GrafVerb',
129 'OpenCPicParams_ptr',
130 'Ptr',
131 'QDProcs',
132 'ReqListRec',
133 'void_ptr',
134 'CustomXFerProcPtr',
137 def makerepairinstructions(self):
138 return [
139 ([('void_ptr', 'textBuf', 'InMode'),
140 ('short', 'firstByte', 'InMode'),
141 ('short', 'byteCount', 'InMode')],
142 [('TextThingie', '*', '*'), ('*', '*', '*'), ('*', '*', '*')]),
144 # GetPen and SetPt use a point-pointer as output-only:
145 ('GetPen', [('Point', '*', 'OutMode')], [('*', '*', 'OutMode')]),
146 ('SetPt', [('Point', '*', 'OutMode')], [('*', '*', 'OutMode')]),
148 # All others use it as input/output:
149 ([('Point', '*', 'OutMode')],
150 [('*', '*', 'InOutMode')]),
152 # InsetRect, OffsetRect
153 ([('Rect', 'r', 'OutMode'),
154 ('short', 'dh', 'InMode'),
155 ('short', 'dv', 'InMode')],
156 [('Rect', 'r', 'InOutMode'),
157 ('short', 'dh', 'InMode'),
158 ('short', 'dv', 'InMode')]),
160 # MapRect
161 ([('Rect', 'r', 'OutMode'),
162 ('Rect_ptr', 'srcRect', 'InMode'),
163 ('Rect_ptr', 'dstRect', 'InMode')],
164 [('Rect', 'r', 'InOutMode'),
165 ('Rect_ptr', 'srcRect', 'InMode'),
166 ('Rect_ptr', 'dstRect', 'InMode')]),
168 # CopyBits and friends
169 ([('RgnHandle', 'maskRgn', 'InMode')],
170 [('OptRgnHandle', 'maskRgn', 'InMode')]),
174 if __name__ == "__main__":
175 main()