Re: cancelling/aborting an emitted signal
- From: Luciano Chavez <lnx1138 us ibm com>
- To: Paul Davis <pbd op net>
- Cc: gtk-list gnome org
- Subject: Re: cancelling/aborting an emitted signal
- Date: 01 Mar 2002 11:30:41 -0600
On Tue, 2002-02-26 at 19:03, Paul Davis wrote:
> >Hello,
> >
> >Can someone suggest the proper generic way to abort a signal from
> >actually causing the default handler to change the widget value. Must I
> >connect the signal handler in a certain order?
> >
> >For example, in a "toggled" signal handler for a toggle button if some
> >condition is true then I want the "toggled" signal to be canceled so the
> >widget does not signify the change (a checkmark displayed or removed).
> >I've tried the following but get a Gtk Warning indicating there is to no
> >emitted signal to stop:
> >
> >gtk_signal_emit_stop_by_name (GTK_OBJECT (button), "toggled");
>
> catch the button_press_event and you'll probably find that you're in
> better shape. also, check and double check that you're calling it on
> the correct widget - i've sometimes done cut-n-paste ops that have led
> to that error message.
>
> >Again, I want to know the generic method to cancel a signal within a
> >signal handler so the widget does not reflect the change. This applies
> >to GtkAdjustment value changes (for GtkHScale and GtkSpinButton
> >changes), GtkCList row selection and unselection, and others.
>
> i do this a LOT in my code, and i always use
> gtk_signal_emit_stop_by_name(), but i always catch the underlying
> events (button press/release etc.), not the "translations" like
> clicked/selected/activate and so forth.
>
> you also need to still return TRUE, sometimes.
>
> --p
Paul,
Sorry, for the delayed question but I was on holiday this week.
So if I understand correctly, I shouldn't connect a signal handler to
something like "toggled" but something like "button_press_event" and
check whether it is button 1 that was clicked?
My original code looks like this:
void on_option_check_button_toggled (GtkToggleButton *button,
option_widget_info_t *info)
{
gint rc;
value_t value;
gboolean value_changed;
log_entry;
value.bool = gtk_toggle_button_get_active (button);
rc = set_widget_option_value (info, &value, &value_changed);
if (rc == SUCCESS)
{
if (value_changed)
{
gtk_signal_handler_block_by_func (GTK_OBJECT (button),
on_option_check_button_toggled, info);
gtk_toggle_button_set_active (button, value.bool);
gtk_signal_handler_unblock_by_func (GTK_OBJECT (button),
on_option_check_button_toggled, info);
}
else
info->value.bool = value.bool;
}
else
{
gtk_signal_emit_stop_by_name (GTK_OBJECT (button), "toggled");
}
log_exit;
}
Do you know a) will the gtk_toggle_button_get_active() still work as
expected in the new handler and b) will calling
gtk_signal_emit_stop_by_name for the "button_press_event" actually
cancel the signal and revert the toggle button to its original state?
Also, do I have to setup identical signal handlers for using the
keyboard, i.e. "key_press_event" since I am not using the
"translations"?
Is this really going to do what I want which is undo the event and
revert to original state?
--
regards,
Luciano Chavez
lnx1138 us ibm com
http://sf.net/projects/evms
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]