Re: Blocking signals



On Thu, 24 Feb 2005, Prewitt,  Nathan C ERDC-ITL-MS Contractor wrote:


    I would like to write a generic routine that will set the value of a
GtkHScale, for example, without it triggering a signal.  I have used
g_signal_handlers_block_by_func() before, but that requires that I know the
function name.  If the routine is generic, I would have a pointer to the
GtkHScale but I don't know exactly which one it is.  Therefore, I don't know
the name of the specific signal handler to block.  So, is there a function
that I can call that will block all signals from being emitted by a widget
while I change the value?


You can attach the unique signal ID to you GtkHScale widgets (I've done
this with buttons and option menus):

        sigid = g_signal_connect (G_OBJECT (button), "toggled",
                                  G_CALLBACK (rig_gui_buttons_ptt_cb),
                                  NULL);

        g_object_set_data (G_OBJECT (button),
                           HANDLER_ID_KEY,
                           GINT_TO_POINTER (sigid));

and then block the signal using this ID:

        sigid = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button), 
                                HANDLER_ID_KEY));

        g_signal_handler_block (G_OBJECT (button), sigid);

        /* ... update widget ... */             

        g_signal_handler_unblock (G_OBJECT (button), sigid);


HANDLER_ID_KEY is just a string.


Thanks,

Nathan


Alex





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