Suppress GTK signal when callback is triggered via code

Gist

handler_block is useful in each case, but I would rather call at the beginning of the program to suppress the signal for all calls to gtk_entry_set_text and gtk_toggle_button_set_active. Is there any way?


Background Information :

My program is used to create entities through the symbol creator dialog with the following attributes:

Name - selected from a predefined list via GTKComboBoxes
Animation - also GTKComboBox
Group - one of six switches that classify an object

Objects can be added - one starts with an empty add dialog, fills in all the fields and sends.
Objects can be edited in the "Edit" dialog box, where all the fields listed above are initially filled with the current attributes of the object. Editing takes place instantly (without the "Submit" button in the "Edit" dialog box), and the displayed "Entity" will be different as soon as a new value is selected from combos or switches.

I have a callback connected to a type record and triggered by a โ€œmodifiedโ€ signal. The callback seems to fire whenever I set the input text manually in code to show the editable object:

 gtk_entry_set_text(GTK_ENTRY(name_entry), entity.name); // name is a char* gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (group_button_friendly), TRUE); 

Yes, there is a way with g_signal_handler_block , but this requires

1) get the gulong , which is created when the signal is first connected. g_signal_connect(args); against gulong entry_handler_id = g_signal_connect(args);

2) Use block / unlock idioms for each individual call.
g_signal_handler_block(args, entry_handler_id);
gtk_entry_set_text(args);
g_signal_handler_unblock(args, entry_handler_id);
or, worse,
g_signal_handler_block(args, entry_handler_id);
fn_that_calls_gtk_entry_set_text();
g_signal_handler_unblock(args, entry_handler_id);

+4
source share
1 answer

I think you are looking for g_signal_handlers_block_matched . If you set the mask to only G_SIGNAL_MATCH_CLOSURE with the closure used in the signal, it should do the trick.

You will need to look for signal_id for the signal that is emitted, but you only need to do this once, since the signal identifier is the same between all widgets, so an instance is required in the call as well.

And to unlock, you want to use g_signal_handlers_unblock_matched .

+1
source

Source: https://habr.com/ru/post/1445576/


All Articles