rendered paste body#!/usr/bin/env python
# file: tmp.py
import ldtp, sys, re
if len(sys.argv) < 3:
print 'Mistach the tag which you wanna generate.\n \
\tRun as genrmap.py <winwain> <python file>'
sys.exit(0)
def striptodefname(tag):
return filterpattern.sub('', tag)
def writetitle(fileopened):
headed = fileopened.readline()
if headed != '#!/usr/bin/env python':
lines = '#!/usr/bin/env python\n\n'
lines += 'sepsym = ";"\n\n'
fileopened.writelines(lines)
return
# the pattern removes the unwanted string
filterpattern = re.compile(r'[^\d\w]')
winmain = sys.argv[1]
pyfile = file(sys.argv[2], 'w+')
writetitle(pyfile)
objlists = ldtp.getobjectlist(winmain)
for objlist in objlists:
print objlist
parent = None
tagname = objlist
defname = striptodefname(objlist)
# check whether the control is menu
if defname[0:3] == 'mnu':
parenttmp = ldtp.getobjectproperty(winmain, objlist, 'parnet')
if parenttmp[0:3] == 'mnu':
parent = parenttmp
lines = 'def %s(parent = %s):\n' % (defname, parent)
lines += '\ttag = "%s"\n' % tagname
lines += '\tif parent:\n'
lines += '\t\ttag = tag + sepsym + parent()\n'
lines += '\treturn tag\n\n'
pyfile.writelines(lines)
else:
pyfile.close()