I have just shipped v0.2 of package gintro. Its connect macro can now deal with
arbitrary number of arguments, which is needed for a few callbacks like the
"draw" callback for DrawingArea widget. (Additional, module gtksourceview is
now included, as well as a preliminary version of full cairo drawing module,
but that one still needs some manual tuning, because cairo is not really
supported by gobject introspection.)
Seems to work fine, but one minor problem is the name conflict of modules gio
and gtk -- gio has type Application, and gtk has a subclass of it. Import with
except works, but using module name prefix seems not to work:
# nim c connect_args.nim
import gintro/[gtk, glib, gobject]
import gintro/gio #except Application, newApplication
type
O = object
i: int
proc b1Callback(button: Button; str: string) =
echo str
proc b2Callback(button: Button; o: O) =
echo "Value of field i in object o = ", o.i
proc b3Callback(button: Button; r: ref O) =
echo "Value of field i in ref to object O = ", r.i
proc b4Callback(button: Button; w: ApplicationWindow) =
if w.title == "Nim with GTK3":
w.title = "GTK3 with Nim"
else:
w.title = "Nim with GTK3"
proc activate (app: gtk.Application) =
var o: O
var r: ref O
new r
o.i = 1234567
r.i = 7654321
let window = gtk.newApplicationWindow(app)
let box = newBox(Orientation.vertical, 0)
window.title = "Parameters for callbacks"
let b1 = newButton("Nim with GTK3")
let b2 = newButton("Passing an object from stack")
let b3 = newButton("Passing an object from heap")
let b4 = newButton("Passing a Widget")
b1.connect("clicked", b1Callback, "is much fun.")
b2.connect("clicked", b2Callback, o)
b3.connect("clicked", b3Callback, r)
b4.connect("clicked", b4Callback, window)
box.add(b1)
box.add(b2)
box.add(b3)
box.add(b4)
window.add(box)
window.showAll
proc main =
let app = gtk.newApplication("org.gtk.example")
connect(app, "activate", activate)
discard app.run
main()
connect_args.nim(50, 10) template/generic instantiation from here
lib/core/macros.nim(368, 17) Error: Error: ambiguous identifier:
'Application' --use gtk.Application or gio.Application
Such macro related error message are a big demand for me, for a few I spent
some hours to find the true origin. AS this one is not really a showstopper, I
have not tried finding the source or a fix myself yet.
The connect macro is located at
[https://github.com/StefanSalewski/gintro/blob/master/gintro/gimpl.nim#L30](https://github.com/StefanSalewski/gintro/blob/master/gintro/gimpl.nim#L30)
I assume that users may not really like an import with mandatory except. And I
hesitate to rename gio.Application to GApplication, because it may generate
some confusion, and is not really straight forward, because other modules may
refer to gio.Application as well.