#!/usr/bin/env python # WidgetGen.py - regenerate the ScintillaWidgetCpp.cpp and ScintillaWidgetCpp.h files # Check that API includes all gtkscintilla2 functions import sys import os import getopt scintillaDirectory = "../.." scintillaIncludeDirectory = os.path.join(scintillaDirectory, "include") sys.path.append(scintillaIncludeDirectory) import Face def Contains(s,sub): return s.find(sub) != -1 def underscoreName(s): # Name conversion fixes to match gtkscintilla2 irregular = ['WS', 'EOL', 'AutoC', 'KeyWords', 'BackSpace', 'UnIndents', 'RE', 'RGBA'] for word in irregular: replacement = word[0] + word[1:].lower() s = s.replace(word, replacement) out = "" for c in s: if c.isupper(): if out: out += "_" out += c.lower() else: out += c return out def normalisedName(s, options, role=None): if options["qtStyle"]: if role == "get": s = s.replace("Get", "") return s[0].lower() + s[1:] else: return underscoreName(s) typeAliases = { "position": "int", "colour": "int", "keymod": "int", "string": "const char *", "stringresult": "const char *", "cells": "const char *", } def cppAlias(s): if s in typeAliases: return typeAliases[s] else: return s understoodTypes = ["", "void", "int", "bool", "position", "colour", "keymod", "string", "stringresult", "cells"] def checkTypes(name, v): understandAllTypes = True if v["ReturnType"] not in understoodTypes: #~ print("Do not understand", v["ReturnType"], "for", name) understandAllTypes = False if v["Param1Type"] not in understoodTypes: #~ print("Do not understand", v["Param1Type"], "for", name) understandAllTypes = False if v["Param2Type"] not in understoodTypes: #~ print("Do not understand", v["Param2Type"], "for", name) understandAllTypes = False return understandAllTypes def arguments(v, stringResult, options): ret = "" p1Type = cppAlias(v["Param1Type"]) if p1Type: ret = ret + p1Type + " " + normalisedName(v["Param1Name"], options) p2Type = cppAlias(v["Param2Type"]) if p2Type and not stringResult: if p1Type: ret = ret + ", " ret = ret + p2Type + " " + normalisedName(v["Param2Name"], options) return ret def printPyFile(f,out, options): 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") if feat in ["evt"]: out.write("SCN_" + name.upper() + "=" + v["Value"] + "\n") def printHFile(f,out, options): for name in f.order: v = f.features[name] if v["Category"] != "Deprecated": feat = v["FeatureType"] if feat in ["fun", "get", "set"]: if checkTypes(name, v): constDeclarator = " const" if feat == "get" else "" returnType = cppAlias(v["ReturnType"]) 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") def methodNames(f, options): for name in f.order: v = f.features[name] if v["Category"] != "Deprecated": feat = v["FeatureType"] if feat in ["fun", "get", "set"]: if checkTypes(name, v): yield normalisedName(name, options) def printCPPFile(f,out, options): for name in f.order: v = f.features[name] if v["Category"] != "Deprecated": feat = v["FeatureType"] if feat in ["fun", "get", "set"]: if checkTypes(name, v): constDeclarator = " const" if feat == "get" else "" featureDefineName = "SCI_" + name.upper() returnType = cppAlias(v["ReturnType"]) stringResult = v["Param2Type"] == "stringresult" if stringResult: returnType = "QByteArray" returnStatement = "" if returnType != "void": returnStatement = "return " out.write(returnType + " ScintillaEdit::" + normalisedName(name, options, feat) + "(") out.write(arguments(v, stringResult, options)) out.write(")" + constDeclarator + " {\n") if stringResult: out.write(" " + returnStatement + "TextReturner(" + featureDefineName + ", ") if "*" in cppAlias(v["Param1Type"]): out.write("(uptr_t)") if v["Param1Name"]: out.write(normalisedName(v["Param1Name"], options)) else: out.write("0") out.write(");\n") else: out.write(" " + returnStatement + "send(" + featureDefineName + ", ") if "*" in cppAlias(v["Param1Type"]): out.write("(uptr_t)") if v["Param1Name"]: out.write(normalisedName(v["Param1Name"], options)) else: out.write("0") out.write(", ") if "*" in cppAlias(v["Param2Type"]): out.write("(sptr_t)") if v["Param2Name"]: out.write(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 "