Home | History | Annotate | Download | only in drag
      1 # Scan <Drag.h>, generating draggen.py.
      2 import sys
      3 from bgenlocations import TOOLBOXDIR, BGENDIR, INCLUDEDIR
      4 sys.path.append(BGENDIR)
      5 
      6 from scantools import Scanner
      7 
      8 MISSING_DEFINES="""
      9 kDragHasLeftSenderWindow        = (1 << 0)
     10 kDragInsideSenderApplication = (1 << 1)
     11 kDragInsideSenderWindow         = (1 << 2)
     12 kDragRegionAndImage                     = (1 << 4)
     13 flavorSenderOnly                        = (1 << 0)
     14 flavorSenderTranslated          = (1 << 1)
     15 flavorNotSaved                          = (1 << 2)
     16 flavorSystemTranslated          = (1 << 8)
     17 """
     18 
     19 
     20 def main():
     21     input = INCLUDEDIR + "Drag.h"
     22     output = "draggen.py"
     23     defsoutput = TOOLBOXDIR + "Dragconst.py"
     24     scanner = MyScanner(input, output, defsoutput)
     25     scanner.scan()
     26     scanner.close()
     27     print "=== Testing definitions output code ==="
     28     execfile(defsoutput, {}, {})
     29     print "=== Done scanning and generating, now doing 'import dragsupport' ==="
     30     import dragsupport
     31     print "=== Done.  It's up to you to compile Dragmodule.c ==="
     32 
     33 class MyScanner(Scanner):
     34 
     35     def destination(self, type, name, arglist):
     36         classname = "Function"
     37         listname = "functions"
     38         if arglist:
     39             t, n, m = arglist[0]
     40             if t in ('DragReference', 'DragRef') and m == "InMode":
     41                 classname = "Method"
     42                 listname = "methods"
     43         return classname, listname
     44 
     45     def writeinitialdefs(self):
     46         self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
     47         self.defsfile.write("from Carbon.TextEdit import *\n")
     48         self.defsfile.write("from Carbon.QuickDraw import *\n")
     49         self.defsfile.write("fkDragActionAll = -1\n")
     50         self.defsfile.write("\n")
     51         # Defines unparseable in Drag.h
     52         self.defsfile.write(MISSING_DEFINES)
     53 
     54     def makeblacklistnames(self):
     55         return [
     56                 "kDragActionAll",
     57                 ]
     58 
     59     def makeblacklisttypes(self):
     60         return [
     61                 "DragTrackingHandlerUPP",
     62                 "DragReceiveHandlerUPP",
     63                 "DragSendDataUPP",
     64                 "DragInputUPP",
     65                 "DragDrawingUPP",
     66                 ]
     67 
     68     def makerepairinstructions(self):
     69         return [
     70                 ([("void_ptr", "*", "InMode"), ("Size", "*", "InMode")],
     71                  [("OptionalInBuffer", "*", "*")]),
     72 
     73                 ([("void", "*", "OutMode"), ("Size", "*", "OutMode")],
     74                  [("VarOutBuffer", "*", "InOutMode")]),
     75 
     76                 ]
     77 
     78 if __name__ == "__main__":
     79     main()
     80