blob: 8a2f726da1bd2cb64e7f9d2d4de700a2d8a25f54 [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
Jack Jansenaaebdd62002-08-05 15:39:30 +00003from bgenlocations import TOOLBOXDIR, BGENDIR
Jack Jansen0c4d9471998-04-17 14:07:56 +00004sys.path.append(BGENDIR)
Guido van Rossum17448e21995-01-30 11:53:55 +00005
6from scantools import Scanner
7
8def main():
Tim Peters182b5ac2004-07-18 06:16:08 +00009 input = "MacWindows.h"
10 output = "wingen.py"
11 defsoutput = TOOLBOXDIR + "Windows.py"
12 scanner = MyScanner(input, output, defsoutput)
13 scanner.scan()
14 scanner.close()
15 print "=== Testing definitions output code ==="
16 execfile(defsoutput, {}, {})
17 print "=== Done scanning and generating, now importing the generated code... ==="
18 import winsupport
19 print "=== Done. It's up to you to compile it now! ==="
Guido van Rossum17448e21995-01-30 11:53:55 +000020
21class MyScanner(Scanner):
22
Tim Peters182b5ac2004-07-18 06:16:08 +000023 def destination(self, type, name, arglist):
24 classname = "Function"
25 listname = "functions"
26 if arglist:
27 t, n, m = arglist[0]
28 if t in ("WindowPtr", "WindowPeek", "WindowRef") and m == "InMode":
29 classname = "Method"
30 listname = "methods"
31 return classname, listname
Guido van Rossum17448e21995-01-30 11:53:55 +000032
Tim Peters182b5ac2004-07-18 06:16:08 +000033 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")
Jack Jansen21f96871998-02-20 16:02:09 +000038
Tim Peters182b5ac2004-07-18 06:16:08 +000039 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',
52 'kWindowNoConstrainAttribute',
53 # OS8 only:
54 'GetAuxWin',
55 'GetWindowDataHandle',
56 'SaveOld',
57 'DrawNew',
58 'SetWinColor',
59 'SetDeskCPat',
60 'InitWindows',
61 'InitFloatingWindows',
62 'GetWMgrPort',
63 'GetCWMgrPort',
64 'ValidRgn', # Use versions with Window in their name
65 'ValidRect',
66 'InvalRgn',
67 'InvalRect',
68 'IsValidWindowPtr', # I think this is useless for Python, but not sure...
69 'GetWindowZoomFlag', # Not available in Carbon
70 'GetWindowTitleWidth', # Ditto
71 'GetWindowGoAwayFlag',
72 'GetWindowSpareFlag',
73 ]
Guido van Rossum17448e21995-01-30 11:53:55 +000074
Tim Peters182b5ac2004-07-18 06:16:08 +000075 def makeblacklisttypes(self):
76 return [
77 'ProcPtr',
78 'DragGrayRgnUPP',
79 'WindowPaintUPP',
80 'Collection', # For now, to be done later
81 'WindowDefSpec', # Too difficult for now
82 'WindowDefSpec_ptr',
83 'EventRef', #TBD
84 ]
85
86 def makerepairinstructions(self):
87 return [
88
89 # GetWTitle
90 ([("Str255", "*", "InMode")],
91 [("*", "*", "OutMode")]),
92
93 ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")],
94 [("InBuffer", "*", "*")]),
95
96 ([("void", "*", "OutMode"), ("long", "*", "InMode"),
97 ("long", "*", "OutMode")],
98 [("VarVarOutBuffer", "*", "InOutMode")]),
99
100 ([("void", "wStorage", "OutMode")],
101 [("NullStorage", "*", "InMode")]),
102
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", "*", "*")]),
109
110 ([("WindowPtr", "*", "OutMode")],
111 [("ExistingWindowPtr", "*", "*")]),
112 ([("WindowRef", "*", "OutMode")], # Same, but other style headerfiles
113 [("ExistingWindowPtr", "*", "*")]),
114
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", "*", "*")]),
123
124 ([("Rect_ptr", "*", "ReturnMode")], # GetWindowXXXState accessors
125 [("void", "*", "ReturnMode")]),
126 ]
Guido van Rossum17448e21995-01-30 11:53:55 +0000127
128if __name__ == "__main__":
Tim Peters182b5ac2004-07-18 06:16:08 +0000129 main()