Re: SpinButton: how to avoid calling signal handler when set_value()



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.

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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]