diff options
Diffstat (limited to 'qt')
-rw-r--r-- | qt/ScintillaEdit/WidgetGen.py | 119 | ||||
-rw-r--r-- | qt/ScintillaEditPy/sepbuild.py | 19 |
2 files changed, 57 insertions, 81 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)) diff --git a/qt/ScintillaEditPy/sepbuild.py b/qt/ScintillaEditPy/sepbuild.py index a823a96b7..77d2cb221 100644 --- a/qt/ScintillaEditPy/sepbuild.py +++ b/qt/ScintillaEditPy/sepbuild.py @@ -11,6 +11,11 @@ import sys sys.path.append(os.path.join("..", "ScintillaEdit")) import WidgetGen +scintillaDirectory = "../.." +scintillaScriptsDirectory = os.path.join(scintillaDirectory, "scripts") +sys.path.append(scintillaScriptsDirectory) +from FileGenerator import GenerateFile + # Decide up front which platform, treat anything other than Windows or OS X as Linux PLAT_WINDOWS = platform.system() == "Windows" PLAT_DARWIN = platform.system() == "Darwin" @@ -56,8 +61,7 @@ def usage(): print("-u --underscore-names use method_names consistent with GTK+ standards") modifyFunctionElement = """ <modify-function signature="%s">%s - </modify-function> -""" + </modify-function>""" injectCode = """ <inject-code class="target" position="beginning">%s @@ -83,7 +87,8 @@ def methodSignature(name, v, options): constDeclarator = " const" if v["FeatureType"] == "get" else "" return methodName + "(" + argTypes + ")" + constDeclarator -def printTypeSystemFile(f,out, options): +def printTypeSystemFile(f, options): + out = [] for name in f.order: v = f.features[name] if v["Category"] != "Deprecated": @@ -99,9 +104,10 @@ def printTypeSystemFile(f,out, options): checks = checks + (injectCheckN % 1) if checks: inject = injectCode % checks - out.write(modifyFunctionElement % (methodSignature(name, v, options), inject)) + out.append(modifyFunctionElement % (methodSignature(name, v, options), inject)) #if v["Param1Type"] == "string": - # out.write("<string-xml>" + name + "</string-xml>\n") + # out.append("<string-xml>" + name + "</string-xml>\n") + return out def doubleBackSlashes(s): # Quote backslashes so qmake does not produce warnings @@ -193,7 +199,8 @@ class SepBuilder: f = WidgetGen.readInterface(False) os.chdir(os.path.join("..", "ScintillaEditPy")) options = {"qtStyle": self.qtStyleInterface} - WidgetGen.Generate("typesystem_ScintillaEdit.xml.template", "typesystem_ScintillaEdit.xml", printTypeSystemFile, f, options) + GenerateFile("typesystem_ScintillaEdit.xml.template", "typesystem_ScintillaEdit.xml", + "<!-- ", True, printTypeSystemFile(f, options)) def runGenerator(self): generatorrunner = "shiboken" |