RE: stopping signals again



You should not use stop_emission, which only stop current signal loop.
You should use g_signal_handlers_block_by_func() before change your
value, after change value unblock it.





-----Original Message-----
From: gtk-app-devel-list-admin gnome org
[mailto:gtk-app-devel-list-admin gnome org] On Behalf Of dave walters
Sent: Saturday, November 22, 2003 11:29 AM
To: gtk-app-devel-list gnome org
Subject: stopping signals again

I'm trying to use g_signal_stop_emission but I can't get it to work
right. This simple program is just a spinbutton. If clicked
once up, the value jumps from 1 to 10, which is the max. It 
should only go up to 3 if the g_signal_stop_emission was done
right, or is working ok. Any ideas on this??
 
Thanks,
Walt
 
#include <gtk/gtk.h>

void set_val(GtkWidget *spin,gpointer data)
{
        gint a,k;
        k =(int)data;
        
        a=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spin));
        g_print("a before %d \n",a);
        
        
g_signal_stop_emission_by_name(GTK_SPIN_BUTTON(spin),"value_changed");
        gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin),(gdouble)(a+1));

        a=gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spin));
        g_print("a after %d \n",a);
}

int main( int   argc,
          char *argv[] )
{
  GtkWidget *window;
  GtkWidget *spin;
  GtkWidget *main_vbox;
  GtkWidget *vbox1;
  GtkWidget *button;
  GtkAdjustment *adj;

  /* Initialise GTK */
  gtk_init (&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

  g_signal_connect (G_OBJECT (window), "destroy",
                    G_CALLBACK (gtk_main_quit),
                    NULL);

  gtk_window_set_title (GTK_WINDOW (window), "Spin Button");

  main_vbox = gtk_vbox_new (FALSE, 5);
  gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 10);
  gtk_container_add (GTK_CONTAINER (window), main_vbox);
  

  
        vbox1 = gtk_vbox_new (TRUE, 0);
        gtk_box_pack_start (GTK_BOX (main_vbox), vbox1, FALSE, FALSE,
5);
        adj = (GtkAdjustment *) gtk_adjustment_new (1,
                        1, 10.0, 1.0, 5.0, 0.0);
        spin = gtk_spin_button_new(adj,0,0);
        g_signal_connect(G_OBJECT(spin),"value_changed",
                                G_CALLBACK(set_val),(gpointer) 1);
        gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(spin),TRUE);
        gtk_box_pack_start (GTK_BOX (vbox1), spin, TRUE, FALSE, 0);
  
  button = gtk_button_new_with_label ("Close");
  g_signal_connect_swapped (G_OBJECT (button), "clicked",
                            G_CALLBACK (gtk_widget_destroy),
                            window);
  gtk_box_pack_start (GTK_BOX (main_vbox), button, TRUE, TRUE, 5);

  gtk_widget_show_all (window);

  /* Enter the event loop */
  gtk_main ();
    
  return 0;
}


Do you Yahoo!?
Free Pop-Up Blocker - Get it now




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