/Mac/Modules/dlg/dlgscan.py

http://unladen-swallow.googlecode.com/ · Python · 115 lines · 89 code · 19 blank · 7 comment · 4 complexity · 6c4155df95376f7fd286e32be92bde2f MD5 · raw file

  1. # Scan an Apple header file, generating a Python file of generator calls.
  2. import sys
  3. from bgenlocations import TOOLBOXDIR, BGENDIR
  4. sys.path.append(BGENDIR)
  5. from scantools import Scanner
  6. LONG = "Dialogs"
  7. SHORT = "dlg"
  8. OBJECT = "DialogPtr"
  9. def main():
  10. input = LONG + ".h"
  11. output = SHORT + "gen.py"
  12. defsoutput = TOOLBOXDIR + LONG + ".py"
  13. scanner = MyScanner(input, output, defsoutput)
  14. scanner.scan()
  15. scanner.close()
  16. print "=== Testing definitions output code ==="
  17. execfile(defsoutput, {}, {})
  18. print "=== Done scanning and generating, now importing the generated code... ==="
  19. exec "import " + SHORT + "support"
  20. print "=== Done. It's up to you to compile it now! ==="
  21. class MyScanner(Scanner):
  22. def destination(self, type, name, arglist):
  23. classname = "Function"
  24. listname = "functions"
  25. if arglist:
  26. t, n, m = arglist[0]
  27. if t in ("DialogPtr", "DialogRef") and m == "InMode":
  28. classname = "Method"
  29. listname = "methods"
  30. return classname, listname
  31. def makeblacklistnames(self):
  32. return [
  33. 'InitDialogs',
  34. 'ErrorSound',
  35. # Dialogs are disposed when the object is deleted
  36. 'CloseDialog',
  37. 'DisposDialog',
  38. 'DisposeDialog',
  39. 'UpdtDialog',
  40. 'CouldAlert',
  41. 'FreeAlert',
  42. 'CouldDialog',
  43. 'FreeDialog',
  44. 'GetStdFilterProc',
  45. 'GetDialogParent',
  46. ## # Can't find these in the CW Pro 3 libraries
  47. 'SetDialogMovableModal',
  48. 'GetDialogControlNotificationProc',
  49. 'SetGrafPortOfDialog', # Funny, and probably not useful
  50. # Can't find these:
  51. 'CloseStandardSheet',
  52. 'RunStandardAlert',
  53. ]
  54. def makeblacklisttypes(self):
  55. return [
  56. "AlertStdAlertParamPtr", # Too much work, for now
  57. "AlertStdAlertParamRec", # ditto
  58. "AlertStdAlertParamRec_ptr", # ditto
  59. "AlertStdCFStringAlertParamPtr", # ditto
  60. "AlertStdCFStringAlertParamRec",
  61. "AlertStdCFStringAlertParamRec_ptr",
  62. "QTModelessCallbackProcPtr",
  63. ]
  64. def makerepairinstructions(self):
  65. return [
  66. ([("Str255", "*", "InMode")],
  67. [("*", "*", "OutMode")]),
  68. ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")],
  69. [("InBuffer", "*", "*")]),
  70. ([("void", "*", "OutMode"), ("long", "*", "InMode"),
  71. ("long", "*", "OutMode")],
  72. [("VarVarOutBuffer", "*", "InOutMode")]),
  73. # GetDialogItem return handle is optional
  74. ([("Handle", "item", "OutMode")],
  75. [("OptHandle", "item", "OutMode")]),
  76. # NewDialog ETC.
  77. ([("void", "*", "OutMode")],
  78. [("NullStorage", "*", "InMode")]),
  79. ([("DialogPtr", "*", "OutMode")],
  80. [("ExistingDialogPtr", "*", "*")]),
  81. ([("DialogRef", "*", "OutMode")],
  82. [("ExistingDialogPtr", "*", "*")]),
  83. ([("WindowPtr", "*", "OutMode")],
  84. [("ExistingWindowPtr", "*", "*")]),
  85. ([("WindowPtr", "*", "ReturnMode")],
  86. [("ExistingWindowPtr", "*", "*")]),
  87. # StdFilterProc
  88. ([('EventRecord', 'event', 'OutMode'),
  89. ('DialogItemIndex', 'itemHit', 'OutMode')],
  90. [('EventRecord', 'event', 'InOutMode'),
  91. ('DialogItemIndex', 'itemHit', 'InOutMode')])
  92. ]
  93. def writeinitialdefs(self):
  94. self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
  95. if __name__ == "__main__":
  96. main()