Re: SpinButton: how to avoid calling signal handler when set_value()
On 11/02/2016 05:19 PM, pozzugno wrote: > It seems pyGObject implementation gives only two "handler block" > functions: handler_block(), that needs the handler_id that I don't have; > handler_block_by_func() that needs the callback to block (the same > problem of your solution, because I have different callbacks). Usually when you connect a signal, the return value from the connect call is the handler_id. Can you save this value somewhere for future use? ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: SpinButton: how to avoid calling signal handler when set_value()
Il 02/11/2016 18:55, Nicola Fontana ha scritto: Il Wed, 2 Nov 2016 14:40:58 +0100 Pozz Pozzscrisse: 2016-11-02 11:24 GMT+01:00 Nicola Fontana : ... you don't necessarily need the handler id. In C (I don't use python) you could write the following: void my_set_value(GtkSpinButton *spin_button, gdouble value) { g_signal_handlers_block_matched(spin_button, G_SIGNAL_MATCH_FUNC, 0, 0, NULL, callback_to_skip, NULL); /* This will not trigger callback_to_skip */ gtk_spin_button_set_value(spin_button, value) g_signal_handlers_unblock_matched(spin_button, G_SIGNAL_MATCH_FUNC, 0, 0, NULL, callback_to_skip, NULL); } I got the idea. I don't know if g_signal_handlers_block_matched() or similar functionality is available in Python. However, remaining in C, your code make the assumption there is a single callback function for all the spinbuttons. This is not true: I have a different handler for each spinbutton, because I have to make different things. Sorry but I am a developer, not a mind reader. Yes, of course :-) Thank you for spending some time for me. I thought using a different callback for each SpinButton was the more typical solution. You can match by data or try to lookup the callback by detail with g_signal_handler_find or refactor your code to use a single callback. It seems pyGObject implementation gives only two "handler block" functions: handler_block(), that needs the handler_id that I don't have; handler_block_by_func() that needs the callback to block (the same problem of your solution, because I have different callbacks). Is it possible to retrieve the list of connected callbacks of an object and a signal name ("value-changed")? The fact that you are using different callbacks has a foul smell indeed. Yes? I have to generate and send a different request to the device. Why do you think it's better to have a single callback? Of course, I could write one single callback as: def callback(self, spinbutton): if spinbutton is spinSetting1: self.callback_setting1(spinbutton) elif spinbutton is spinSetting2: self.callback_setting2(spinbutton) ... def callback_setting1(self,spinbutton): # This is the callback of the spinbutton associated to setting1 parameter set_setting1(spinbutton.get_value()) It seems to me a more complicated way to write different callbacks. IMHO the solution to use a refreshing flag is the simplest solution, even if a little dirty. Alternatively, I have to create a list of spinbuttons *and* callbacks and search for the callback to unblock in your suggested function my_set_value(). Come on, a little bit of initiative. Here, today only, the link to the official (C) documentation: https://developer.gnome.org/gobject/stable/gobject-Signals.html Please, don't think I don't use to read documentation. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: SpinButton: how to avoid calling signal handler when set_value()
Il Wed, 2 Nov 2016 14:40:58 +0100 Pozz Pozzscrisse: > 2016-11-02 11:24 GMT+01:00 Nicola Fontana : > > ... > > > > you don't necessarily need the handler id. In C (I don't use > > python) you could write the following: > > > > void my_set_value(GtkSpinButton *spin_button, gdouble value) > > { > > g_signal_handlers_block_matched(spin_button, > > G_SIGNAL_MATCH_FUNC, > > 0, 0, NULL, > > callback_to_skip, > > NULL); > > > > /* This will not trigger callback_to_skip */ > > gtk_spin_button_set_value(spin_button, value) > > > > g_signal_handlers_unblock_matched(spin_button, > > G_SIGNAL_MATCH_FUNC, > > 0, 0, NULL, > > callback_to_skip, > > NULL); > > } > > > > I got the idea. I don't know if g_signal_handlers_block_matched() or > similar functionality is available in Python. However, remaining in C, your > code make the assumption there is a single callback function for all the > spinbuttons. This is not true: I have a different handler for each > spinbutton, because I have to make different things. Sorry but I am a developer, not a mind reader. You can match by data or try to lookup the callback by detail with g_signal_handler_find or refactor your code to use a single callback. The fact that you are using different callbacks has a foul smell indeed. Come on, a little bit of initiative. Here, today only, the link to the official (C) documentation: https://developer.gnome.org/gobject/stable/gobject-Signals.html Ciao. -- Nicola ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: SpinButton: how to avoid calling signal handler when set_value()
Il Wed, 2 Nov 2016 10:23:44 +0100 Pozz Pozzscrisse: > ... > How do you implement the generic function _my_set_value()? It should have > two parameters: spinbutton and value. signal_handler_block() function needs > the handler_id associated that I don't have. > Maybe during initialization, when I connected the handlers, I could create > a data structure (a list) with spinbuttons and associated handler_id. In > this way, _my_set_value() could accept the item of the list and could > recover the handler_id to block. > > However there is another problem with this approach. I'm using Glade and I > connect *all* the handlers with a single instruction: > builder.connect_signals(). So I don't have the handler IDs. > ... Hi, you don't necessarily need the handler id. In C (I don't use python) you could write the following: void my_set_value(GtkSpinButton *spin_button, gdouble value) { g_signal_handlers_block_matched(spin_button, G_SIGNAL_MATCH_FUNC, 0, 0, NULL, callback_to_skip, NULL); /* This will not trigger callback_to_skip */ gtk_spin_button_set_value(spin_button, value) g_signal_handlers_unblock_matched(spin_button, G_SIGNAL_MATCH_FUNC, 0, 0, NULL, callback_to_skip, NULL); } Not tested, but should give you the idea. Ciao. -- Nicola ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: SpinButton: how to avoid calling signal handler when set_value()
Il Wed, 2 Nov 2016 00:09:29 +0100 pozzugnoscrisse: > ... > A simple and clear sequence of instructions: > >_set_value() >_set_value() >.. > > will be transformed in a complex, long and cryptic sequence of > instructions: > >_block() >_set_value() >_unblock() >_block() >_set_value() >_unblock() Hi, I hope you are missing some fundamental detail because this is a non-problem. _my_set_value() _block() _set_value() _unblock _my_set_value() _my_set_value() > I hoped there was another better solution. Actually I'm using a flag > that is checked in the handler: > >refreshing = True >_set_value() >_set_value() >... >refreshing = False This is not equivalent to what you wrote above. This is (roughly) equivalent to: _block() _set_value() _set_value() ... _unblock() A minimal test case exposing the problem would be much clearer. Ciao. -- Nicola ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list