How to avoid recursion on a entry validator

Hi, I’m trying to achieve something similar to this:

but this code is in python and I’m using javascript.

I’m interested in block/unblock signal emission when I programmatically add text to the entry.
In python it suggest to use entry.handler_block_by_func

but it seem that in GJS there’s not this function or similar. The only one that I can get is GObject.signal_handler_block() but then I need to have the handler_id, and I don’t know how to get it (I use Glade to connect signals/handlers)

This does seem to be an omission in GJS. We should probably have an override for it. Could you please open a feature request issue on GNOME / gjs · GitLab?

You might be able to retrieve the handler ID with GObject.signal_handler_find() although it looks like searching by function doesn’t work in GJS, so you could only use it if you were certain there would be no other signal handlers connected to that signal, e.g. on an internal object:

gjs> const {GObject} = imports.gi;
gjs> const o = new GObject.Object()
gjs> function foo() {}
gjs> o.connect('notify', foo)
14
gjs> function bar() {}
gjs> o.connect('notify', bar)
15
gjs> GObject.signal_handler_find(o, GObject.SignalMatchType.ID, GObject.signal_lookup('notify', GObject.Object), 0, foo, null, null)
14
gjs> GObject.signal_handler_find(o, GObject.SignalMatchType.ID, GObject.signal_lookup('notify', GObject.Object), 0, bar, null, null)
14
gjs> GObject.signal_handler_find(o, GObject.SignalMatchType.ID | GObject.SignalMatchType.CLOSURE, GObject.signal_lookup('notify', GObject.Object), 0, foo, null, null)
0
gjs> GObject.signal_handler_find(o, GObject.SignalMatchType.ID | GObject.SignalMatchType.CLOSURE, GObject.signal_lookup('notify', GObject.Object), 0, bar, null, null)
0
gjs> GObject.signal_handler_find(o, GObject.SignalMatchType.ID | GObject.SignalMatchType.FUNC, GObject.signal_lookup('notify', GObject.Object), 0, null, foo, null)
0
gjs> GObject.signal_handler_find(o, GObject.SignalMatchType.ID | GObject.SignalMatchType.FUNC, GObject.signal_lookup('notify', GObject.Object), 0, null, bar, null)
0

done: GObject: Add override for GObject.handler_block_by_func (#290) · Issues · GNOME / gjs · GitLab
thanks for your help

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.