version 0.9.3

This commit is contained in:
Stefan Salewski 2021-06-29 12:54:59 +02:00
commit 23c2fdeafe
3 changed files with 34 additions and 11 deletions

View file

@ -29,12 +29,13 @@ with code inserted from files directly.
NOTE: This work is partly based on earlier works of J. Mansour and has been supported by A. Rumpf, E. Bassi and other _Nim_ and _GTK/Gnome_ developers. NOTE: This work is partly based on earlier works of J. Mansour and has been supported by A. Rumpf, E. Bassi and other _Nim_ and _GTK/Gnome_ developers.
The `combinatorics` module was kindly provided by R. Behrends. The `combinatorics` module was kindly provided by R. Behrends.
NOTE: The upcomming version 0.9.3 of the gintro Nim GTK bindings contains some serious changes NOTE: The current version 0.9.3 of the gintro Nim GTK bindings contains some serious changes
following the discussion in https://discourse.gnome.org/t/get-ref-function-for-none-gobject-classes-like-gtkexpression/6696. following the discussion in https://discourse.gnome.org/t/get-ref-function-for-none-gobject-classes-like-gtkexpression/6696.
With that changes issue https://github.com/StefanSalewski/gintro/issues/135 should be fixed, and the listview_clocks example works With that changes issue https://github.com/StefanSalewski/gintro/issues/135 should be fixed, and the listview_clocks example works
with a C and a Nim part. For most apps that changes should be invisible, but it is possible that we have introduced with a C and a Nim part. For most apps that changes should be invisible, but it is possible that we have introduced
new bugs or maybe memory leaks. At least the existing examples seems still to compile, but we have not yet tested them all. new bugs or maybe memory leaks. At least the existing examples seems still to compile, but we have not yet tested them all.
You can test this version with nimble install gintro@#head. //You can test this version with nimble install gintro@#head.
And the notify signals for gobject properties like "notify::cursor-moved" for entry widgets should work now.
NOTE: The version 0.9.2 of the gintro Nim GTK bindings is only a fix for the issue with latest gstreamer NOTE: The version 0.9.2 of the gintro Nim GTK bindings is only a fix for the issue with latest gstreamer
from gitlab, see https://github.com/StefanSalewski/gintro/issues/138. from gitlab, see https://github.com/StefanSalewski/gintro/issues/138.

View file

@ -17,6 +17,11 @@ proc ct5nt(s: string): string =
proc findSignal(name, obj: NimNode): string = proc findSignal(name, obj: NimNode): string =
let str = ($name).replace("-", "_") & RecSep let str = ($name).replace("-", "_") & RecSep
#echo str
if str.startsWith("notify::"):
return "notify!Object!1!(self: Object; paramSpec: ParamSpec)!(self: ptr Object00; paramSpec: ptr ParamSpec00)"
# "size_allocate!Widget!1!(self: Widget; allocation: gdk.Rectangle)!(self: ptr Widget00; allocation: gdk.Rectangle)"
var ipros: seq[string] var ipros: seq[string]
for i in SCA: for i in SCA:
if i.startsWith(str): if i.startsWith(str):
@ -47,6 +52,7 @@ proc findSignal(name, obj: NimNode): string =
# https://mail.gnome.org/archives/gtk-list/2017-July/msg00018.html # https://mail.gnome.org/archives/gtk-list/2017-July/msg00018.html
# This interface parameter is in most cases the second parameter of handler proc, but can be the third also. # This interface parameter is in most cases the second parameter of handler proc, but can be the third also.
macro mconnect(widget: gobject.Object; signal: string; p: typed; arg: typed; ignoreArg: bool; sf: static[gobject.ConnectFlags]): untyped = macro mconnect(widget: gobject.Object; signal: string; p: typed; arg: typed; ignoreArg: bool; sf: static[gobject.ConnectFlags]): untyped =
# echo $signal
#echo p.symbol.getImpl().toStrLit #echo p.symbol.getImpl().toStrLit
#echo p.symbol.getImpl().params.toStrLit #echo p.symbol.getImpl().params.toStrLit
#echo p.symbol.getImpl().params[2][1].toStrLit #echo p.symbol.getImpl().params[2][1].toStrLit
@ -79,7 +85,14 @@ macro mconnect(widget: gobject.Object; signal: string; p: typed; arg: typed; ign
#assert ats == $(at.toStrLit) #assert ats == $(at.toStrLit)
#assert ats == at.toStrLit.strVal #assert ats == at.toStrLit.strVal
let signalName = ($signal).replace("-", "_") # maybe we should just use plain proc names var signalName = ($signal).replace("-", "_") # maybe we should just use plain proc names
var sigName: string # for the notify:: signals
if signalName.startsWith("notify::"):
#sfstr.add(", " & signalName)
sigName = ", \"" & signalName.replace("_", "-") & "\"" # https://mail.gnome.org/archives/gtk-app-devel-list/2008-March/msg00197.html
signalName = "notify" # https://discourse.gnome.org/t/notify-signal-and-underscore-vs-hyphen/6835
let procNameCdecl = "connect_for_signal_cdecl_" & signalName & $ProcID let procNameCdecl = "connect_for_signal_cdecl_" & signalName & $ProcID
let procName = "connect_for_signal_" & signalName & $ProcID let procName = "connect_for_signal_" & signalName & $ProcID
var sn, wid, num, all, ahl: string var sn, wid, num, all, ahl: string
@ -258,14 +271,14 @@ proc $1$2 {.cdecl.} =
proc $1(self: $2; p: proc $3): culong {.discardable.} = proc $1(self: $2; p: proc $3): culong {.discardable.} =
sc$4(self, $5, nil, $8) sc$4(self, $5, nil, $8)
$1($6, $7) $1($6, $7)
""" % [$procName, wts, ahl, signalName, $procNameCdecl, $(widget.toStrLit), $p, sfstr] """ % [$procName, wts, ahl, signalName, $procNameCdecl, $(widget.toStrLit), $p, sfstr, sigName]
elif getTypeInst(arg).typeKind == ntyRef: elif getTypeInst(arg).typeKind == ntyRef:
""" """
proc $1(self: $2; p: proc $3; a: $4): culong {.discardable.} = proc $1(self: $2; p: proc $3; a: $4): culong {.discardable.} =
GC_ref(a) GC_ref(a)
sc$5(self, $6, cast[pointer](a), $10) sc$5(self, $6, cast[pointer](a), $10 $11)
$1($7, $8, $9) $1($7, $8, $9)
""" % [$procName, wts, ahl, ats, signalName, $procNameCdecl, $(widget.toStrLit), $p, $(arg.toStrLit), sfstr] """ % [$procName, wts, ahl, ats, signalName, $procNameCdecl, $(widget.toStrLit), $p, $(arg.toStrLit), sfstr, sigName]
else: else:
""" """
proc $1(self: $2; p: proc $3; a: $4): culong {.discardable.} = proc $1(self: $2; p: proc $3; a: $4): culong {.discardable.} =
@ -275,9 +288,9 @@ proc $1(self: $2; p: proc $3; a: $4): culong {.discardable.} =
ar[] = a ar[] = a
GC_ref(ar) GC_ref(ar)
# sc$5(self, $6, cast[pointer](ar[])) # sc$5(self, $6, cast[pointer](ar[]))
sc$5(self, $6, cast[pointer](ar), $10) sc$5(self, $6, cast[pointer](ar), $10 $11)
$1($7, $8, $9) $1($7, $8, $9)
""" % [$procName, wts, ahl, ats, signalName, $procNameCdecl, $(widget.toStrLit), $p, $(arg.toStrLit), sfstr] """ % [$procName, wts, ahl, ats, signalName, $procNameCdecl, $(widget.toStrLit), $p, $(arg.toStrLit), sfstr, sigName]
#echo r2s #echo r2s
result.add(parseStmt(r2s)) result.add(parseStmt(r2s))
@ -360,6 +373,6 @@ $1($4)
""" % [$procName, ats, $procNameCdecl, $arg] """ % [$procName, ats, $procNameCdecl, $arg]
result = parseStmt(r1s & r2s) result = parseStmt(r1s & r2s)
# 362 lines # 376 lines

View file

@ -1,6 +1,6 @@
# High level gobject-introspection based GTK4/GTK3 bindings for the Nim programming language # High level gobject-introspection based GTK4/GTK3 bindings for the Nim programming language
# nimpretty --maxLineLen:130 gen.nim # nimpretty --maxLineLen:130 gen.nim
# v 0.9.3 2021-JUN-18 # v 0.9.3 2021-JUN-29
# (c) S. Salewski 2018, 2019, 2020, 2021 # (c) S. Salewski 2018, 2019, 2020, 2021
# usefull for finding death code: # usefull for finding death code:
@ -353,6 +353,8 @@ defaultParameters["gtk_builder_new_from_string"] = "length int64 -1"
defaultParameters["gtk_box_new"] = "spacing int 0" defaultParameters["gtk_box_new"] = "spacing int 0"
defaultParameters["gtk_grid_attach"] = "width int 1|height int 1" defaultParameters["gtk_grid_attach"] = "width int 1|height int 1"
defaultParameters["gtk_adjustment_new"] = "pageSize cdouble 1.0" defaultParameters["gtk_adjustment_new"] = "pageSize cdouble 1.0"
defaultParameters["pango_layout_set_text"] = "length int -1"
# proc pango_layout_set_text(self: ptr Layout00; text: cstring; length: int32)
for i in keywords: mangledNames[i] = '`' & i & '`' for i in keywords: mangledNames[i] = '`' & i & '`'
@ -3135,6 +3137,13 @@ const GObject_EPI = """
# let p = cast[ptr cuint](cast[int](o.impl) + sizeof(pointer)) # let p = cast[ptr cuint](cast[int](o.impl) + sizeof(pointer))
# return p[].int # return p[].int
proc scNotify*(self: Object; p: proc (self: ptr Object00; paramSpec: ptr ParamSpec00; xdata: pointer) {.cdecl.}, xdata: pointer, cf: gobject.ConnectFlags; sigName: cstring): culong =
# g_signal_connect_data(self.impl, "notify::cursor-position", cast[GCallback](p), xdata, nil, cf)
g_signal_connect_data(self.impl, sigName, cast[GCallback](p), xdata, nil, cf)
# similar to gobjectTemp() # similar to gobjectTemp()
proc glistObjects2seq*[T](t: typedesc[T]; l: ptr glib.List; elTransferFull: bool): seq[T] = proc glistObjects2seq*[T](t: typedesc[T]; l: ptr glib.List; elTransferFull: bool): seq[T] =
var r: T var r: T
@ -4260,7 +4269,7 @@ launch()
# if not xcallerAlloc.contains(el): # if not xcallerAlloc.contains(el):
# echo el # echo el
# 4263 lines # 4263 lines defaultParameters
# gtk_icon_view_get_tooltip_context bug Candidate # gtk_icon_view_get_tooltip_context bug Candidate
# gtk_tree_view_get_cursor bug # gtk_tree_view_get_cursor bug
# #