/Mac/Modules/ctl/ctlscan.py

http://unladen-swallow.googlecode.com/ · Python · 171 lines · 110 code · 19 blank · 42 comment · 4 complexity · e048d485baec9ae175cca9098dd402dd MD5 · raw file

  1. # Scan <Controls.h>, generating ctlgen.py.
  2. import sys
  3. from bgenlocations import TOOLBOXDIR, BGENDIR
  4. sys.path.append(BGENDIR)
  5. from scantools import Scanner
  6. def main():
  7. # input = "Controls.h" # Universal Headers < 3.3
  8. input = ["Controls.h", "ControlDefinitions.h"] # Universal Headers >= 3.3
  9. output = "ctlgen.py"
  10. defsoutput = TOOLBOXDIR + "Controls.py"
  11. scanner = MyScanner(input, output, defsoutput)
  12. scanner.scan()
  13. scanner.close()
  14. print "=== Testing definitions output code ==="
  15. execfile(defsoutput, {}, {})
  16. print "=== Done scanning and generating, now doing 'import ctlsupport' ==="
  17. import ctlsupport
  18. print "=== Done. It's up to you to compile Ctlmodule.c ==="
  19. class MyScanner(Scanner):
  20. def destination(self, type, name, arglist):
  21. classname = "Function"
  22. listname = "functions"
  23. if arglist:
  24. t, n, m = arglist[0]
  25. if t in ("ControlHandle", "ControlRef") and m == "InMode":
  26. classname = "Method"
  27. listname = "methods"
  28. return classname, listname
  29. def writeinitialdefs(self):
  30. self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
  31. self.defsfile.write("from Carbon.TextEdit import *\n")
  32. self.defsfile.write("from Carbon.QuickDraw import *\n")
  33. self.defsfile.write("from Carbon.Dragconst import *\n")
  34. self.defsfile.write("from Carbon.CarbonEvents import *\n")
  35. self.defsfile.write("from Carbon.Appearance import *\n")
  36. self.defsfile.write("kDataBrowserItemAnyState = -1\n")
  37. self.defsfile.write("kControlBevelButtonCenterPopupGlyphTag = -1\n")
  38. self.defsfile.write("kDataBrowserClientPropertyFlagsMask = 0xFF000000\n")
  39. self.defsfile.write("\n")
  40. def makeblacklistnames(self):
  41. return [
  42. 'FindControlUnderMouse', # Generated manually, returns an existing control, not a new one.
  43. 'DisposeControl', # Generated manually
  44. 'KillControls', # Implied by close of dialog
  45. 'SetCtlAction',
  46. 'TrackControl', # Generated manually
  47. 'HandleControlClick', # Generated manually
  48. 'SetControlData', # Generated manually
  49. 'GetControlData', # Generated manually
  50. 'kControlBevelButtonCenterPopupGlyphTag', # Constant with funny definition
  51. 'kDataBrowserClientPropertyFlagsMask', # ditto
  52. 'kDataBrowserItemAnyState', # and ditto
  53. # The following are unavailable for static 68k (appearance manager)
  54. ## 'GetBevelButtonMenuValue',
  55. ## 'SetBevelButtonMenuValue',
  56. ## 'GetBevelButtonMenuHandle',
  57. ## 'SetBevelButtonTransform',
  58. 'SetBevelButtonGraphicAlignment',
  59. 'SetBevelButtonTextAlignment',
  60. 'SetBevelButtonTextPlacement',
  61. ## 'SetImageWellTransform',
  62. ## 'GetTabContentRect',
  63. ## 'SetTabEnabled',
  64. ## 'SetDisclosureTriangleLastValue',
  65. ## # Unavailable in CW Pro 3 libraries
  66. ## 'SetUpControlTextColor',
  67. ## # Unavailable in Jack's CW Pro 5.1 libraries
  68. ## 'GetControlRegion',
  69. ## 'RemoveControlProperty',
  70. ## 'IsValidControlHandle',
  71. ## 'SetControl32BitMinimum',
  72. ## 'GetControl32BitMinimum',
  73. ## 'SetControl32BitMaximum',
  74. ## 'GetControl32BitMaximum',
  75. ## 'SetControl32BitValue',
  76. ## 'GetControl32BitValue',
  77. ## 'SetControlViewSize',
  78. ## 'GetControlViewSize',
  79. # Generally Bad News
  80. 'GetControlProperty',
  81. 'SetControlProperty',
  82. 'GetControlPropertySize',
  83. 'SendControlMessage', # Parameter changed from long to void* from UH3.3 to UH3.4
  84. 'CreateTabsControl', # wrote manually
  85. 'GetControlAction', # too much effort for too little usefulness
  86. # too lazy for now
  87. 'GetImageWellContentInfo',
  88. 'GetBevelButtonContentInfo',
  89. # OS8 only
  90. 'GetAuxiliaryControlRecord',
  91. 'SetControlColor',
  92. ]
  93. def makeblacklisttypes(self):
  94. return [
  95. 'ProcPtr',
  96. # 'ControlActionUPP',
  97. 'Ptr',
  98. 'ControlDefSpec', # Don't know how to do this yet
  99. 'ControlDefSpec_ptr', # ditto
  100. 'Collection', # Ditto
  101. # not-yet-supported stuff in Universal Headers 3.4:
  102. 'ControlColorUPP',
  103. 'ControlKind', # XXX easy: 2-tuple containing 2 OSType's
  104. # 'ControlTabEntry_ptr', # XXX needed for tabs
  105. # 'ControlButtonContentInfoPtr',
  106. # 'ControlButtonContentInfo', # XXX ugh: a union
  107. # 'ControlButtonContentInfo_ptr', # XXX ugh: a union
  108. 'ListDefSpec_ptr', # XXX see _Listmodule.c, tricky but possible
  109. 'DataBrowserItemID_ptr', # XXX array of UInt32, for BrowserView
  110. 'DataBrowserItemUPP',
  111. 'DataBrowserItemDataRef', # XXX void *
  112. 'DataBrowserCallbacks', # difficult struct
  113. 'DataBrowserCallbacks_ptr',
  114. 'DataBrowserCustomCallbacks',
  115. 'DataBrowserCustomCallbacks_ptr',
  116. ## 'DataBrowserTableViewColumnDesc',
  117. ## 'DataBrowserListViewColumnDesc',
  118. 'CFDataRef',
  119. 'DataBrowserListViewHeaderDesc', # difficult struct
  120. ]
  121. def makerepairinstructions(self):
  122. return [
  123. ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")],
  124. [("InBuffer", "*", "*")]),
  125. ([("void", "*", "OutMode"), ("long", "*", "InMode"),
  126. ("long", "*", "OutMode")],
  127. [("VarVarOutBuffer", "*", "InOutMode")]),
  128. ## # For TrackControl
  129. ## ([("ProcPtr", "actionProc", "InMode")],
  130. ## [("FakeType('(ControlActionUPP)0')", "*", "*")]),
  131. ## ([("ControlActionUPP", "actionProc", "InMode")],
  132. ## [("FakeType('(ControlActionUPP)0')", "*", "*")]),
  133. # For GetControlTitle
  134. ([('Str255', 'title', 'InMode')],
  135. [('Str255', 'title', 'OutMode')]),
  136. ([("ControlHandle", "*", "OutMode")],
  137. [("ExistingControlHandle", "*", "*")]),
  138. ([("ControlRef", "*", "OutMode")], # Ditto, for Universal Headers
  139. [("ExistingControlHandle", "*", "*")]),
  140. ([("Rect_ptr", "*", "ReturnMode")], # GetControlBounds
  141. [("void", "*", "ReturnMode")]),
  142. ([("DataBrowserListViewColumnDesc", "*", "OutMode")],
  143. [("DataBrowserListViewColumnDesc", "*", "InMode")]),
  144. ([("ControlButtonContentInfoPtr", 'outContent', "InMode")],
  145. [("ControlButtonContentInfoPtr", '*', "OutMode")]),
  146. ([("ControlButtonContentInfo", '*', "OutMode")],
  147. [("ControlButtonContentInfo", '*', "InMode")]),
  148. ([("ControlActionUPP", 'liveTrackingProc', "InMode")],
  149. [("ControlActionUPPNewControl", 'liveTrackingProc', "InMode")]),
  150. ]
  151. if __name__ == "__main__":
  152. main()