This is (hopefully) last checkin before releasing 2.1c2 -- get rid of
[python/dscho.git] / Mac / Modules / app / appsupport.py
blobbd314dde5f40806b735d748cc3e1d6f0a133e08e
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 = 'UNUSED' # The basic name of the objects used here
12 KIND = 'Record' # Usually 'Ptr' or 'Handle'
14 # The following is *usually* unchanged but may still require tuning
15 MODPREFIX = MODNAME # The prefix for module-wide routines
16 OBJECTTYPE = OBJECTNAME + KIND # The C type used to represent them
17 OBJECTPREFIX = MODPREFIX + '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 # XXXX Should be next, but this will break a lot of code...
31 # RgnHandle = OpaqueByValueType("RgnHandle", "OptResObj")
33 #KeyMap = ArrayOutputBufferType("KeyMap")
34 #MacOSEventKind = Type("MacOSEventKind", "h") # Old-style
35 #MacOSEventMask = Type("MacOSEventMask", "h") # Old-style
36 #EventMask = Type("EventMask", "h")
37 #EventKind = Type("EventKind", "h")
38 ThemeBrush = Type("ThemeBrush", "h")
39 ThemeColor = Type("ThemeColor", "h")
40 ThemeTextColor = Type("ThemeTextColor", "h")
41 ThemeMenuBarState = Type("ThemeMenuBarState", "H")
42 ThemeMenuState = Type("ThemeMenuState", "H")
43 ThemeMenuType = Type("ThemeMenuType", "H")
44 ThemeMenuItemType = Type("ThemeMenuItemType", "H")
45 ThemeFontID = Type("ThemeFontID", "H")
46 ThemeTabStyle = Type("ThemeTabStyle", "H")
47 ThemeTabDirection = Type("ThemeTabDirection", "H")
48 ThemeDrawState = Type("ThemeDrawState", "l")
49 ThemeCursor = Type("ThemeCursor", "l")
50 ThemeCheckBoxStyle = Type("ThemeCheckBoxStyle", "H")
51 ThemeScrollBarArrowStyle = Type("ThemeScrollBarArrowStyle", "H")
52 ThemeScrollBarThumbStyle = Type("ThemeScrollBarThumbStyle", "H")
53 CTabHandle = OpaqueByValueType("CTabHandle", "ResObj")
54 ThemeTrackEnableState = Type("ThemeTrackEnableState", "b")
55 ThemeTrackPressState = Type("ThemeTrackPressState", "b")
56 ThemeThumbDirection = Type("ThemeThumbDirection", "b")
57 ThemeTrackAttributes = Type("ThemeTrackAttributes", "H")
58 ControlPartCode = Type("ControlPartCode", "h")
59 ThemeWindowAttributes = Type("ThemeWindowAttributes", "l")
60 ThemeWindowType = Type("ThemeWindowType", "H")
61 ThemeTitleBarWidget = Type("ThemeTitleBarWidget", "H")
62 ThemeArrowOrientation = Type("ThemeArrowOrientation", "H")
63 ThemePopupArrowSize = Type("ThemePopupArrowSize", "H")
64 ThemeGrowDirection = Type("ThemeGrowDirection", "H")
65 ThemeSoundKind = OSTypeType("ThemeSoundKind")
66 ThemeDragSoundKind = OSTypeType("ThemeDragSoundKind")
67 ThemeBackgroundKind = Type("ThemeBackgroundKind", "l")
68 ThemeMetric = Type("ThemeMetric", "l")
69 RGBColor = OpaqueType("RGBColor", "QdRGB")
71 includestuff = includestuff + """
72 #include <%s>""" % MACHEADERFILE + """
73 """
75 ## class MyObjectDefinition(GlobalObjectDefinition):
76 ## def outputCheckNewArg(self):
77 ## Output("if (itself == NULL) return PyMac_Error(resNotFound);")
78 ## def outputCheckConvertArg(self):
79 ## OutLbrace("if (DlgObj_Check(v))")
80 ## Output("*p_itself = ((WindowObject *)v)->ob_itself;")
81 ## Output("return 1;")
82 ## OutRbrace()
83 ## Out("""
84 ## if (v == Py_None) { *p_itself = NULL; return 1; }
85 ## if (PyInt_Check(v)) { *p_itself = (WindowPtr)PyInt_AsLong(v); return 1; }
86 ## """)
88 # From here on it's basically all boiler plate...
90 # Create the generator groups and link them
91 module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
92 ##object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE)
93 ##module.addobject(object)
95 # Create the generator classes used to populate the lists
96 Function = OSErrFunctionGenerator
97 ##Method = OSErrMethodGenerator
99 # Create and populate the lists
100 functions = []
101 ##methods = []
102 execfile(INPUTFILE)
104 # add the populated lists to the generator groups
105 # (in a different wordl the scan program would generate this)
106 for f in functions: module.add(f)
107 ##for f in methods: object.add(f)
109 # generate output (open the output file as late as possible)
110 SetOutputFileName(OUTPUTFILE)
111 module.generate()