This commit was manufactured by cvs2svn to create tag 'r221'.
[python/dscho.git] / Mac / Modules / app / appsupport.py
blob880a70db90bd04d83eac92b96175419239123f4c
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).
6 import string
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'
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
21 from macsupport import *
23 # Create the type objects
24 #MenuRef = OpaqueByValueType("MenuRef", "MenuObj")
27 #WindowPeek = OpaqueByValueType("WindowPeek", OBJECTPREFIX)
29 RgnHandle = FakeType("(RgnHandle)0")
30 NULL = FakeType("NULL")
32 # XXXX Should be next, but this will break a lot of code...
33 # RgnHandle = OpaqueByValueType("RgnHandle", "OptResObj")
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 CFStringRef = OpaqueByValueType("CFStringRef", "CFStringRefObj")
73 CFMutableStringRef = OpaqueByValueType("CFMutableStringRef", "CFMutableStringRefObj")
74 TruncCode = Type("TruncCode", "h")
77 ThemeButtonKind = UInt16
78 ThemeButtonDrawInfo_ptr = OpaqueType("ThemeButtonDrawInfo", "ThemeButtonDrawInfo")
79 ThemeEraseUPP = FakeType("NULL")
80 ThemeButtonDrawUPP = FakeType("NULL")
83 includestuff = includestuff + """
84 #ifdef WITHOUT_FRAMEWORKS
85 #include <Appearance.h>
86 #else
87 #include <Carbon/Carbon.h>
88 #endif
92 int ThemeButtonDrawInfo_Convert(PyObject *v, ThemeButtonDrawInfo *p_itself)
94 return PyArg_Parse(v, "(iHH)", &p_itself->state, &p_itself->value, &p_itself->adornment);
97 """
99 class MyObjectDefinition(GlobalObjectDefinition):
100 pass
101 ## def outputCheckNewArg(self):
102 ## Output("if (itself == NULL) return PyMac_Error(resNotFound);")
103 ## def outputCheckConvertArg(self):
104 ## OutLbrace("if (DlgObj_Check(v))")
105 ## Output("*p_itself = ((WindowObject *)v)->ob_itself;")
106 ## Output("return 1;")
107 ## OutRbrace()
108 ## Out("""
109 ## if (v == Py_None) { *p_itself = NULL; return 1; }
110 ## if (PyInt_Check(v)) { *p_itself = (WindowPtr)PyInt_AsLong(v); return 1; }
111 ## """)
113 # From here on it's basically all boiler plate...
115 # Create the generator groups and link them
116 module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
117 object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE)
118 module.addobject(object)
120 ThemeDrawingState = OpaqueByValueType("ThemeDrawingState", "ThemeDrawingStateObj")
121 Method = WeakLinkMethodGenerator
124 # Create the generator classes used to populate the lists
125 Function = OSErrWeakLinkFunctionGenerator
126 ##Method = OSErrWeakLinkMethodGenerator
128 # Create and populate the lists
129 functions = []
130 methods = []
131 execfile(INPUTFILE)
133 # add the populated lists to the generator groups
134 # (in a different wordl the scan program would generate this)
135 for f in functions: module.add(f)
136 for f in methods: object.add(f)
138 # generate output (open the output file as late as possible)
139 SetOutputFileName(OUTPUTFILE)
140 module.generate()