Reputation: 149
Gist:
handler_block
is useful on a case-by-case basis, but I'd rather call something at the beginning of the program to suppress a signal for all calls to gtk_entry_set_text
and gtk_toggle_button_set_active. Is there a way?
Background Info:
My program is used to make Entities via a character creator dialog box with the following attributes:
Name - chosen from a predetermined list via GTKComboBoxes
Animation - also a GTKComboBox
Group - one of six radio buttons classifying the entity
Entities can be added - one starts with a blank Add dialog, fills in all fields, and submits.
Entities can be edited via the Edit dialog, where all the fields listed above are initially filled in with the entity's current attributes. The edits are instantaneous (no Submit button on the Edit dialog) and the displayed Entity will appear different as soon as the new value from the combo or radio buttons is selected.
I have a callback connected to the Type entry and triggered by the "changed" signal. The callback seems to trigger whenever I set the entry text manually in code to show the entity being edited:
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);
Yeah, there is a way with g_signal_handler_block
, but that requires
1) getting the gulong
that is created when you connect the signal in the first place.
g_signal_connect(args);
vs.
gulong entry_handler_id = g_signal_connect(args);
2) Using the block/unblock idiom for every single 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);
Upvotes: 4
Views: 1461
Reputation: 760
I think what you're looking for is g_signal_handlers_block_matched
. If you set the mask to just G_SIGNAL_MATCH_CLOSURE
with the closure used in the signal it should do the trick.
You'll have to look up the signal_id
for the signal that is being emitted, but you should only need to do that once since the signal id is the same between all widgets, which is why the instance is required in the call as well.
And to unblock you want to use g_signal_handlers_unblock_matched
.
Upvotes: 1