gotk4 icon indicating copy to clipboard operation
gotk4 copied to clipboard

How to connect signals with builder?

Open webracer999 opened this issue 2 years ago • 5 comments

Hi,

thank you for your perfect work! I'm trying to migrate from gotk3 to gotk4.

I don't find a way how to connect signals with builder. Like https://github.com/gotk3/gotk3-examples/blob/master/gtk-examples/glade/glade.go I used in gotk3

builder.ConnectSignals(signals)

The migrating guide https://docs.gtk.org/gtk4/migrating-3to4.html#adapt-to-gtkbuilder-api-changes says "gtk_builder_connect_signals() no longer exists. Instead, signals are always connected automatically.". Can you tell me how this works with this package?

webracer999 avatar Dec 18 '21 12:12 webracer999

I'm not sure; I'm not very familiar with the Builder API. Perhaps you'd want to grab each object and attach a signal to them manually?

There is an internal mechanism to allow storing Go data inside any GObject, which can be useful here, but it's not exposed at the moment. If that eases using Builder, I can consider exposing it for the user.

diamondburned avatar Dec 18 '21 20:12 diamondburned

Yes, manual connecting works.

Like

obj := builder.GetObject("about_button")
obj.Connect("clicked", onAboutButtonClicked)

But it's not as nice as if I can see the handler in the xml file.

I found something about this topic in gnome forum: https://discourse.gnome.org/t/gtk-4-how-to-replace-gtk-builder-connect-signals/3561/3 It says that the language binding needs to implement GtkBuilderScope interface in an ancillary object. (And also some detailed info.) Does that mean anything to you?

webracer999 avatar Dec 19 '21 14:12 webracer999

gotk4 doesn't have the right code to create custom objects that implement GLib interfaces yet, so that won't work.

GLib interfaces are horribly painful to implement without the caked-up C macro monstrosity, so it might take me at least half a year of fiddling around before I can even get a working prototype.

diamondburned avatar Dec 19 '21 22:12 diamondburned

OK I understand, it's a lot of work. So it's out of scope now - it's ok!

Thank you for checking!

webracer999 avatar Dec 20 '21 14:12 webracer999

I'm reposting this comment that I accidentally made on gotk3/gotk3, thinking it's gotk4:

This seems valid. If you ever want to PR this directly into the library, you can open one for adding a new function NewSignal in pkg/core/glib.

diamondburned avatar Dec 25 '21 07:12 diamondburned