openfile(): Go back to opening the files in text mode. This undoes
[python/dscho.git] / Mac / Modules / win / winscan.py
blob06b421f830a744a2a72fbea79cf616bfb3117f4f
1 # Scan an Apple header file, generating a Python file of generator calls.
2 import sys
3 import os
4 from bgenlocations import TOOLBOXDIR, BGENDIR
5 sys.path.append(BGENDIR)
7 from scantools import Scanner
9 def main():
10 input = "MacWindows.h"
11 output = "wingen.py"
12 defsoutput = TOOLBOXDIR + "Windows.py"
13 scanner = MyScanner(input, output, defsoutput)
14 scanner.scan()
15 scanner.close()
16 print "=== Testing definitions output code ==="
17 execfile(defsoutput, {}, {})
18 print "=== Done scanning and generating, now importing the generated code... ==="
19 import winsupport
20 print "=== Done. It's up to you to compile it now! ==="
22 class MyScanner(Scanner):
24 def destination(self, type, name, arglist):
25 classname = "Function"
26 listname = "functions"
27 if arglist:
28 t, n, m = arglist[0]
29 if t in ("WindowPtr", "WindowPeek", "WindowRef") and m == "InMode":
30 classname = "Method"
31 listname = "methods"
32 return classname, listname
34 def writeinitialdefs(self):
35 self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
36 self.defsfile.write("false = 0\n")
37 self.defsfile.write("true = 1\n")
39 def makeblacklistnames(self):
40 return [
41 'DisposeWindow', # Implied when the object is deleted
42 'CloseWindow',
43 'SetWindowProperty', # For the moment
44 'GetWindowProperty',
45 'GetWindowPropertySize',
46 'RemoveWindowProperty',
47 'MacCloseWindow',
48 'GetWindowList', # Don't know whether this is safe...
49 # Constants with funny definitions
50 'kMouseUpOutOfSlop',
51 'kAllWindowClasses',
54 def makegreylist(self):
55 return [
56 ('#if !TARGET_API_MAC_CARBON', [
57 'GetAuxWin',
58 'GetWindowDataHandle',
59 'SaveOld',
60 'DrawNew',
61 'SetWinColor',
62 'SetDeskCPat',
63 'InitWindows',
64 'InitFloatingWindows',
65 'GetWMgrPort',
66 'GetCWMgrPort',
67 'ValidRgn', # Use versions with Window in their name
68 'ValidRect',
69 'InvalRgn',
70 'InvalRect',
71 'IsValidWindowPtr', # I think this is useless for Python, but not sure...
72 'GetWindowZoomFlag', # Not available in Carbon
73 'GetWindowTitleWidth', # Ditto
74 'GetWindowGoAwayFlag',
75 'GetWindowSpareFlag',
76 ]),
77 ('#if !TARGET_API_MAC_OS8', [
78 'IsWindowUpdatePending',
79 'FindWindowOfClass',
80 'GetFrontWindowOfClass',
81 'ChangeWindowPropertyAttributes',
82 'GetWindowPropertyAttributes',
83 'GetNextWindowOfClass',
84 'ScrollWindowRegion',
85 'ScrollWindowRect',
86 'ChangeWindowAttributes',
87 'ReshapeCustomWindow',
88 'EnableScreenUpdates',
89 'DisableScreenUpdates',
90 'GetAvailableWindowPositioningBounds',
91 'CreateStandardWindowMenu',
92 'GetSheetWindowParent',
93 'HideSheetWindow',
94 'ShowSheetWindow',
95 'ConstrainWindowToScreen',
96 'GetWindowGreatestAreaDevice',
97 'CopyWindowTitleAsCFString',
98 'SetWindowTitleWithCFString',
99 'CopyWindowAlternateTitle',
100 'SetWindowAlternateTitle',
101 'GetWindowModality',
102 'SetWindowModality',
103 'SetWindowClass',
104 'ReleaseWindow',
105 'RetainWindow',
106 'GetWindowRetainCount',
108 ('#if TARGET_API_MAC_OSX', [
109 'TransitionWindowAndParent',
112 def makeblacklisttypes(self):
113 return [
114 'ProcPtr',
115 'DragGrayRgnUPP',
116 'WindowPaintUPP',
117 'Collection', # For now, to be done later
118 'WindowDefSpec', # Too difficult for now
119 'WindowDefSpec_ptr',
120 'EventRef', #TBD
123 def makerepairinstructions(self):
124 return [
126 # GetWTitle
127 ([("Str255", "*", "InMode")],
128 [("*", "*", "OutMode")]),
130 ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")],
131 [("InBuffer", "*", "*")]),
133 ([("void", "*", "OutMode"), ("long", "*", "InMode"),
134 ("long", "*", "OutMode")],
135 [("VarVarOutBuffer", "*", "InOutMode")]),
137 ([("void", "wStorage", "OutMode")],
138 [("NullStorage", "*", "InMode")]),
140 # match FindWindowOfClass
141 ([("WindowRef", "outWindow", "OutMode"), ("WindowPartCode", "outWindowPart", "OutMode")],
142 [("ExistingWindowPtr", "*", "OutMode"), ("WindowPartCode", "outWindowPart", "OutMode")]),
143 # then match CreateNewWindow and CreateWindowFromResource
144 ([("WindowRef", "outWindow", "OutMode")],
145 [("WindowRef", "*", "*")]),
147 ([("WindowPtr", "*", "OutMode")],
148 [("ExistingWindowPtr", "*", "*")]),
149 ([("WindowRef", "*", "OutMode")], # Same, but other style headerfiles
150 [("ExistingWindowPtr", "*", "*")]),
152 ([("WindowPtr", "FrontWindow", "ReturnMode")],
153 [("ExistingWindowPtr", "*", "*")]),
154 ([("WindowRef", "FrontWindow", "ReturnMode")], # Ditto
155 [("ExistingWindowPtr", "*", "*")]),
156 ([("WindowPtr", "FrontNonFloatingWindow", "ReturnMode")],
157 [("ExistingWindowPtr", "*", "*")]),
158 ([("WindowRef", "FrontNonFloatingWindow", "ReturnMode")], # Ditto
159 [("ExistingWindowPtr", "*", "*")]),
161 ([("Rect_ptr", "*", "ReturnMode")], # GetWindowXXXState accessors
162 [("void", "*", "ReturnMode")]),
165 if __name__ == "__main__":
166 main()