fixes for Nim 0.19

This commit is contained in:
Stefan Salewski 2018-08-02 16:31:54 +02:00
commit 37f7ee9ace
3 changed files with 94 additions and 41 deletions

View file

@ -1,6 +1,6 @@
# Package # Package
version = "0.4.3" version = "0.4.4"
author = "Stefan Salewski" author = "Stefan Salewski"
description = "High level GObject-Introspection based GTK3 bindings" description = "High level GObject-Introspection based GTK3 bindings"
license = "MIT" license = "MIT"

View file

@ -67,7 +67,7 @@ macro mconnect(widget: gobject.Object; signal: string; p: typed; arg: typed; ign
proc $1$2 {.cdecl.} = proc $1$2 {.cdecl.} =
let h: pointer = g_object_get_qdata(self, Quark) let h: pointer = g_object_get_qdata(self, Quark)
""" """
if sci.isNil: # the simple signals if sci.isNil or sci == "": # the simple signals
all = "(self: ptr gobject.Object00; xdata: pointer)" all = "(self: ptr gobject.Object00; xdata: pointer)"
ahl = "(self: gobject.Object)" ahl = "(self: gobject.Object)"
r1s.add(" $3(cast[$4](h)") r1s.add(" $3(cast[$4](h)")

View file

@ -1,5 +1,5 @@
# 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.4 2018-APR-25 # v 0.4.4 2018-AUG-02
# (c) S. Salewski 2018 # (c) S. Salewski 2018
# https://wiki.gnome.org/Projects/GObjectIntrospection # https://wiki.gnome.org/Projects/GObjectIntrospection
@ -10,12 +10,12 @@
# you may also compare the currently unmaintained work of # you may also compare the currently unmaintained work of
# https://github.com/jdmansour/nim-smartgi # https://github.com/jdmansour/nim-smartgi
# This module itself is still based on the low level GTK 3.20 wrappers at # This module itself is still based on the low level GTK 3.22 wrappers at
# https://github.com/ngtk3 # https://github.com/StefanSalewski/oldgtk3
# Currently we intentionally do not free any resources! # Currently we intentionally do not free any resources!
# First goal is creating low level bindings similar to current ngtk3. #XXX DONE # First goal is creating low level bindings similar to current oldgtk3. #XXX DONE
# Then we will add the high level wrapper similar as done in Nim's libui wrapper. #XXX Mostly DONE # Then we will add the high level wrapper similar as done in Nim's libui wrapper. #XXX Mostly DONE
# What remains is carefully inspecting the generated code, adding special like list/array results # What remains is carefully inspecting the generated code, adding special like list/array results
# and of course a lot of testing. # and of course a lot of testing.
@ -128,6 +128,21 @@ fixedProcNames.add("gtk_button_new_with_label", "newButton")
fixedProcNames.add("pango_font_description_from_string", "newFontDescription") fixedProcNames.add("pango_font_description_from_string", "newFontDescription")
fixedProcNames.add("pango_language_from_string", "languageFromString") fixedProcNames.add("pango_language_from_string", "languageFromString")
fixedProcNames.add("atk_role_register", "registerAtkRole")
fixedProcNames.add("atk_state_type_register", "registerStateType")
fixedProcNames.add("atk_relation_type_register", "registerRelationType")
fixedProcNames.add("atk_text_attribute_register", "registerTextAttribute")
fixedProcNames.add("atk_role_for_name", "roleForName")
fixedProcNames.add("atk_state_type_for_name", "stateTypeForName")
fixedProcNames.add("atk_relation_type_for_name", "relationTypeForName")
fixedProcNames.add("atk_text_attribute_for_name", "textAttributeForName")
fixedProcNames.add("gtk_settings_get_for_screen", "getSettingsForScreen")
fixedProcNames.add("gtk_icon_theme_get_for_screen", "getIconThemeForScreen")
fixedProcNames.add("gtk_requisition_new", "newRequisition")
fixedProcNames.add("gtk_text_attributes_new", "newTextAttributes")
fixedProcNames.add("pango_script_for_unichar", "scriptForUnichar")
fixedProcNames.add("pango_bidi_type_for_unichar", "bidiTypeForUnichar")
defaultParameters.add("gtk_window_new", "`type` WindowType WindowType.toplevel") defaultParameters.add("gtk_window_new", "`type` WindowType WindowType.toplevel")
defaultParameters.add("gtk_application_new", "flags gio.ApplicationFlags {}") defaultParameters.add("gtk_application_new", "flags gio.ApplicationFlags {}")
for i in keywords.split: mangledNames.add(i, '`' & i & '`') for i in keywords.split: mangledNames.add(i, '`' & i & '`')
@ -500,6 +515,15 @@ proc writeMethod(info: GIBaseInfo; minfo: GIFunctionInfo; genProxy = false) =
if sym == "gtk_text_iter_copy": return if sym == "gtk_text_iter_copy": return
if sym == "gtk_widget_destroyed": return if sym == "gtk_widget_destroyed": return
if sym == "g_error_new_literal": return if sym == "g_error_new_literal": return
#if not gCallableInfoIsMethod(minfo) and gCallableInfoGetNArgs(minfo) == 1:
# let arg = gCallableInfoGetArg(minfo, 0)
# let t = gArgInfoGetType(arg)
# if isString(t) and gTypeInfoGetTag(gCallableInfoGetReturnType(minfo)) != GITypeTag.VOID:
# echo "===#" & sym & " " & $manglename(gBaseInfoGetName(info))
for j in 0.cint ..< gCallableInfoGetNArgs(minfo): for j in 0.cint ..< gCallableInfoGetNArgs(minfo):
let arg = gCallableInfoGetArg(minfo, j) let arg = gCallableInfoGetArg(minfo, j)
let t = gArgInfoGetType(arg) let t = gArgInfoGetType(arg)
@ -516,8 +540,22 @@ proc writeMethod(info: GIBaseInfo; minfo: GIFunctionInfo; genProxy = false) =
return 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_fi$manglename(gBaseInfoGetName(info)))nd_cell_property"): return
if sym.contains("gtk_cell_area_class_find_cell_property"): return if sym.contains("gtk_cell_area_class_find_cell_property"): return
var asym = manglename(gBaseInfoGetName(mInfo)) var asym = manglename(gBaseInfoGetName(mInfo))
#[
# this does not work really well, so we do proc renaming manually using fixedProcNames seq.
if not info.isNil and not gCallableInfoIsMethod(minfo) and gCallableInfoGetNArgs(minfo) == 1:
let arg = gCallableInfoGetArg(minfo, 0)
let t = gArgInfoGetType(arg)
if isString(t) and gTypeInfoGetTag(gCallableInfoGetReturnType(minfo)) != GITypeTag.VOID:
echo "===#" & sym & " " & $manglename(gBaseInfoGetName(info))
asym[0] = asym[0].toUpperAscii
asym = $manglename(gBaseInfoGetName(info)) & asym
asym[0] = asym[0].toLowerAscii
]#
if asym == "get" or asym == "getDefault" or asym == "from" or asym == "fromString": # maybe we should relax this later a bit for the case that first parameter type == gBaseInfoGetName(info) if asym == "get" or asym == "getDefault" or asym == "from" or asym == "fromString": # maybe we should relax this later a bit for the case that first parameter type == gBaseInfoGetName(info)
asym.add($manglename(gBaseInfoGetName(info))) asym.add($manglename(gBaseInfoGetName(info)))
if sym == "gtk_buildable_get_name": asym = "buildableGetName" # conflict with gtk_widget_get_name() if sym == "gtk_buildable_get_name": asym = "buildableGetName" # conflict with gtk_widget_get_name()
@ -813,6 +851,11 @@ proc writeMethod(info: GIBaseInfo; minfo: GIFunctionInfo; genProxy = false) =
methodBuffer.writeLine(" g_error_free(gerror)") methodBuffer.writeLine(" g_error_free(gerror)")
methodBuffer.writeLine(" raise newException(GException, msg)") methodBuffer.writeLine(" raise newException(GException, msg)")
else: else:
if fixedProcNames.contains(sym):
asym = fixedProcNames[sym]
(plist, arglist, replist) = genP(mInfo, genProxy, info) (plist, arglist, replist) = genP(mInfo, genProxy, info)
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)
@ -827,7 +870,7 @@ proc writeMethod(info: GIBaseInfo; minfo: GIFunctionInfo; genProxy = false) =
methodBuffer.writeLine(" g_object_unref(cast[ptr Object00](self.impl))") methodBuffer.writeLine(" g_object_unref(cast[ptr Object00](self.impl))")
except UndefEx: except UndefEx:
echo "delay ", sym#, delayedMethods.len #######echo "delay ", sym#, delayedMethods.len
processedFunctions.excl(sym) processedFunctions.excl(sym)
delayedMethods.add((info, minfo)) delayedMethods.add((info, minfo))
methodBuffer.cut(p) methodBuffer.cut(p)
@ -938,13 +981,15 @@ proc writeInterface(info: GIInterfaceInfo) =
var plist, arglist: string var plist, arglist: string
var replist: TableRef[string, string] var replist: TableRef[string, string]
(plist, arglist, replist) = genP(signalInfo, false, nil) (plist, arglist, replist) = genP(signalInfo, false, nil)
echo plist #######echo plist
echo arglist #######echo arglist
#[
if replist.len > 0: if replist.len > 0:
for k, v in replist: for k, v in replist:
stdout.write(k & "--" & v & " ") stdout.write(k & "--" & v & " ")
stdout.writeLine("") stdout.writeLine("")
echo "PPP ", gBaseInfoGetName(signalInfo), gCallableInfoGetNArgs(signalInfo) ]#
#######echo "PPP ", gBaseInfoGetName(signalInfo), gCallableInfoGetNArgs(signalInfo)
h = h.replace(")", "; xdata: pointer)") h = h.replace(")", "; xdata: pointer)")
else: else:
h = h.replace(")", "xdata: pointer)") h = h.replace(")", "xdata: pointer)")
@ -1208,13 +1253,15 @@ proc writeObj(info: GIObjectInfo) =
var plist, arglist: string var plist, arglist: string
var replist: TableRef[string, string] var replist: TableRef[string, string]
(plist, arglist, replist) = genP(signalInfo, false, nil) (plist, arglist, replist) = genP(signalInfo, false, nil)
echo plist #######echo plist
echo arglist #######echo arglist
#[
if replist.len > 0: if replist.len > 0:
for k, v in replist: for k, v in replist:
stdout.write(k & "--" & v & " ") stdout.write(k & "--" & v & " ")
stdout.writeLine("") stdout.writeLine("")
echo "PPP ", gBaseInfoGetName(signalInfo), gCallableInfoGetNArgs(signalInfo) ]#
#######echo "PPP ", gBaseInfoGetName(signalInfo), gCallableInfoGetNArgs(signalInfo)
h = h.replace(")", "; xdata: pointer)") h = h.replace(")", "; xdata: pointer)")
else: else:
h = h.replace(")", "xdata: pointer)") h = h.replace(")", "xdata: pointer)")
@ -1438,6 +1485,10 @@ proc main(namespace: string) =
let typelib = gi.gIrepositoryRequire(namespace, version, cast[GIRepositoryLoadFlags](0), error) let typelib = gi.gIrepositoryRequire(namespace, version, cast[GIRepositoryLoadFlags](0), error)
if typelib.isNil: if typelib.isNil:
echo error.message echo error.message
echo "Maybe for your OS you have to install additional GTK related packages?"
echo "We continue with the remaining packages..."
#quit()
return
let dep: cstringArray = gi.gIrepositoryGetDependencies(namespace) let dep: cstringArray = gi.gIrepositoryGetDependencies(namespace)
output.writeLine("# dependencies:") output.writeLine("# dependencies:")
var importedModules = "" var importedModules = ""
@ -1554,6 +1605,7 @@ proc main(namespace: string) =
output.writeLine("type\n DBusPropertyInfo00Array* = pointer") output.writeLine("type\n DBusPropertyInfo00Array* = pointer")
output.writeLine("type\n DBusInterfaceInfo00Array* = pointer") output.writeLine("type\n DBusInterfaceInfo00Array* = pointer")
output.writeLine("type\n DBusNodeInfo00Array* = pointer") output.writeLine("type\n DBusNodeInfo00Array* = pointer")
output.writeLine("type\n DBusErrorEntry00Array* = pointer")
output.writeLine("type\n InputVector00Array* = pointer") output.writeLine("type\n InputVector00Array* = pointer")
output.writeLine("type\n SocketControlMessage00Array* = pointer") output.writeLine("type\n SocketControlMessage00Array* = pointer")
output.writeLine("type\n InputMessage00Array* = pointer") output.writeLine("type\n InputMessage00Array* = pointer")
@ -1639,13 +1691,13 @@ proc main(namespace: string) =
let h = priList.pop let h = priList.pop
if ig.contains(h): continue if ig.contains(h): continue
ig.incl(h) ig.incl(h)
echo h #######echo h
var k = -1 var k = -1
for p, el in s: for p, el in s:
if (gBaseInfoGetType(el) == GIInfoType.OBJECT or gBaseInfoGetType(el) == GIInfoType.INTERFACE or gBaseInfoGetType(el) == GIInfoType.STRUCT or isEnumInfo(el)) and gBaseInfoGetName(el) == h: if (gBaseInfoGetType(el) == GIInfoType.OBJECT or gBaseInfoGetType(el) == GIInfoType.INTERFACE or gBaseInfoGetType(el) == GIInfoType.STRUCT or isEnumInfo(el)) and gBaseInfoGetName(el) == h:
k = p k = p
if k >= 0: if k >= 0:
echo "moved" #######echo "moved"
s.add(s[k]) s.add(s[k])
s.delete(k) s.delete(k)
@ -1666,7 +1718,7 @@ proc main(namespace: string) =
processInfo(k) processInfo(k)
output.write(signalBuffer.data) output.write(signalBuffer.data)
output.write(methodBuffer.data) output.write(methodBuffer.data)
echo "----------", gBaseInfoGetName(k) #######echo "----------", gBaseInfoGetName(k)
except UndefEx: except UndefEx:
unp.add(k) unp.add(k)
knownSyms.excl(mangleName(gBaseInfoGetName(k))) knownSyms.excl(mangleName(gBaseInfoGetName(k)))
@ -1751,6 +1803,7 @@ supmod = newStringStream()
supmod.writeLine("const\n SCA = [") supmod.writeLine("const\n SCA = [")
main("fontconfig") main("fontconfig")
#main("nothing")
main("freetype2") main("freetype2")
main("PangoCairo") main("PangoCairo")
main("PangoFT2") main("PangoFT2")