1 # Scan an Apple header file, generating a Python file of generator calls.
4 BGENDIR
=os
.path
.join(sys
.prefix
, ':Tools:bgen:bgen')
5 sys
.path
.append(BGENDIR
)
6 from bgenlocations
import TOOLBOXDIR
8 from scantools
import Scanner
11 input = "MacWindows.h"
13 defsoutput
= TOOLBOXDIR
+ "Windows.py"
14 scanner
= MyScanner(input, output
, 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")
36 def makeblacklistnames(self
):
38 'DisposeWindow', # Implied when the object is deleted
40 'SetWindowProperty', # For the moment
42 'GetWindowPropertySize',
43 'RemoveWindowProperty',
45 # Constants with funny definitions
49 def makegreylist(self
):
51 ('#if !TARGET_API_MAC_CARBON', [
53 'GetWindowDataHandle',
59 'InitFloatingWindows',
62 'ValidRgn', # Use versions with Window in their name
66 'IsValidWindowPtr', # I think this is useless for Python, but not sure...
69 def makeblacklisttypes(self
):
73 'Collection', # For now, to be done later
74 'DragReference', # Ditto, dragmodule doesn't export it yet.
77 def makerepairinstructions(self
):
81 ([("Str255", "*", "InMode")],
82 [("*", "*", "OutMode")]),
84 ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")],
85 [("InBuffer", "*", "*")]),
87 ([("void", "*", "OutMode"), ("long", "*", "InMode"),
88 ("long", "*", "OutMode")],
89 [("VarVarOutBuffer", "*", "InOutMode")]),
91 ([("void", "wStorage", "OutMode")],
92 [("NullStorage", "*", "InMode")]),
94 ([("WindowPtr", "*", "OutMode")],
95 [("ExistingWindowPtr", "*", "*")]),
96 ([("WindowRef", "*", "OutMode")], # Same, but other style headerfiles
97 [("ExistingWindowPtr", "*", "*")]),
99 ([("WindowPtr", "FrontWindow", "ReturnMode")],
100 [("ExistingWindowPtr", "*", "*")]),
101 ([("WindowRef", "FrontWindow", "ReturnMode")], # Ditto
102 [("ExistingWindowPtr", "*", "*")]),
105 if __name__
== "__main__":