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