1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
import sys
for i in range(0, len(sys.argv)):
if sys.argv[i] == "-vtkdir" and i < len(sys.argv)-1:
input_file = sys.argv[i+1]
if not input_file:
print "Usage: %s [-vtkdir <path to the vtk source tree>] [-k ...] ..." % sys.argv[0]
print "Got Args: %s" % `sys.argv`
sys.exit(1)
input_file = input_file+"/Common/vtkCommand.h"
fp = file(input_file, "r")
fp = fp.readlines()
output = "vtkEventIDs = [\n"
Start = False
for f in fp:
# Old style:
if f.strip() == "};":
Start = False
# New style:
if f.strip() == "#define VTK_DECLARE_EVENTIDS(_enum_name)\\":
Start = False
output += "\"UserEvent\",\n"
if Start == True:
if f.find("*/")<0:
if f.count("//")>0:
f=f[:f.find("//")]
if f.count("=")>0:
f=f[:f.find("=")]
# Old style:
f = f.replace(",","")
# New style:
f = f.replace("_vtk_add_event(","")
f = f.replace(")","")
f = f.replace("\\","")
event_name = f.replace(" ","").replace("\n","")
if event_name != "":
output += "\"" + event_name + "\"" + ",\n"
# Old style:
if f.strip().replace(" ","").replace("\n","") == "enumEventIds{":
Start = True
# New style:
if f.strip().replace(" ","").replace("\n","") == "#defineVTK_EVENT_TYPES\\":
Start = True
output += "\"NoEvent\",\n"
output = output[:-2] + """
]
def get_vtk_event_ids():
return vtkEventIDs
"""
try:
ofp = file("vtkCommandList.py.in", "w")
ofp.write(output)
ofp.close()
except:
print "Failed to write output file %s" % output
sys.exit(1)
|