|
1 # This script generates a Python interface for an Apple Macintosh Manager. |
|
2 # It uses the "bgen" package to generate C code. |
|
3 # The function specifications are generated by scanning the mamager's header file, |
|
4 # using the "scantools" package (customized for this particular manager). |
|
5 |
|
6 import string |
|
7 |
|
8 # Declarations that change for each manager |
|
9 MACHEADERFILE = 'Appearance.h' # The Apple header file |
|
10 MODNAME = '_App' # The name of the module |
|
11 OBJECTNAME = 'ThemeDrawingState' # The basic name of the objects used here |
|
12 KIND = '' # Usually 'Ptr' or 'Handle' |
|
13 |
|
14 # The following is *usually* unchanged but may still require tuning |
|
15 MODPREFIX = 'App' # The prefix for module-wide routines |
|
16 OBJECTTYPE = OBJECTNAME + KIND # The C type used to represent them |
|
17 OBJECTPREFIX = OBJECTNAME + 'Obj' # The prefix for object methods |
|
18 INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner |
|
19 OUTPUTFILE = MODNAME + "module.c" # The file generated by this program |
|
20 |
|
21 from macsupport import * |
|
22 |
|
23 # Create the type objects |
|
24 #MenuRef = OpaqueByValueType("MenuRef", "MenuObj") |
|
25 |
|
26 |
|
27 #WindowPeek = OpaqueByValueType("WindowPeek", OBJECTPREFIX) |
|
28 |
|
29 RgnHandle = FakeType("(RgnHandle)0") |
|
30 NULL = FakeType("NULL") |
|
31 |
|
32 # XXXX Should be next, but this will break a lot of code... |
|
33 # RgnHandle = OpaqueByValueType("RgnHandle", "OptResObj") |
|
34 |
|
35 #KeyMap = ArrayOutputBufferType("KeyMap") |
|
36 #MacOSEventKind = Type("MacOSEventKind", "h") # Old-style |
|
37 #MacOSEventMask = Type("MacOSEventMask", "h") # Old-style |
|
38 #EventMask = Type("EventMask", "h") |
|
39 #EventKind = Type("EventKind", "h") |
|
40 ThemeBrush = Type("ThemeBrush", "h") |
|
41 ThemeColor = Type("ThemeColor", "h") |
|
42 ThemeTextColor = Type("ThemeTextColor", "h") |
|
43 ThemeMenuBarState = Type("ThemeMenuBarState", "H") |
|
44 ThemeMenuState = Type("ThemeMenuState", "H") |
|
45 ThemeMenuType = Type("ThemeMenuType", "H") |
|
46 ThemeMenuItemType = Type("ThemeMenuItemType", "H") |
|
47 ThemeFontID = Type("ThemeFontID", "H") |
|
48 ThemeTabStyle = Type("ThemeTabStyle", "H") |
|
49 ThemeTabDirection = Type("ThemeTabDirection", "H") |
|
50 ThemeDrawState = Type("ThemeDrawState", "l") |
|
51 ThemeCursor = Type("ThemeCursor", "l") |
|
52 ThemeCheckBoxStyle = Type("ThemeCheckBoxStyle", "H") |
|
53 ThemeScrollBarArrowStyle = Type("ThemeScrollBarArrowStyle", "H") |
|
54 ThemeScrollBarThumbStyle = Type("ThemeScrollBarThumbStyle", "H") |
|
55 CTabHandle = OpaqueByValueType("CTabHandle", "ResObj") |
|
56 ThemeTrackEnableState = Type("ThemeTrackEnableState", "b") |
|
57 ThemeTrackPressState = Type("ThemeTrackPressState", "b") |
|
58 ThemeThumbDirection = Type("ThemeThumbDirection", "b") |
|
59 ThemeTrackAttributes = Type("ThemeTrackAttributes", "H") |
|
60 ControlPartCode = Type("ControlPartCode", "h") |
|
61 ThemeWindowAttributes = Type("ThemeWindowAttributes", "l") |
|
62 ThemeWindowType = Type("ThemeWindowType", "H") |
|
63 ThemeTitleBarWidget = Type("ThemeTitleBarWidget", "H") |
|
64 ThemeArrowOrientation = Type("ThemeArrowOrientation", "H") |
|
65 ThemePopupArrowSize = Type("ThemePopupArrowSize", "H") |
|
66 ThemeGrowDirection = Type("ThemeGrowDirection", "H") |
|
67 ThemeSoundKind = OSTypeType("ThemeSoundKind") |
|
68 ThemeDragSoundKind = OSTypeType("ThemeDragSoundKind") |
|
69 ThemeBackgroundKind = Type("ThemeBackgroundKind", "l") |
|
70 ThemeMetric = Type("ThemeMetric", "l") |
|
71 RGBColor = OpaqueType("RGBColor", "QdRGB") |
|
72 TruncCode = Type("TruncCode", "h") |
|
73 |
|
74 |
|
75 ThemeButtonKind = UInt16 |
|
76 ThemeButtonDrawInfo_ptr = OpaqueType("ThemeButtonDrawInfo", "ThemeButtonDrawInfo") |
|
77 ThemeEraseUPP = FakeType("NULL") |
|
78 ThemeButtonDrawUPP = FakeType("NULL") |
|
79 |
|
80 |
|
81 includestuff = includestuff + """ |
|
82 #include <Carbon/Carbon.h> |
|
83 |
|
84 |
|
85 int ThemeButtonDrawInfo_Convert(PyObject *v, ThemeButtonDrawInfo *p_itself) |
|
86 { |
|
87 return PyArg_Parse(v, "(iHH)", &p_itself->state, &p_itself->value, &p_itself->adornment); |
|
88 } |
|
89 |
|
90 """ |
|
91 |
|
92 class MyObjectDefinition(PEP253Mixin, GlobalObjectDefinition): |
|
93 pass |
|
94 ## def outputCheckNewArg(self): |
|
95 ## Output("if (itself == NULL) return PyMac_Error(resNotFound);") |
|
96 ## def outputCheckConvertArg(self): |
|
97 ## OutLbrace("if (DlgObj_Check(v))") |
|
98 ## Output("*p_itself = ((WindowObject *)v)->ob_itself;") |
|
99 ## Output("return 1;") |
|
100 ## OutRbrace() |
|
101 ## Out(""" |
|
102 ## if (v == Py_None) { *p_itself = NULL; return 1; } |
|
103 ## if (PyInt_Check(v)) { *p_itself = (WindowPtr)PyInt_AsLong(v); return 1; } |
|
104 ## """) |
|
105 |
|
106 # From here on it's basically all boiler plate... |
|
107 |
|
108 # Create the generator groups and link them |
|
109 module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff) |
|
110 object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE) |
|
111 module.addobject(object) |
|
112 |
|
113 ThemeDrawingState = OpaqueByValueType("ThemeDrawingState", "ThemeDrawingStateObj") |
|
114 Method = WeakLinkMethodGenerator |
|
115 |
|
116 |
|
117 # Create the generator classes used to populate the lists |
|
118 Function = OSErrWeakLinkFunctionGenerator |
|
119 ##Method = OSErrWeakLinkMethodGenerator |
|
120 |
|
121 # Create and populate the lists |
|
122 functions = [] |
|
123 methods = [] |
|
124 execfile(INPUTFILE) |
|
125 |
|
126 # add the populated lists to the generator groups |
|
127 # (in a different wordl the scan program would generate this) |
|
128 for f in functions: module.add(f) |
|
129 for f in methods: object.add(f) |
|
130 |
|
131 # generate output (open the output file as late as possible) |
|
132 SetOutputFileName(OUTPUTFILE) |
|
133 module.generate() |