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
10 input = "MacWindows.h"
12 defsoutput
= TOOLBOXDIR
+ "Windows.py"
13 scanner
= MyScanner(input, output
, defsoutput
)
16 print "=== Testing definitions output code ==="
17 execfile(defsoutput
, {}, {})
18 print "=== Done scanning and generating, now importing the generated code... ==="
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"
29 if t
in ("WindowPtr", "WindowPeek", "WindowRef") and m
== "InMode":
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
):
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
54 def makegreylist(self
):
56 ('#if !TARGET_API_MAC_CARBON', [
58 'GetWindowDataHandle',
64 'InitFloatingWindows',
67 'ValidRgn', # Use versions with Window in their name
71 'IsValidWindowPtr', # I think this is useless for Python, but not sure...
72 'GetWindowZoomFlag', # Not available in Carbon
73 'GetWindowTitleWidth', # Ditto
74 'GetWindowGoAwayFlag',
77 ('#if !TARGET_API_MAC_OS8', [
78 'IsWindowUpdatePending',
80 'GetFrontWindowOfClass',
81 'ChangeWindowPropertyAttributes',
82 'GetWindowPropertyAttributes',
83 'GetNextWindowOfClass',
86 'ChangeWindowAttributes',
87 'ReshapeCustomWindow',
88 'EnableScreenUpdates',
89 'DisableScreenUpdates',
90 'GetAvailableWindowPositioningBounds',
91 'CreateStandardWindowMenu',
92 'GetSheetWindowParent',
95 'ConstrainWindowToScreen',
96 'GetWindowGreatestAreaDevice',
97 'CopyWindowTitleAsCFString',
98 'SetWindowTitleWithCFString',
99 'CopyWindowAlternateTitle',
100 'SetWindowAlternateTitle',
106 'GetWindowRetainCount',
108 ('#if TARGET_API_MAC_OSX', [
109 'TransitionWindowAndParent',
112 def makeblacklisttypes(self
):
117 'Collection', # For now, to be done later
118 'WindowDefSpec', # Too difficult for now
123 def makerepairinstructions(self
):
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__":