Re: SpinButton: how to avoid calling signal handler when set_value()
- From: pozzugno <pozzugno gmail com>
- To: gtk-app-devel-list gnome org
- Subject: Re: SpinButton: how to avoid calling signal handler when set_value()
- Date: Thu, 3 Nov 2016 00:19:41 +0100
Il 02/11/2016 18:55, Nicola Fontana ha scritto:
Il Wed, 2 Nov 2016 14:40:58 +0100 Pozz Pozz <pozzugno gmail com> scrisse:
2016-11-02 11:24 GMT+01:00 Nicola Fontana <ntd entidi it>:
...
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.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]