diff options
| author | Neil <nyamatongwe@gmail.com> | 2013-07-01 16:37:06 +1000 | 
|---|---|---|
| committer | Neil <nyamatongwe@gmail.com> | 2013-07-01 16:37:06 +1000 | 
| commit | 92bd3a82d73dd2ea22df882b0b62e7f5878e5420 (patch) | |
| tree | af35507a7c121fae3916a4f69c357f163927248c /qt/ScintillaEdit/WidgetGen.py | |
| parent | c47b81b98f01cf84f5559adae256bff58b54005f (diff) | |
| download | scintilla-mirror-92bd3a82d73dd2ea22df882b0b62e7f5878e5420.tar.gz | |
Move non-platform-specific scripts into the scripts directory.
Use FileGenerator module for file generation instead of code in each script.
Diffstat (limited to 'qt/ScintillaEdit/WidgetGen.py')
| -rw-r--r-- | qt/ScintillaEdit/WidgetGen.py | 119 | 
1 files changed, 44 insertions, 75 deletions
| diff --git a/qt/ScintillaEdit/WidgetGen.py b/qt/ScintillaEdit/WidgetGen.py index 322c7dc7d..b53fe988c 100644 --- a/qt/ScintillaEdit/WidgetGen.py +++ b/qt/ScintillaEdit/WidgetGen.py @@ -7,12 +7,10 @@ import os  import getopt  scintillaDirectory = "../.." -scintillaIncludeDirectory = os.path.join(scintillaDirectory, "include") -sys.path.append(scintillaIncludeDirectory) +scintillaScriptsDirectory = os.path.join(scintillaDirectory, "scripts") +sys.path.append(scintillaScriptsDirectory)  import Face - -def Contains(s,sub): -	return s.find(sub) != -1 +from FileGenerator import GenerateFile  def underscoreName(s):  	# Name conversion fixes to match gtkscintilla2 @@ -82,17 +80,20 @@ def arguments(v, stringResult, options):  		ret = ret + p2Type + " " + normalisedName(v["Param2Name"], options)  	return ret -def printPyFile(f,out, options): +def printPyFile(f, options): +	out = []  	for name in f.order:  		v = f.features[name]  		if v["Category"] != "Deprecated":  			feat = v["FeatureType"]  			if feat in ["val"]: -				out.write(name + "=" + v["Value"] + "\n") +				out.append(name + "=" + v["Value"])  			if feat in ["evt"]: -				out.write("SCN_" + name.upper() + "=" + v["Value"] + "\n") +				out.append("SCN_" + name.upper() + "=" + v["Value"]) +	return out -def printHFile(f,out, options): +def printHFile(f, options): +	out = []  	for name in f.order:  		v = f.features[name]  		if v["Category"] != "Deprecated": @@ -104,9 +105,10 @@ def printHFile(f,out, options):  					stringResult = v["Param2Type"] == "stringresult"  					if stringResult:  						returnType = "QByteArray" -					out.write("\t" + returnType + " " + normalisedName(name, options, feat) + "(") -					out.write(arguments(v, stringResult, options)) -					out.write(")" + constDeclarator + ";\n") +					out.append("\t" + returnType + " " + normalisedName(name, options, feat) + "(" + +						arguments(v, stringResult, options)+ +						")" + constDeclarator + ";") +	return out  def methodNames(f, options):  	for name in f.order: @@ -117,7 +119,8 @@ def methodNames(f, options):  				if checkTypes(name, v):  					yield normalisedName(name, options) -def printCPPFile(f,out, options): +def printCPPFile(f, options): +	out = []  	for name in f.order:  		v = f.features[name]  		if v["Category"] != "Deprecated": @@ -133,75 +136,39 @@ def printCPPFile(f,out, options):  					returnStatement = ""  					if returnType != "void":  						returnStatement = "return " -					out.write(returnType + " ScintillaEdit::" + normalisedName(name, options, feat) + "(") -					out.write(arguments(v, stringResult, options)) -					out.write(")" + constDeclarator + " {\n") +					out.append(returnType + " ScintillaEdit::" + normalisedName(name, options, feat) + "(" + +						arguments(v, stringResult, options) + +						")" + constDeclarator + " {") +					returns = ""  					if stringResult: -						out.write("    " + returnStatement + "TextReturner(" + featureDefineName + ", ") +						returns += "    " + returnStatement + "TextReturner(" + featureDefineName + ", "  						if "*" in cppAlias(v["Param1Type"]): -							out.write("(uptr_t)") +							returns += "(uptr_t)"  						if v["Param1Name"]: -							out.write(normalisedName(v["Param1Name"], options)) +							returns += normalisedName(v["Param1Name"], options)  						else: -							out.write("0") -						out.write(");\n") +							returns += "0" +						returns += ");"  					else: -						out.write("    " + returnStatement + "send(" + featureDefineName + ", ") +						returns += "    " + returnStatement + "send(" + featureDefineName + ", "  						if "*" in cppAlias(v["Param1Type"]): -							out.write("(uptr_t)") +							returns += "(uptr_t)"  						if v["Param1Name"]: -							out.write(normalisedName(v["Param1Name"], options)) +							returns += normalisedName(v["Param1Name"], options)  						else: -							out.write("0") -						out.write(", ") +							returns += "0" +						returns += ", "  						if "*" in cppAlias(v["Param2Type"]): -							out.write("(sptr_t)") +							returns += "(sptr_t)"  						if v["Param2Name"]: -							out.write(normalisedName(v["Param2Name"], options)) +							returns += normalisedName(v["Param2Name"], options)  						else: -							out.write("0") -						out.write(");\n") -					out.write("}\n") -					out.write("\n") - -def CopyWithInsertion(input, output, genfn, definition, options): -	copying = 1 -	for line in input.readlines(): -		if copying: -			output.write(line) -		if "/* ++Autogenerated" in line or "# ++Autogenerated" in line or "<!-- ++Autogenerated" in line: -			copying = 0 -			genfn(definition, output, options) -		# ~~ form needed as XML comments can not contain -- -		if "/* --Autogenerated" in line or "# --Autogenerated" in line or "<!-- ~~Autogenerated" in line: -			copying = 1 -			output.write(line) - -def contents(filename): -	with open(filename, "U") as f: -		t = f.read() -		return t - -def Generate(templateFile, destinationFile, genfn, definition, options): -	inText = contents(templateFile) -	try: -		currentText = contents(destinationFile) -	except IOError: -		currentText = "" -	tempname = "WidgetGen.tmp" -	with open(tempname, "w") as out: -		with open(templateFile, "U") as hfile: -			CopyWithInsertion(hfile, out, genfn, definition, options) -	outText = contents(tempname) -	if currentText == outText: -		os.unlink(tempname) -	else: -		try: -			os.unlink(destinationFile) -		except OSError: -			# Will see failure if file does not yet exist -			pass -		os.rename(tempname, destinationFile) +							returns += "0" +						returns += ");" +					out.append(returns) +					out.append("}") +					out.append("") +	return out  def gtkNames():  	# The full path on my machine: should be altered for anyone else @@ -253,11 +220,13 @@ def main(argv):  	options = {"qtStyle": qtStyleInterface}  	f = readInterface(cleanGenerated)  	try: -		Generate("ScintillaEdit.cpp.template", "ScintillaEdit.cpp", printCPPFile, f, options) -		Generate("ScintillaEdit.h.template", "ScintillaEdit.h", printHFile, f, options) -		Generate("../ScintillaEditPy/ScintillaConstants.py.template", +		GenerateFile("ScintillaEdit.cpp.template", "ScintillaEdit.cpp",  +			"/* ", True, printCPPFile(f, options)) +		GenerateFile("ScintillaEdit.h.template", "ScintillaEdit.h", +			"/* ", True, printHFile(f, options)) +		GenerateFile("../ScintillaEditPy/ScintillaConstants.py.template",  			"../ScintillaEditPy/ScintillaConstants.py", -			printPyFile, f, options) +			"# ", True, printPyFile(f, options))  		if checkGTK:  			names = set(methodNames(f))  			#~ print("\n".join(names)) | 
