1# IBCarbonscan.py 2 3import sys 4import MacOS 5import sys 6 7from bgenlocations import TOOLBOXDIR, BGENDIR 8sys.path.append(BGENDIR) 9 10from scantools import Scanner, Scanner_OSX 11 12def main(): 13 print "---Scanning CarbonEvents.h---" 14 input = ["CarbonEvents.h"] 15 output = "CarbonEventsgen.py" 16 defsoutput = TOOLBOXDIR + "CarbonEvents.py" 17 scanner = CarbonEvents_Scanner(input, output, defsoutput) 18 scanner.scan() 19 scanner.close() 20 print "=== Testing definitions output code ===" 21 execfile(defsoutput, {}, {}) 22 print "--done scanning, importing--" 23 import CarbonEvtsupport 24 print "done" 25 26RefObjectTypes = ["EventRef", 27 "EventQueueRef", 28 "EventLoopRef", 29 "EventLoopTimerRef", 30 "EventHandlerRef", 31 "EventHandlerCallRef", 32 "EventTargetRef", 33 "EventHotKeyRef", 34 ] 35 36class CarbonEvents_Scanner(Scanner_OSX): 37 def destination(self, type, name, arglist): 38 classname = "CarbonEventsFunction" 39 listname = "functions" 40 if arglist: 41 t, n, m = arglist[0] 42 if t in RefObjectTypes and m == "InMode": 43 if t == "EventHandlerRef": 44 classname = "EventHandlerRefMethod" 45 else: 46 classname = "CarbonEventsMethod" 47 listname = t + "methods" 48 #else: 49 # print "not method" 50 return classname, listname 51 52 def writeinitialdefs(self): 53 self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n") 54 self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n") 55 self.defsfile.write("false = 0\n") 56 self.defsfile.write("true = 1\n") 57 self.defsfile.write("keyAEEventClass = FOUR_CHAR_CODE('evcl')\n") 58 self.defsfile.write("keyAEEventID = FOUR_CHAR_CODE('evti')\n") 59 60 def makeblacklistnames(self): 61 return [ 62 "sHandler", 63 "MacCreateEvent", 64# "TrackMouseLocationWithOptions", 65# "TrackMouseLocation", 66# "TrackMouseRegion", 67 "RegisterToolboxObjectClass", 68 "UnregisterToolboxObjectClass", 69 "ProcessHICommand", 70 "GetCFRunLoopFromEventLoop", 71 72 "InvokeEventHandlerUPP", 73 "InvokeEventComparatorUPP", 74 "InvokeEventLoopTimerUPP", 75 "NewEventComparatorUPP", 76 "NewEventLoopTimerUPP", 77 "NewEventHandlerUPP", 78 "DisposeEventComparatorUPP", 79 "DisposeEventLoopTimerUPP", 80 "DisposeEventHandlerUPP", 81 82 # Wrote by hand 83 "InstallEventHandler", 84 "RemoveEventHandler", 85 86 # Write by hand? 87 "GetEventParameter", 88 "FlushSpecificEventsFromQueue", 89 "FindSpecificEventInQueue", 90 "InstallEventLoopTimer", 91 92 # Don't do these because they require a CFRelease 93 "CreateTypeStringWithOSType", 94 "CopyEvent", 95 ] 96 97# def makeblacklisttypes(self): 98# return ["EventComparatorUPP", 99# "EventLoopTimerUPP", 100# #"EventHandlerUPP", 101# "EventComparatorProcPtr", 102# "EventLoopTimerProcPtr", 103# "EventHandlerProcPtr", 104# ] 105 106 def makerepairinstructions(self): 107 return [ 108 ([("UInt32", 'inSize', "InMode"), ("void_ptr", 'inDataPtr', "InMode")], 109 [("MyInBuffer", 'inDataPtr', "InMode")]), 110 ([("Boolean", 'ioWasInRgn', "OutMode")], 111 [("Boolean", 'ioWasInRgn', "InOutMode")]), 112 ] 113 114if __name__ == "__main__": 115 main() 116