• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 = 'Icons.h'               # The Apple header file
10MODNAME = '_Icn'                                # The name of the module
11OBJECTNAME = 'Icon'                     # The basic name of the objects used here
12KIND = 'Handle'                         # Usually 'Ptr' or 'Handle'
13
14# The following is *usually* unchanged but may still require tuning
15MODPREFIX = 'Icn'                       # The prefix for module-wide routines
16OBJECTTYPE = OBJECTNAME + KIND          # The C type used to represent them
17OBJECTPREFIX = MODPREFIX + '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
24CIconHandle = OpaqueByValueType("CIconHandle", "ResObj")
25IconSuiteRef = OpaqueByValueType("IconSuiteRef", "ResObj")
26IconCacheRef = OpaqueByValueType("IconCacheRef", "ResObj")
27IconRef = OpaqueByValueType("IconRef", "ResObj")
28IconFamilyHandle = OpaqueByValueType("IconFamilyHandle", "ResObj")
29RgnHandle = OpaqueByValueType("RgnHandle", "ResObj")
30IconAlignmentType = Type("IconAlignmentType", "h")
31IconTransformType = Type("IconTransformType", "h")
32IconSelectorValue = Type("IconSelectorValue", "l")
33IconServicesUsageFlags = Type("IconServicesUsageFlags", "l")
34RGBColor = OpaqueType("RGBColor", "QdRGB")
35CGContextRef = OpaqueByValueType("CGContextRef", "CGContextRefObj")
36
37#WindowPeek = OpaqueByValueType("WindowPeek", OBJECTPREFIX)
38
39# RgnHandle = FakeType("(RgnHandle)0")
40# XXXX Should be next, but this will break a lot of code...
41# RgnHandle = OpaqueByValueType("RgnHandle", "OptResObj")
42
43# KeyMap = ArrayOutputBufferType("KeyMap")
44#MacOSEventKind = Type("MacOSEventKind", "h") # Old-style
45#MacOSEventMask = Type("MacOSEventMask", "h") # Old-style
46#EventMask = Type("EventMask", "H")
47#EventKind = Type("EventKind", "H")
48
49includestuff = includestuff + """
50#include <Carbon/Carbon.h>
51
52"""
53
54class MyObjectDefinition(PEP253Mixin, GlobalObjectDefinition):
55    def outputCheckNewArg(self):
56        Output("if (itself == NULL) return PyMac_Error(resNotFound);")
57    def outputCheckConvertArg(self):
58        OutLbrace("if (DlgObj_Check(v))")
59        Output("*p_itself = ((WindowObject *)v)->ob_itself;")
60        Output("return 1;")
61        OutRbrace()
62        Out("""
63        if (v == Py_None) { *p_itself = NULL; return 1; }
64        if (PyInt_Check(v)) { *p_itself = (WindowPtr)PyInt_AsLong(v); return 1; }
65        """)
66
67# From here on it's basically all boiler plate...
68
69# Create the generator groups and link them
70module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
71##object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE)
72##module.addobject(object)
73
74# Create the generator classes used to populate the lists
75Function = OSErrWeakLinkFunctionGenerator
76##Method = OSErrMethodGenerator
77
78# Create and populate the lists
79functions = []
80##methods = []
81execfile(INPUTFILE)
82
83# add the populated lists to the generator groups
84# (in a different wordl the scan program would generate this)
85for f in functions: module.add(f)
86##for f in methods: object.add(f)
87
88# generate output (open the output file as late as possible)
89SetOutputFileName(OUTPUTFILE)
90module.generate()
91