1 # Scan an Apple header file, generating a Python file of generator calls.
3 from bgenlocations
import TOOLBOXDIR
, BGENDIR
4 sys
.path
.append(BGENDIR
)
6 from scantools
import Scanner
11 defsoutput
= TOOLBOXDIR
+ "Windows.py"
12 scanner
= MyScanner(input, output
, defsoutput
)
15 print "=== Testing definitions output code ==="
16 execfile(defsoutput
, {}, {})
17 print "=== Done scanning and generating, now importing the generated code... ==="
19 print "=== Done. It's up to you to compile it now! ==="
21 class MyScanner(Scanner
):
23 def destination(self
, type, name
, arglist
):
24 classname
= "Function"
25 listname
= "functions"
28 if t
in ("WindowPtr", "WindowPeek", "WindowRef") and m
== "InMode":
31 return classname
, listname
33 def writeinitialdefs(self
):
34 self
.defsfile
.write("def FOUR_CHAR_CODE(x): return x\n")
35 self
.defsfile
.write("false = 0\n")
36 self
.defsfile
.write("true = 1\n")
37 self
.defsfile
.write("kWindowNoConstrainAttribute = 0x80000000\n")
39 def makeblacklistnames(self
):
41 'DisposeWindow', # Implied when the object is deleted
43 'SetWindowProperty', # For the moment
45 'GetWindowPropertySize',
46 'RemoveWindowProperty',
48 'GetWindowList', # Don't know whether this is safe...
49 # Constants with funny definitions
52 'kWindowNoConstrainAttribute',
55 'GetWindowDataHandle',
61 'InitFloatingWindows',
64 'ValidRgn', # Use versions with Window in their name
68 'IsValidWindowPtr', # I think this is useless for Python, but not sure...
69 'GetWindowZoomFlag', # Not available in Carbon
70 'GetWindowTitleWidth', # Ditto
71 'GetWindowGoAwayFlag',
75 def makeblacklisttypes(self
):
80 'Collection', # For now, to be done later
81 'WindowDefSpec', # Too difficult for now
86 def makerepairinstructions(self
):
90 ([("Str255", "*", "InMode")],
91 [("*", "*", "OutMode")]),
93 ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")],
94 [("InBuffer", "*", "*")]),
96 ([("void", "*", "OutMode"), ("long", "*", "InMode"),
97 ("long", "*", "OutMode")],
98 [("VarVarOutBuffer", "*", "InOutMode")]),
100 ([("void", "wStorage", "OutMode")],
101 [("NullStorage", "*", "InMode")]),
103 # match FindWindowOfClass
104 ([("WindowRef", "outWindow", "OutMode"), ("WindowPartCode", "outWindowPart", "OutMode")],
105 [("ExistingWindowPtr", "*", "OutMode"), ("WindowPartCode", "outWindowPart", "OutMode")]),
106 # then match CreateNewWindow and CreateWindowFromResource
107 ([("WindowRef", "outWindow", "OutMode")],
108 [("WindowRef", "*", "*")]),
110 ([("WindowPtr", "*", "OutMode")],
111 [("ExistingWindowPtr", "*", "*")]),
112 ([("WindowRef", "*", "OutMode")], # Same, but other style headerfiles
113 [("ExistingWindowPtr", "*", "*")]),
115 ([("WindowPtr", "FrontWindow", "ReturnMode")],
116 [("ExistingWindowPtr", "*", "*")]),
117 ([("WindowRef", "FrontWindow", "ReturnMode")], # Ditto
118 [("ExistingWindowPtr", "*", "*")]),
119 ([("WindowPtr", "FrontNonFloatingWindow", "ReturnMode")],
120 [("ExistingWindowPtr", "*", "*")]),
121 ([("WindowRef", "FrontNonFloatingWindow", "ReturnMode")], # Ditto
122 [("ExistingWindowPtr", "*", "*")]),
124 ([("Rect_ptr", "*", "ReturnMode")], # GetWindowXXXState accessors
125 [("void", "*", "ReturnMode")]),
128 if __name__
== "__main__":