|
Hey I am farely new at GTK, and have been trying to create a signal using gtk_signal_new(), I was just wondering if anybody had an example on the proper syntax for this function.
I have created a test program that is supposed to increment all of the values of the labels that i have in the window by pressing a button that runs the gtk_signal_emit_by_name(). I have created this button as a test becuase this function is actually going to be called from somewhere else in the actual program. I want this signal to run a callback routine that increments all the label(for testing purposes).
Here is what i have so far for the test program:
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include <pthread.h>
#include <gtk/gtk.h>
GtkWidget
*input_trigger;
gtk_signal_new("input-trigger",
GTK_RUN_NO_HOOKS|GTK_RUN_LAST,
GtkWidget,
0,
g_cclosure_marshal_VOID__VOID, G_TYPE_NONE,
NULL,
0);
int main(int argc,char *argv[])
{
gtk_init(&argc,&argv);
int
num[6],
numt[6]={0,0,0,0,0,0},
i;
GtkWidget
*window,
*label,
*table,
*button,
*button2;
GtkTooltips
*tip;
char labelstring[6][20];
gboolean delete_event(GtkWidget *widget,GdkEvent *event,gpointer data)
{
//gtk_loop=1;
gtk_main_quit();
return(FALSE);
}
void destroy(GtkWidget *widget,gpointer data)
{
gtk_widget_destroy(data);
}
void count_coin(GtkWidget *input_trigger,GdkEvent *event,gpointer data)
{
int i;
char labelstring[6][20];
printf("run 1\n");
for(i=0;i<6;i++)
{
num[i]=1;
numt[i]+=num[i];
}
//table=gtk_table_new(10,10,FALSE);
for(i=0;i<5;i++)
{
sprintf(labelstring[i],"times button #%d was pressed: %d",i,numt[i]);
gtk_label_set_text(GTK_LABEL(label),labelstring[i]);
}
printf("run 2\n");
gtk_signal_emit_stop_by_name(GTK_OBJECT (input_trigger),"input-trigger");
}
void button_test(GtkWidget *button2,GdkEvent *event,gpointer data)
{
gtk_signal_emit_by_name (GTK_OBJECT (input_trigger),"input-trigger");
}
window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window),(gchar *)"gtk_sim");
gtk_container_set_border_width(GTK_CONTAINER(window),80);
g_signal_connect(G_OBJECT(window),"delete_event",G_CALLBACK(delete_event),NULL);
table=gtk_table_new(10,10,FALSE);
gtk_container_add(GTK_CONTAINER(window),table);
gtk_table_set_row_spacings(GTK_TABLE(table),2);
gtk_table_set_col_spacings(GTK_TABLE(table),2);
label=gtk_label_new("number of times a button is pressed");
gtk_table_attach(GTK_TABLE(table),label,0,2,0,1,GTK_SHRINK,GTK_SHRINK,0,0);
gtk_widget_show(label);
for(i=0;i<6;i++)
{
sprintf(labelstring[i],"times button #%d was pressed: %d",i,numt[i]);
label=gtk_label_new(labelstring[i]);
gtk_table_attach(GTK_TABLE(table),label,0,2,i+1,i+2,GTK_SHRINK,GTK_SHRINK,0,0);
gtk_widget_show(label);
}
gtk_signal_connect(GTK_OBJECT(input_trigger),"key-press-event",G_CALLBACK(count_coin),NULL);
button=gtk_button_new_with_label("Quit");
g_signal_connect(G_OBJECT(button),"clicked",G_CALLBACK(delete_event),NULL);
button2=gtk_button_new_with_label("increment all");
g_signal_connect(G_OBJECT(button2),"clicked",G_CALLBACK(button_test),NULL);
tip=gtk_tooltips_new();
gtk_tooltips_set_tip(tip,button,"This will Quit the program",NULL);
gtk_table_attach(GTK_TABLE(table),button,0,2,8,10,GTK_SHRINK,GTK_SHRINK,0,0);
gtk_table_attach(GTK_TABLE(table),button2,0,2,8,11,GTK_SHRINK,GTK_SHRINK,0,0);
gtk_widget_show(button);
gtk_widget_show(button2);
gtk_widget_show (table);
gtk_widget_show (window);
//g_signal_emit_by_name(input_trigger,"button-press-event");
gtk_main();
return 0;
}
|