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 6import string 7 8# Declarations that change for each manager 9MACHEADERFILE = 'Appearance.h' # The Apple header file 10MODNAME = '_App' # The name of the module 11OBJECTNAME = 'ThemeDrawingState' # The basic name of the objects used here 12KIND = '' # Usually 'Ptr' or 'Handle' 13 14# The following is *usually* unchanged but may still require tuning 15MODPREFIX = 'App' # The prefix for module-wide routines 16OBJECTTYPE = OBJECTNAME + KIND # The C type used to represent them 17OBJECTPREFIX = OBJECTNAME + 'Obj' # The prefix for object methods 18INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner 19OUTPUTFILE = MODNAME + "module.c" # The file generated by this program 20 21from macsupport import * 22 23# Create the type objects 24#MenuRef = OpaqueByValueType("MenuRef", "MenuObj") 25 26 27#WindowPeek = OpaqueByValueType("WindowPeek", OBJECTPREFIX) 28 29RgnHandle = FakeType("(RgnHandle)0") 30NULL = 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") 40ThemeBrush = Type("ThemeBrush", "h") 41ThemeColor = Type("ThemeColor", "h") 42ThemeTextColor = Type("ThemeTextColor", "h") 43ThemeMenuBarState = Type("ThemeMenuBarState", "H") 44ThemeMenuState = Type("ThemeMenuState", "H") 45ThemeMenuType = Type("ThemeMenuType", "H") 46ThemeMenuItemType = Type("ThemeMenuItemType", "H") 47ThemeFontID = Type("ThemeFontID", "H") 48ThemeTabStyle = Type("ThemeTabStyle", "H") 49ThemeTabDirection = Type("ThemeTabDirection", "H") 50ThemeDrawState = Type("ThemeDrawState", "l") 51ThemeCursor = Type("ThemeCursor", "l") 52ThemeCheckBoxStyle = Type("ThemeCheckBoxStyle", "H") 53ThemeScrollBarArrowStyle = Type("ThemeScrollBarArrowStyle", "H") 54ThemeScrollBarThumbStyle = Type("ThemeScrollBarThumbStyle", "H") 55CTabHandle = OpaqueByValueType("CTabHandle", "ResObj") 56ThemeTrackEnableState = Type("ThemeTrackEnableState", "b") 57ThemeTrackPressState = Type("ThemeTrackPressState", "b") 58ThemeThumbDirection = Type("ThemeThumbDirection", "b") 59ThemeTrackAttributes = Type("ThemeTrackAttributes", "H") 60ControlPartCode = Type("ControlPartCode", "h") 61ThemeWindowAttributes = Type("ThemeWindowAttributes", "l") 62ThemeWindowType = Type("ThemeWindowType", "H") 63ThemeTitleBarWidget = Type("ThemeTitleBarWidget", "H") 64ThemeArrowOrientation = Type("ThemeArrowOrientation", "H") 65ThemePopupArrowSize = Type("ThemePopupArrowSize", "H") 66ThemeGrowDirection = Type("ThemeGrowDirection", "H") 67ThemeSoundKind = OSTypeType("ThemeSoundKind") 68ThemeDragSoundKind = OSTypeType("ThemeDragSoundKind") 69ThemeBackgroundKind = Type("ThemeBackgroundKind", "l") 70ThemeMetric = Type("ThemeMetric", "l") 71RGBColor = OpaqueType("RGBColor", "QdRGB") 72TruncCode = Type("TruncCode", "h") 73 74 75ThemeButtonKind = UInt16 76ThemeButtonDrawInfo_ptr = OpaqueType("ThemeButtonDrawInfo", "ThemeButtonDrawInfo") 77ThemeEraseUPP = FakeType("NULL") 78ThemeButtonDrawUPP = FakeType("NULL") 79 80 81includestuff = includestuff + """ 82#include <Carbon/Carbon.h> 83 84 85int 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 92class 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 109module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff) 110object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE) 111module.addobject(object) 112 113ThemeDrawingState = OpaqueByValueType("ThemeDrawingState", "ThemeDrawingStateObj") 114Method = WeakLinkMethodGenerator 115 116 117# Create the generator classes used to populate the lists 118Function = OSErrWeakLinkFunctionGenerator 119##Method = OSErrWeakLinkMethodGenerator 120 121# Create and populate the lists 122functions = [] 123methods = [] 124execfile(INPUTFILE) 125 126# add the populated lists to the generator groups 127# (in a different wordl the scan program would generate this) 128for f in functions: module.add(f) 129for f in methods: object.add(f) 130 131# generate output (open the output file as late as possible) 132SetOutputFileName(OUTPUTFILE) 133module.generate() 134