Home | History | Annotate | Download | only in osa
      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 
      6 import string
      7 
      8 # Declarations that change for each manager
      9 MACHEADERFILE = 'OSA.h'         # The Apple header file
     10 MODNAME = '_OSA'                                # The name of the module
     11 
     12 # The following is *usually* unchanged but may still require tuning
     13 MODPREFIX = 'OSA'                       # The prefix for module-wide routines
     14 OBJECTPREFIX = 'OSAObj' # The prefix for object methods
     15 INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner
     16 OUTPUTFILE = MODNAME + "module.c"       # The file generated by this program
     17 
     18 from macsupport import *
     19 
     20 # Create the type objects
     21 
     22 includestuff = includestuff + """
     23 #if PY_VERSION_HEX < 0x02040000
     24 PyObject *PyMac_GetOSErrException(void);
     25 #endif
     26 #include <Carbon/Carbon.h>
     27 
     28 #ifdef USE_TOOLBOX_OBJECT_GLUE
     29 extern PyObject *_OSAObj_New(ComponentInstance);
     30 extern int _OSAObj_Convert(PyObject *, ComponentInstance *);
     31 
     32 #define OSAObj_New _OSAObj_New
     33 #define OSAObj_Convert _OSAObj_Convert
     34 #endif
     35 """
     36 
     37 initstuff = initstuff + """
     38 /*
     39         PyMac_INIT_TOOLBOX_OBJECT_NEW(ComponentInstance, OSAObj_New);
     40         PyMac_INIT_TOOLBOX_OBJECT_CONVERT(ComponentInstance, OSAObj_Convert);
     41 */
     42 """
     43 
     44 ComponentInstance = OpaqueByValueType('ComponentInstance', OBJECTPREFIX)
     45 OSAError = OSErrType("OSAError", "l")
     46 # OSALocalOrGlobal = Type("OSALocalOrGlobal", "l")
     47 OSAID = Type("OSAID", "l")
     48 OSADebugCallFrameRef = Type("OSADebugCallFrameRef", "l")
     49 OSADebugSessionRef = Type("OSADebugSessionRef", "l")
     50 OSADebugStepKind = Type("OSADebugStepKind", "l")
     51 DescType = OSTypeType("DescType")
     52 AEDesc = OpaqueType('AEDesc')
     53 AEDesc_ptr = OpaqueType('AEDesc')
     54 AEAddressDesc = OpaqueType('AEAddressDesc', 'AEDesc')
     55 AEAddressDesc_ptr = OpaqueType('AEAddressDesc', 'AEDesc')
     56 AEDescList = OpaqueType('AEDescList', 'AEDesc')
     57 AEDescList_ptr = OpaqueType('AEDescList', 'AEDesc')
     58 AERecord = OpaqueType('AERecord', 'AEDesc')
     59 AERecord_ptr = OpaqueType('AERecord', 'AEDesc')
     60 AppleEvent = OpaqueType('AppleEvent', 'AEDesc')
     61 AppleEvent_ptr = OpaqueType('AppleEvent', 'AEDesc')
     62 
     63 # NOTE: at the moment OSA.ComponentInstance is not a subclass
     64 # of Cm.ComponentInstance. If this is a problem it can be fixed.
     65 class MyObjectDefinition(PEP253Mixin, GlobalObjectDefinition):
     66     def outputCheckNewArg(self):
     67         Output("""if (itself == NULL) {
     68                                 PyErr_SetString(OSA_Error,"NULL ComponentInstance");
     69                                 return NULL;
     70                         }""")
     71 
     72     def outputCheckConvertArg(self):
     73         Output("""
     74                 if (CmpInstObj_Convert(v, p_itself))
     75                         return 1;
     76                 PyErr_Clear();
     77                 """)
     78 
     79 
     80 # Create the generator groups and link them
     81 module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
     82 object = MyObjectDefinition('OSAComponentInstance', OBJECTPREFIX,
     83                 'ComponentInstance')
     84 module.addobject(object)
     85 
     86 # Create the generator classes used to populate the lists
     87 Function = OSErrWeakLinkFunctionGenerator
     88 Method = OSErrWeakLinkMethodGenerator
     89 
     90 # Test which types we are still missing.
     91 execfile(string.lower(MODPREFIX) + 'typetest.py')
     92 
     93 # Create and populate the lists
     94 functions = []
     95 methods = []
     96 execfile(INPUTFILE)
     97 
     98 # add the populated lists to the generator groups
     99 # (in a different wordl the scan program would generate this)
    100 for f in functions: module.add(f)
    101 for f in methods: object.add(f)
    102 
    103 # generate output (open the output file as late as possible)
    104 SetOutputFileName(OUTPUTFILE)
    105 module.generate()
    106