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