1

I'm trying to add callback functions to a Gtk.Builder using Gtk.Builder.add_callback_symbol. I tried to pass a python function to it, but that does not work. Documentation says I need to pass a GObject.Callback instead, so I tried to cast one by calling GObject.Callback(myfunc) but got a NotImplementedError. The C-Documentation on GCallback says I need to use something called G_CALLBACK to typecast. But there does not seem to be any reference to this in PyGObject and I'm lost at that point.

I would like to say beforehand, that I know callback can be also added by using 'Gtk.Builder.connect_signals', but that's not the question here.

Bachsau
  • 1,213
  • 14
  • 21
  • It's quite strange to say thin on SO, but: your code works for me: https://imgur.com/a/PUpzT Maybe you should clean python cache? – Alexander Dmitriev Mar 27 '18 at 22:01
  • I'm on Debian 8. Gtk 3.14 (I had to fix that in glade file), python 3.4.2. Everything is ok when I click buttons, I see popups. Btw, it's impossible to launch 2 instances of app – Alexander Dmitriev Mar 29 '18 at 06:13
  • @AlexanderDmitriev Thank you very much for your feedback. I'll try to figure out what's going wrong on my side. It is intended, that you can't run two or more instances. You could on v0.1.0 but now I'm in the process of implementing management of multiple files. Currently every new instance will immediately quit, but the first instance should react to the event by raising its window and printing a message to `stderr`. – Bachsau Mar 29 '18 at 13:00

1 Answers1

1

The GObject.Callback function is just there for documentation purposes atm. You can just pass a function matching the signature of the callback type, in this case a function which doesn't take any arguments and has no return value.

lazka
  • 683
  • 6
  • 7
  • Well, that's what I tried first, but as I wrote, it had no effect. – Bachsau Mar 28 '18 at 18:01
  • Until today I have not figured out, what was going wrong, but I decided to go on with passing a dictionary to `connect_signals` anyway, as it seems cleaner than calling one function ever again while providing the same level of abstraction. – Bachsau Dec 14 '18 at 02:18