rendered paste body#!/usr/bin/env python
# file: tmp.py
import ldtp, sys, re
aa = [u'pnl1', u'tchPlaces', u'tchModified', u'mnu0', u'btnCreateFolder', u'mnu3', u'tchName', u'btn0', u'mnuAutoDetected', u'btnCancel', u'btn1', u'cboAllFiles', u'tbtnTypeafilename', u'scbr0', u'dlgOpenFile...', u'tbtnnags', u'flr0', u'tbtn3', u'btnRemove', u'flr1', u'flr2', u'flr3', u'flr10', u'flr4', u'flr11', u'lblLocation', u'flr5', u'scpn0', u'flr6', u'flr12', u'scpn1', u'flr7', u'mnuWestern(ISO-8859-15)', u'flr13', u'flr8', u'flr9', u'tbtnhome', u'cboCharacterCoding', u'mnuCurrentLocale(UTF-8)']
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()