symbian-qemu-0.9.1-12/python-2.6.1/Mac/Modules/evt/evtsupport.py
changeset 1 2fb8b9db1c86
equal deleted inserted replaced
0:ffa851df0825 1:2fb8b9db1c86
       
     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 = 'Events.h'              # The Apple header file
       
    10 MODNAME = '_Evt'                                # The name of the module
       
    11 OBJECTNAME = 'Event'                    # The basic name of the objects used here
       
    12 KIND = 'Record'                         # Usually 'Ptr' or 'Handle'
       
    13 
       
    14 # The following is *usually* unchanged but may still require tuning
       
    15 MODPREFIX = 'Evt'                       # 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
       
    20 
       
    21 from macsupport import *
       
    22 
       
    23 # Create the type objects
       
    24 
       
    25 #WindowPeek = OpaqueByValueType("WindowPeek", OBJECTPREFIX)
       
    26 
       
    27 RgnHandle = FakeType("(RgnHandle)0")
       
    28 # XXXX Should be next, but this will break a lot of code...
       
    29 # RgnHandle = OpaqueByValueType("RgnHandle", "OptResObj")
       
    30 
       
    31 KeyMap = ArrayOutputBufferType("KeyMap")
       
    32 ##MacOSEventKind = Type("MacOSEventKind", "h") # Old-style
       
    33 ##MacOSEventMask = Type("MacOSEventMask", "h") # Old-style
       
    34 EventMask = Type("EventMask", "H")
       
    35 EventKind = Type("EventKind", "H")
       
    36 
       
    37 includestuff = includestuff + """
       
    38 #include <Carbon/Carbon.h>
       
    39 
       
    40 """
       
    41 
       
    42 # From here on it's basically all boiler plate...
       
    43 
       
    44 # Create the generator groups and link them
       
    45 module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
       
    46 
       
    47 # Create the generator classes used to populate the lists
       
    48 Function = OSErrWeakLinkFunctionGenerator
       
    49 ##Method = OSErrWeakLinkMethodGenerator
       
    50 
       
    51 # Create and populate the lists
       
    52 functions = []
       
    53 execfile(INPUTFILE)
       
    54 
       
    55 # Move TickCount here, for convenience
       
    56 f = Function(UInt32, 'TickCount',
       
    57 )
       
    58 functions.append(f)
       
    59 
       
    60 # add the populated lists to the generator groups
       
    61 # (in a different wordl the scan program would generate this)
       
    62 for f in functions: module.add(f)
       
    63 
       
    64 WaitNextEvent_body = """
       
    65 Boolean _rv;
       
    66 EventMask eventMask;
       
    67 EventRecord theEvent;
       
    68 UInt32 sleep;
       
    69 Handle mouseregion = (Handle)0;
       
    70 
       
    71 if (!PyArg_ParseTuple(_args, "Hl|O&",
       
    72                       &eventMask,
       
    73                       &sleep,
       
    74                       OptResObj_Convert, &mouseregion))
       
    75         return NULL;
       
    76 _rv = WaitNextEvent(eventMask,
       
    77                     &theEvent,
       
    78                     sleep,
       
    79                     (RgnHandle)mouseregion);
       
    80 _res = Py_BuildValue("bO&",
       
    81                      _rv,
       
    82                      PyMac_BuildEventRecord, &theEvent);
       
    83 return _res;
       
    84 """
       
    85 f = ManualGenerator("WaitNextEvent", WaitNextEvent_body);
       
    86 f.docstring = lambda: "(EventMask eventMask, UInt32 sleep [,RegionHandle]) -> (Boolean _rv, EventRecord theEvent)"
       
    87 module.add(f)
       
    88 
       
    89 
       
    90 # generate output (open the output file as late as possible)
       
    91 SetOutputFileName(OUTPUTFILE)
       
    92 module.generate()