blob: f78935d0d513d9f264b9b65b967a9f03db79512a [file] [log] [blame]
Guido van Rossum17448e21995-01-30 11:53:55 +00001# Scan an Apple header file, generating a Python file of generator calls.
Jack Jansen0c4d9471998-04-17 14:07:56 +00002import sys
3import os
Jack Jansenaaebdd62002-08-05 15:39:30 +00004from bgenlocations import TOOLBOXDIR, BGENDIR
Jack Jansen0c4d9471998-04-17 14:07:56 +00005sys.path.append(BGENDIR)
Guido van Rossum17448e21995-01-30 11:53:55 +00006
7from scantools import Scanner
8
9def main():
Tim Peters182b5ac2004-07-18 06:16:08 +000010 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! ==="
Guido van Rossum17448e21995-01-30 11:53:55 +000021
22class MyScanner(Scanner):
23
Tim Peters182b5ac2004-07-18 06:16:08 +000024 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
Guido van Rossum17448e21995-01-30 11:53:55 +000033
Tim Peters182b5ac2004-07-18 06:16:08 +000034 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")
38 self.defsfile.write("kWindowNoConstrainAttribute = 0x80000000\n")
Jack Jansen21f96871998-02-20 16:02:09 +000039
Tim Peters182b5ac2004-07-18 06:16:08 +000040 def makeblacklistnames(self):
41 return [
42 'DisposeWindow', # Implied when the object is deleted
43 'CloseWindow',
44 'SetWindowProperty', # For the moment
45 'GetWindowProperty',
46 'GetWindowPropertySize',
47 'RemoveWindowProperty',
48 'MacCloseWindow',
49 'GetWindowList', # Don't know whether this is safe...
50 # Constants with funny definitions
51 'kMouseUpOutOfSlop',
52 'kAllWindowClasses',
53 'kWindowNoConstrainAttribute',
54 # OS8 only:
55 'GetAuxWin',
56 'GetWindowDataHandle',
57 'SaveOld',
58 'DrawNew',
59 'SetWinColor',
60 'SetDeskCPat',
61 'InitWindows',
62 'InitFloatingWindows',
63 'GetWMgrPort',
64 'GetCWMgrPort',
65 'ValidRgn', # Use versions with Window in their name
66 'ValidRect',
67 'InvalRgn',
68 'InvalRect',
69 'IsValidWindowPtr', # I think this is useless for Python, but not sure...
70 'GetWindowZoomFlag', # Not available in Carbon
71 'GetWindowTitleWidth', # Ditto
72 'GetWindowGoAwayFlag',
73 'GetWindowSpareFlag',
74 ]
Guido van Rossum17448e21995-01-30 11:53:55 +000075
Tim Peters182b5ac2004-07-18 06:16:08 +000076 def makeblacklisttypes(self):
77 return [
78 'ProcPtr',
79 'DragGrayRgnUPP',
80 'WindowPaintUPP',
81 'Collection', # For now, to be done later
82 'WindowDefSpec', # Too difficult for now
83 'WindowDefSpec_ptr',
84 'EventRef', #TBD
85 ]
86
87 def makerepairinstructions(self):
88 return [
89
90 # GetWTitle
91 ([("Str255", "*", "InMode")],
92 [("*", "*", "OutMode")]),
93
94 ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")],
95 [("InBuffer", "*", "*")]),
96
97 ([("void", "*", "OutMode"), ("long", "*", "InMode"),
98 ("long", "*", "OutMode")],
99 [("VarVarOutBuffer", "*", "InOutMode")]),
100
101 ([("void", "wStorage", "OutMode")],
102 [("NullStorage", "*", "InMode")]),
103
104 # match FindWindowOfClass
105 ([("WindowRef", "outWindow", "OutMode"), ("WindowPartCode", "outWindowPart", "OutMode")],
106 [("ExistingWindowPtr", "*", "OutMode"), ("WindowPartCode", "outWindowPart", "OutMode")]),
107 # then match CreateNewWindow and CreateWindowFromResource
108 ([("WindowRef", "outWindow", "OutMode")],
109 [("WindowRef", "*", "*")]),
110
111 ([("WindowPtr", "*", "OutMode")],
112 [("ExistingWindowPtr", "*", "*")]),
113 ([("WindowRef", "*", "OutMode")], # Same, but other style headerfiles
114 [("ExistingWindowPtr", "*", "*")]),
115
116 ([("WindowPtr", "FrontWindow", "ReturnMode")],
117 [("ExistingWindowPtr", "*", "*")]),
118 ([("WindowRef", "FrontWindow", "ReturnMode")], # Ditto
119 [("ExistingWindowPtr", "*", "*")]),
120 ([("WindowPtr", "FrontNonFloatingWindow", "ReturnMode")],
121 [("ExistingWindowPtr", "*", "*")]),
122 ([("WindowRef", "FrontNonFloatingWindow", "ReturnMode")], # Ditto
123 [("ExistingWindowPtr", "*", "*")]),
124
125 ([("Rect_ptr", "*", "ReturnMode")], # GetWindowXXXState accessors
126 [("void", "*", "ReturnMode")]),
127 ]
Guido van Rossum17448e21995-01-30 11:53:55 +0000128
129if __name__ == "__main__":
Tim Peters182b5ac2004-07-18 06:16:08 +0000130 main()