added libvte

This commit is contained in:
Stefan Salewski 2018-03-11 15:22:02 +01:00
commit 2baabcdf38
2 changed files with 40 additions and 23 deletions

View file

@ -1,6 +1,6 @@
= High level GTK3 bindings for the Nim programming language = High level GTK3 bindings for the Nim programming language
(c) Stefan Salewski (c) Stefan Salewski
//Version 0.3 2018 //Version 0.4 2018
:experimental: :experimental:
:imagesdir: http://ssalewski.de/tmp :imagesdir: http://ssalewski.de/tmp
:source-highlighter: pygments :source-highlighter: pygments
@ -116,7 +116,7 @@ But maybe more is missing, we have to investigate that. Until now these bindings
These basic libraries are already partly tested: These basic libraries are already partly tested:
Gtk, Gdk, GLib, GObject, Gio, GdkPixbuf, GtkSource, Pango, PangoCairo, PangoFT2, GModule, Rsvg, fontconfig, freetype2, xlib, Atk and *cairo* Gtk, Gdk, GLib, GObject, Gio, GdkPixbuf, GtkSource, Pango, PangoCairo, PangoFT2, GModule, Rsvg, fontconfig, freetype2, xlib, Atk, Vte, cairo
In best case it should be possible to add more GObject based libraries to this list without larger modifications of the generator source code. In best case it should be possible to add more GObject based libraries to this list without larger modifications of the generator source code.
Unfortunately the bindings for the _cairo_ drawing library provided by {GIR} was only a minimal stub -- we have extend it manually. Unfortunately the bindings for the _cairo_ drawing library provided by {GIR} was only a minimal stub -- we have extend it manually.

View file

@ -1,6 +1,6 @@
# High level gobject-introspection based GTK3 bindings for the Nim programming language # High level gobject-introspection based GTK3 bindings for the Nim programming language
# v 0.2 2017-NOV-20 # v 0.4 2018-MAR-10
# (c) S. Salewski 2017 # (c) S. Salewski 2018
# https://wiki.gnome.org/Projects/GObjectIntrospection # https://wiki.gnome.org/Projects/GObjectIntrospection
# https://developer.gnome.org/gi/1.50/index.html # https://developer.gnome.org/gi/1.50/index.html
@ -253,7 +253,7 @@ proc genRec(t: GITypeInfo; genProxy = false; fullQualified: bool = false): strin
let tag = gTypeInfoGetTag(t) let tag = gTypeInfoGetTag(t)
if tag == GITypeTag.ARRAY: if tag == GITypeTag.ARRAY:
let toa = gTypeInfoGetArrayType(t) # type of array let toa = gTypeInfoGetArrayType(t) # type of array
if toa == GIArrayType.ARRAY: result = "Array" if toa == GIArrayType.ARRAY: result = "GArray00"
elif toa == GIArrayType.PTR_ARRAY: result = "PtrArray" elif toa == GIArrayType.PTR_ARRAY: result = "PtrArray"
elif toa == GIArrayType.BYTE_ARRAY: result = "ByteArray00" elif toa == GIArrayType.BYTE_ARRAY: result = "ByteArray00"
elif toa == GIArrayType.C: elif toa == GIArrayType.C:
@ -293,6 +293,12 @@ proc genRec(t: GITypeInfo; genProxy = false; fullQualified: bool = false): strin
proc isProxyCandidate(t: GITypeInfo): bool = proc isProxyCandidate(t: GITypeInfo): bool =
let tag = gTypeInfoGetTag(t) let tag = gTypeInfoGetTag(t)
#let tag = gTypeInfoGetTag(t)
#if tag == GITypeTag.ARRAY:
# let toa = gTypeInfoGetArrayType(t) # type of array
# if toa == GIArrayType.ARRAY: return true#result = "Array00"
if tag == GITypeTag.INTERFACE: if tag == GITypeTag.INTERFACE:
let iface = gTypeInfoGetInterface(t) let iface = gTypeInfoGetInterface(t)
var ns = ($gBaseInfoGetNamespace(iface)).toLowerAscii var ns = ($gBaseInfoGetNamespace(iface)).toLowerAscii
@ -503,6 +509,10 @@ proc writeMethod(info: GIBaseInfo; minfo: GIFunctionInfo; genProxy = false) =
methodBuffer.write("\nproc " & sym & EM & plist) methodBuffer.write("\nproc " & sym & EM & plist)
methodBuffer.writeLine(" {.\n importc: \"", sym, "\", ", libprag, ".}") methodBuffer.writeLine(" {.\n importc: \"", sym, "\", ", libprag, ".}")
processedFunctions.incl(sym) processedFunctions.incl(sym)
if sym.contains("vte_regex_unref"): # this function is special, as it returns the object
methodBuffer.writeLine("\nproc unref*(self: Regex) =")
methodBuffer.writeLine(" discard vte_regex_unref(cast[ptr Regex00](self.impl))")
return
if sym.contains("g_param_spec_") or sym.contains("g_type_interface_") or sym.contains("g_object_interface_"): return # or sym.contains("g_value_"): return if sym.contains("g_param_spec_") or sym.contains("g_type_interface_") or sym.contains("g_object_interface_"): return # or sym.contains("g_value_"): return
if sym.contains("gtk_widget_class_find_style_property") or sym.contains("gtk_container_class_find_child_property"): return if sym.contains("gtk_widget_class_find_style_property") or sym.contains("gtk_container_class_find_child_property"): return
if sym.contains("gtk_cell_area_class_find_cell_property"): return if sym.contains("gtk_cell_area_class_find_cell_property"): return
@ -554,7 +564,6 @@ proc writeMethod(info: GIBaseInfo; minfo: GIFunctionInfo; genProxy = false) =
hhh = hhh.replace("new", "init") hhh = hhh.replace("new", "init")
hhh = hhh.replace("*(", "*[T](result: var T" & semi) hhh = hhh.replace("*(", "*[T](result: var T" & semi)
methodBuffer.writeLine(hhh & " =") methodBuffer.writeLine(hhh & " =")
if true:#needProxyProc(mInfo): if true:#needProxyProc(mInfo):
for j in 0.cint ..< gCallableInfoGetNArgs(minfo): for j in 0.cint ..< gCallableInfoGetNArgs(minfo):
let arg = gCallableInfoGetArg(minfo, j) let arg = gCallableInfoGetArg(minfo, j)
@ -563,7 +572,6 @@ proc writeMethod(info: GIBaseInfo; minfo: GIFunctionInfo; genProxy = false) =
assert(false) assert(false)
let h2 = mangleName(gBaseInfoGetName(arg)) let h2 = mangleName(gBaseInfoGetName(arg))
methodBuffer.writeLine(" if " & h2 & ".isNil: " & h2 & " = new type(" & h2 & ")") methodBuffer.writeLine(" if " & h2 & ".isNil: " & h2 & " = new type(" & h2 & ")")
if gCallableInfoCanThrowGerror(minfo): if gCallableInfoCanThrowGerror(minfo):
methodBuffer.writeLine(" var gerror: ptr Error00") methodBuffer.writeLine(" var gerror: ptr Error00")
if i == 0: arglist.insert(", addr gerror", arglist.high) if i == 0: arglist.insert(", addr gerror", arglist.high)
@ -622,7 +630,7 @@ proc writeMethod(info: GIBaseInfo; minfo: GIFunctionInfo; genProxy = false) =
elif gCallableInfoGetCallerOwns(minfo) == GITransfer.EVERYTHING: elif gCallableInfoGetCallerOwns(minfo) == GITransfer.EVERYTHING:
if sym == "g_closure_new_simple": if sym == "g_closure_new_simple":
let nMethods = gStructInfoGetNMethods(info) let nMethods = gStructInfoGetNMethods(info)
for j in 0 .. <nMethods: for j in 0.cint ..< nMethods:
echo "yes there is unref method! ", $gBaseInfoGetName(gStructInfoGetMethod(info, j)) echo "yes there is unref method! ", $gBaseInfoGetName(gStructInfoGetMethod(info, j))
#assert(gStructInfoFindMethod(info, "unref") != nil) # TODO GI bug? #assert(gStructInfoFindMethod(info, "unref") != nil) # TODO GI bug?
assert info != nil assert info != nil
@ -705,7 +713,7 @@ proc writeMethod(info: GIBaseInfo; minfo: GIFunctionInfo; genProxy = false) =
else: else:
let nMethods = gStructInfoGetNMethods(iface) let nMethods = gStructInfoGetNMethods(iface)
var freeMeName: string var freeMeName: string
for j in 0 .. <nMethods: for j in 0.cint ..< nMethods:
let h = $gBaseInfoGetName(gStructInfoGetMethod(iface, j)) let h = $gBaseInfoGetName(gStructInfoGetMethod(iface, j))
if h.endsWith("free"): if h.endsWith("free"):
freeMeName = "free" freeMeName = "free"
@ -808,6 +816,7 @@ proc writeMethod(info: GIBaseInfo; minfo: GIFunctionInfo; genProxy = false) =
if asym != "errorQuark" and asym != "getPlugin" and asym != "quark": if asym != "errorQuark" and asym != "getPlugin" and asym != "quark":
methodBuffer.write("\nproc " & asym & EM & plist) methodBuffer.write("\nproc " & asym & EM & plist)
methodBuffer.writeLine(" {.\n importc: \"", sym, "\", ", libprag, ".}") methodBuffer.writeLine(" {.\n importc: \"", sym, "\", ", libprag, ".}")
if sym == "gtk_window_set_default_size": if sym == "gtk_window_set_default_size":
methodBuffer.writeLine("\nproc `defaultSize=`*(self: Window; dim: tuple[width: int; height: int]) =") methodBuffer.writeLine("\nproc `defaultSize=`*(self: Window; dim: tuple[width: int; height: int]) =")
methodBuffer.writeLine(" gtk_window_set_default_size(cast[ptr Window00](self.impl), int32(dim[0]), int32(dim[1]))") methodBuffer.writeLine(" gtk_window_set_default_size(cast[ptr Window00](self.impl), int32(dim[0]), int32(dim[1]))")
@ -827,7 +836,7 @@ proc writeUnion(info: GIUnionInfo) =
output.writeLine("type") output.writeLine("type")
output.writeLine(" ", mangleName(gBaseInfoGetName(info)) & "00" & EM, " = object {.union.}") output.writeLine(" ", mangleName(gBaseInfoGetName(info)) & "00" & EM, " = object {.union.}")
let n = info.gUnionInfoGetNFields() let n = info.gUnionInfoGetNFields()
for j in 0 .. <n: for j in 0.cint ..< n:
let field = info.gUnionInfoGetField(j) let field = info.gUnionInfoGetField(j)
let name = manglename(gBaseInfoGetName(field)) & EM let name = manglename(gBaseInfoGetName(field)) & EM
let t = gFieldInfoGetType(field) let t = gFieldInfoGetType(field)
@ -845,7 +854,7 @@ proc writeUnion(info: GIUnionInfo) =
var mseq = newSeq[GIFunctionInfo]() var mseq = newSeq[GIFunctionInfo]()
var freePos = -1 var freePos = -1
for j in 0 .. <nMethods: for j in 0.cint ..< nMethods:
mseq.add(gUnionInfoGetMethod(info, j)) mseq.add(gUnionInfoGetMethod(info, j))
if freePos < 0 and gBaseInfoGetName(gUnionInfoGetMethod(info, j)) == "free": if freePos < 0 and gBaseInfoGetName(gUnionInfoGetMethod(info, j)) == "free":
freePos = j freePos = j
@ -863,7 +872,7 @@ proc writeStruct(info: GIStructInfo) =
else: else:
output.writeLine(" ", mangleName(gBaseInfoGetName(info)) & "00" & EM & " {.pure.} = object") output.writeLine(" ", mangleName(gBaseInfoGetName(info)) & "00" & EM & " {.pure.} = object")
let n = info.gStructInfoGetNFields() let n = info.gStructInfoGetNFields()
for j in 0 .. <n: for j in 0.cint ..< n:
let field = info.gStructInfoGetField(j) let field = info.gStructInfoGetField(j)
let name = manglename(gBaseInfoGetName(field)) & EM let name = manglename(gBaseInfoGetName(field)) & EM
let t = gFieldInfoGetType(field) let t = gFieldInfoGetType(field)
@ -879,7 +888,7 @@ proc writeStruct(info: GIStructInfo) =
let nMethods = gStructInfoGetNMethods(info) let nMethods = gStructInfoGetNMethods(info)
var mseq = newSeq[GIFunctionInfo]() var mseq = newSeq[GIFunctionInfo]()
var freePos = -1 var freePos = -1
for j in 0 .. <nMethods: for j in 0.cint ..< nMethods:
mseq.add(gStructInfoGetMethod(info, j)) mseq.add(gStructInfoGetMethod(info, j))
if freePos < 0 and gBaseInfoGetName(gStructInfoGetMethod(info, j)) == "free": if freePos < 0 and gBaseInfoGetName(gStructInfoGetMethod(info, j)) == "free":
freePos = j freePos = j
@ -903,7 +912,7 @@ proc writeInterface(info: GIInterfaceInfo) =
let numsig = info.gInterfaceInfoGetNSignals let numsig = info.gInterfaceInfoGetNSignals
if numsig > 0: signalbuffer.writeLine("") if numsig > 0: signalbuffer.writeLine("")
for j in 0 .. <numsig: for j in 0.cint ..< numsig:
let signalInfo = gInterfaceInfoGetSignal(info, j) let signalInfo = gInterfaceInfoGetSignal(info, j)
#let c = gSignalInfoGetClassClosure(signalInfo) #let c = gSignalInfoGetClassClosure(signalInfo)
#if not c.isNil: echo "maybe we should process class closures!" #if not c.isNil: echo "maybe we should process class closures!"
@ -953,7 +962,7 @@ proc writeInterface(info: GIInterfaceInfo) =
signalbuffer.write($gBaseInfoGetName(signalInfo)) signalbuffer.write($gBaseInfoGetName(signalInfo))
signalbuffer.writeLine("\", cast[GCallback](p), xdata, nil, cast[ConnectFlags](0))") signalbuffer.writeLine("\", cast[GCallback](p), xdata, nil, cast[ConnectFlags](0))")
let nMethods = gInterfaceInfoGetNMethods(info) let nMethods = gInterfaceInfoGetNMethods(info)
for j in 0 .. <nMethods: for j in 0.cint ..< nMethods:
let mInfo = gInterfaceInfoGetMethod(info, j) let mInfo = gInterfaceInfoGetMethod(info, j)
writeMethod(info, minfo) writeMethod(info, minfo)
@ -1024,7 +1033,7 @@ proc writeModifierType(info: GIEnumInfo) =
#elif we == "AccelFlags": #elif we == "AccelFlags":
# output.writeLine("\nconst AccelFlagsMask* = AccelFlags(7)") # output.writeLine("\nconst AccelFlagsMask* = AccelFlags(7)")
let nMethods = gEnumInfoGetNMethods(info) let nMethods = gEnumInfoGetNMethods(info)
for j in 0 .. <nMethods: for j in 0.cint ..< nMethods:
let mInfo = gEnumInfoGetMethod(info, j) let mInfo = gEnumInfoGetMethod(info, j)
writeMethod(info, minfo) writeMethod(info, minfo)
@ -1081,7 +1090,7 @@ proc writeEnum(info: GIEnumInfo) =
if flags: if flags:
output.writeLine("\n ", tname & "Flags" & EM, " {.size: sizeof(cint).} = set[$1Flag]" % [tname]) output.writeLine("\n ", tname & "Flags" & EM, " {.size: sizeof(cint).} = set[$1Flag]" % [tname])
let nMethods = gEnumInfoGetNMethods(info) let nMethods = gEnumInfoGetNMethods(info)
for j in 0 .. <nMethods: for j in 0.cint ..< nMethods:
let mInfo = gEnumInfoGetMethod(info, j) let mInfo = gEnumInfoGetMethod(info, j)
writeMethod(info, minfo) writeMethod(info, minfo)
@ -1137,7 +1146,7 @@ proc writeObj(info: GIObjectInfo) =
if pname != "": pname.add("00") if pname != "": pname.add("00")
output.writeLine(" ", mangleName(gBaseInfoGetName(info)) & "00" & EM, oof, ns & $pname) output.writeLine(" ", mangleName(gBaseInfoGetName(info)) & "00" & EM, oof, ns & $pname)
if mangleName(gBaseInfoGetName(info)) != "InitiallyUnowned": if mangleName(gBaseInfoGetName(info)) != "InitiallyUnowned":
for j in 0 .. <n: for j in 0.cint ..< n:
let field = info.gObjectInfoGetField(j) let field = info.gObjectInfoGetField(j)
var name = mangleName(gBaseInfoGetName(field)) var name = mangleName(gBaseInfoGetName(field))
if privStr.contains(name) and cnt > 0: if privStr.contains(name) and cnt > 0:
@ -1173,7 +1182,7 @@ proc writeObj(info: GIObjectInfo) =
let numsig = info.gObjectInfoGetNSignals let numsig = info.gObjectInfoGetNSignals
if numsig > 0: signalbuffer.writeLine("") if numsig > 0: signalbuffer.writeLine("")
for j in 0 .. <numsig: for j in 0.cint ..< numsig:
let signalInfo = gObjectInfoGetSignal(info, j) let signalInfo = gObjectInfoGetSignal(info, j)
let c = gSignalInfoGetClassClosure(signalInfo) let c = gSignalInfoGetClassClosure(signalInfo)
if not c.isNil: echo "maybe we should process class closures!" if not c.isNil: echo "maybe we should process class closures!"
@ -1225,7 +1234,7 @@ proc writeObj(info: GIObjectInfo) =
signalbuffer.write($gBaseInfoGetName(signalInfo)) signalbuffer.write($gBaseInfoGetName(signalInfo))
signalbuffer.writeLine("\", cast[GCallback](p), xdata, nil, cast[ConnectFlags](0))") signalbuffer.writeLine("\", cast[GCallback](p), xdata, nil, cast[ConnectFlags](0))")
let nMethods = gObjectInfoGetNMethods(info) let nMethods = gObjectInfoGetNMethods(info)
for j in 0 .. <nMethods: for j in 0.cint ..< nMethods:
let mInfo = gObjectInfoGetMethod(info, j) let mInfo = gObjectInfoGetMethod(info, j)
writeMethod(info, minfo) writeMethod(info, minfo)
if class != nil and not allSyms.contains(mangleName(gBaseInfoGetName(class))): if class != nil and not allSyms.contains(mangleName(gBaseInfoGetName(class))):
@ -1434,6 +1443,7 @@ proc main(namespace: string) =
elif namespace == "GLib": elif namespace == "GLib":
output.writeLine("type\n GException* = object of Exception") output.writeLine("type\n GException* = object of Exception")
output.writeLine("type\n OptionEntry00Array* = pointer") output.writeLine("type\n OptionEntry00Array* = pointer")
output.writeLine("type\n GArray00* = pointer")
output.writeLine("type\n int8Array* = pointer") output.writeLine("type\n int8Array* = pointer")
output.writeLine("type\n uintArray* = pointer") output.writeLine("type\n uintArray* = pointer")
output.writeLine("type\n gbooleanArray* = pointer") output.writeLine("type\n gbooleanArray* = pointer")
@ -1441,6 +1451,7 @@ proc main(namespace: string) =
output.writeLine("type\n int32Array* = pointer") output.writeLine("type\n int32Array* = pointer")
output.writeLine("type\n PollFD00Array* = pointer") output.writeLine("type\n PollFD00Array* = pointer")
output.writeLine("type\n Variant00Array* = pointer") output.writeLine("type\n Variant00Array* = pointer")
output.writeLine("type\n Regex00Array* = pointer")
output.writeLine("type\n LogField00Array* = pointer") output.writeLine("type\n LogField00Array* = pointer")
output.writeLine("type\n VariantType00Array* = pointer") output.writeLine("type\n VariantType00Array* = pointer")
output.writeLine("type\n DebugKey00Array* = pointer") output.writeLine("type\n DebugKey00Array* = pointer")
@ -1518,6 +1529,9 @@ proc main(namespace: string) =
output.writeLine("type\n OutputVector00Array* = pointer") output.writeLine("type\n OutputVector00Array* = pointer")
elif namespace == "GtkSource": elif namespace == "GtkSource":
output.writeLine("import glib") output.writeLine("import glib")
elif namespace == "Vte":
output.writeLine("import glib\n")
output.writeLine("type\n Regex00Array* = pointer")
if namespace == "GObject": if namespace == "GObject":
output.writeLine("\nimport times") output.writeLine("\nimport times")
output.writeLine("var qt = \"NGIQ\" & $epochTime()") output.writeLine("var qt = \"NGIQ\" & $epochTime()")
@ -1547,7 +1561,7 @@ proc main(namespace: string) =
var interf = newSeq[string]() var interf = newSeq[string]()
let name = $gBaseInfoGetName(info) let name = $gBaseInfoGetName(info)
for i in 0 .. < ninterfaces: for i in 0.cint ..< ninterfaces:
interf.add($gBaseInfoGetName(info.gObjectInfoGetInterface(i))) interf.add($gBaseInfoGetName(info.gObjectInfoGetInterface(i)))
if provInt.contains(name): if provInt.contains(name):
@ -1567,7 +1581,8 @@ proc main(namespace: string) =
var h = $gBaseInfoGetName(i) var h = $gBaseInfoGetName(i)
if h.startsWith("KEY_"): if h.startsWith("KEY_"):
if gdkKeys.contains(h.toLowerAscii): if gdkKeys.contains(h.toLowerAscii):
gdkKeys.mget(h.toLowerAscii).add(h) #gdkKeys.mget(h.toLowerAscii).add(h)
gdkKeys[h.toLowerAscii].add(h)
else: else:
gdkKeys.add(h.toLowerAscii, @[h]) gdkKeys.add(h.toLowerAscii, @[h])
for el in mvalues(gdkKeys): for el in mvalues(gdkKeys):
@ -1698,6 +1713,7 @@ proc main(namespace: string) =
#scfilter = initSet[string]() #scfilter = initSet[string]()
supmod = newStringStream() supmod = newStringStream()
supmod.writeLine("const\n SCA = [") supmod.writeLine("const\n SCA = [")
main("fontconfig") main("fontconfig")
main("freetype2") main("freetype2")
main("PangoCairo") main("PangoCairo")
@ -1715,6 +1731,7 @@ main("Rsvg")
main("Gdk") main("Gdk")
main("Gtk") main("Gtk")
main("GtkSource") main("GtkSource")
main("Vte")
supmod.writeLine(" ]") supmod.writeLine(" ]")
supmod.flush supmod.flush
@ -1724,4 +1741,4 @@ o.close()
supmod.close supmod.close
#for i in callerAllocCollector: echo i #for i in callerAllocCollector: echo i
# 1725 lines # 1743 lines