Re: button to update graph when pressed



Hi Salvador,

Something is not ok with your example, because in your example plotbox is a local variable that is left uninitialized. What you want to do is to pass a pointer to plotbox to the callback function, which may be done in a number of ways. One is to use the third parameter of the callback function. Another option is to use g_object_set_data() to the button that you may then retrieve through g_object_get_data() and a third method is too use global variables.

Hope this helps.
Dov


2008/10/24 Salvador Aguinaga <salvador aguinaga gmail com>
I have a button that fails to update the graph on my main window, and does I figured I am doing something wrong.

Here is the error msg when I press the button:

SynchioButton I was clicked!
(harp_app_0:5279): GLib-GObject-WARNING **: invalid cast from `GtkDataboxLines' to `GtkDatabox'
** (harp_app_0:5279): CRITICAL **: gtk_databox_graph_add: assertion `GTK_IS_DATABOX (box)' failed
(harp_app_0:5279): GLib-GObject-WARNING **: invalid cast from `GtkDataboxLines' to `GtkDatabox'
** (harp_app_0:5279): CRITICAL **: gtk_databox_calculate_extrema: assertion `GTK_IS_DATABOX (box)' failed
(harp_app_0:5279): Gtk-CRITICAL **: gtk_widget_show: assertion `GTK_IS_WIDGET (widget)' failed


The call in the interface.c file  is like this: 

/* SYNCH IO BUTTON CALLBACK */

g_signal_connect (G_OBJECT (synchioButton), "clicked"

         G_CALLBACK (button_clicked), (gpointer) window1);

 The callbacks.c file has the following code, any help on figuring how how to fix this will be greatly appreciated. :
void
button_clicked (GtkButton *synchioButton,
GtkWindow *window1)
{
//GtkWidget *dialog, *label, *image, *hbox;
GtkWidget *plotbox;
GtkWidget *gtk_databox_new (void);
GtkDataboxGraph *graph; 

GdkColor color;
gfloat *X, *Y;
gint i;

g_print("SynchioButton I was clicked!\n");

X = g_new0 (gfloat, POINTS);   // WILL PROBABLY HAVE TO GET RID OF THIS 
Y = g_new0 (gfloat, POINTS); 
for (i = 1 ; i < POINTS + 1; i ++) { X [i] = i; Y [i] = log10 (i); } 

color.red   = 15535;
color.green = 15535;
color.blue  = 15535;  

graph = gtk_databox_lines_new (POINTS, X, Y, &color, 1); 
    gtk_databox_graph_add (GTK_DATABOX (plotbox), graph); 
gtk_databox_auto_rescale (GTK_DATABOX (plotbox), 0.05);
gtk_widget_show (plotbox);
}


_______________________________________________
gtk-list mailing list
gtk-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-list




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