StefanSalewski / gintro

High level GObject-Introspection based GTK3/GTK4 bindings for Nim language
MIT License
298 stars 20 forks source link

Error: Invalid node kind nnkCall for macros.`$` #184

Closed ITwrx closed 3 years ago

ITwrx commented 3 years ago

I very well may be doing something dumb. I'm just trying to figure out how to modify my gui when a button is pressed, but through my crapulence maybe i've stumbled upon a gintro bug?

var home_box = newBox(gtk4.Orientation.horizontal)
var home_chooser_btn = newButtonFromIconName("folder-open")

proc home_chooser_btnCb(home_box: Box, home_chooser_btn: Button) =
    home_box.remove(home_chooser_btn)
    let notify_label = newLabel("home chooser box and button are gone!")
    home_box.append(notify_label)
    echo "home chooser clicked"

#error triggered by next line
home_chooser_btn.connect("clicked", home_chooser_btnCb(home_box, home_chooser_btn))

results in:

nim c -r EZMP.nim --gc:orc
Hint: used config file '/home/itwrx/.choosenim/toolchains/nim-1.4.8/config/nim.cfg' [Conf]
Hint: used config file '/home/itwrx/.choosenim/toolchains/nim-1.4.8/config/config.nims' [Conf]
..............................
stack trace: (most recent call last)
/home/itwrx/.nimble/pkgs/gintro-0.9.5/gintro/gimplgobj.nim(236, 37) mconnect
/home/itwrx/.choosenim/toolchains/nim-1.4.8/lib/core/macros.nim(1281, 5) $
/home/itwrx/moarpath/EZMP.nim(44, 57) Error: Invalid node kind nnkCall for macros.`$`

thanks

ITwrx commented 3 years ago

@#%^ i see now that the gintro readme (!) has an example of how to pass variables as parameters to callbacks. Looking at that now. I hope my bug report is valid.

StefanSalewski commented 3 years ago

nim c -r EZMP.nim --gc:orc

Sometimes I really hate the "r" or "c -r" options of the Nim compiler. The may be OK for general use, but in case of bugs it is helpful to know exactly if it is a compiletime or runtime issue.

And please try --gc:refc and --gc:arc also.

ITwrx commented 3 years ago

it's a compile time error.

StefanSalewski commented 3 years ago

This is invalid code:

home_chooser_btn.connect("clicked", home_chooser_btnCb(home_box, home_chooser_btn))

I am not sure what you intend, but you pass a proc call as last argument, while last argument should be justb the proc/callback name, e.g. like

home_chooser_btn.connect("clicked", home_chooser_btnCb) # or with optional ref object parameter
home_chooser_btn.connect("clicked", home_chooser_btnCb, myRefObjOrwidgetOrIntAndSuch)
ITwrx commented 3 years ago

right, i understand that now, but i still didn't know if it was exposing a gintro bug anyways. i'll close now. sorry for all the noise. Thanks again.

StefanSalewski commented 3 years ago

Maybe this was intented:

import gintro/[gtk4, gdk4, glib, gio, gobject]

var home_box = newBox(gtk4.Orientation.horizontal)
var home_chooser_btn = newButtonFromIconName("folder-open")

proc home_chooser_btnCb(home_chooser_btn: Button; home_box: Box) =
    #home_box.remove(home_chooser_btn)
    #let notify_label = newLabel("home chooser box and button are gone!")
    #home_box.append(notify_label)
    echo "home chooser clicked"

#error triggered by next line
home_chooser_btn.connect("clicked", home_chooser_btnCb, home_box)
StefanSalewski commented 3 years ago

if it was exposing a gintro bug anyways.

We can always try to improve the connect macro to catch invalid calls better. But in real life it is not a real issue, as when you have learned Nim and gintro for a few weeks, you just generally do it right.

Rewriting all the gintro macros is indeed on the to do list, I was hoping all the years that maybe someone of the Nim experts would do it, instead sitting the whole day in from of the Nim IRC. But now Araq and a few other Nim devs seems to favour the fidget GUI toolkit, so I have not much hope. When we will have at least 100 really active gintro users I will do it myself, or hire someone to do it.

ITwrx commented 3 years ago

Rewriting all the gintro macros is indeed on the to do list, I was hoping all the years that maybe someone of the Nim experts would do it, instead sitting the whole day in from of the Nim IRC.

lol

But now Araq and a few other Nim devs seems to favour the fidget GUI toolkit, so I have not much hope.

Yeah, don't get me started on this whole topic. :)