?? example-2-with-libglade-connection.c
字號(hào):
/* This program displays a "pulsing" (or whatever it's called) * ProgressBar, adds a timeout function to keep it updated, shows how * to obtain an individual widget that libglade created, and also * manually sets up the callback for the delete_event on the main * window so that some data (a glib timer) can be attached to the * callback. * * Note that most programs update progress bars during some kind of * function that doesn't return to the main event loop (unlike this * simple example). In that case, you must manually tell gtk to * update widgets yourself by calling g_main_context_iteration. (See * example-3.c for an example of doing this in a different context). */#include <gtk/gtk.h>#include <glib.h>#include <glade/glade.h>/* This is the callback for the delete_event, i.e. window closing */voidinform_user_of_time_wasted (GtkWidget *widget, GdkEvent * event, gpointer data){ /* Get the elapsed time since the timer was started */ GTimer * timer = (GTimer*) data; gulong dumb_API_needs_this_variable; gdouble time_elapsed = g_timer_elapsed (timer, &dumb_API_needs_this_variable); /* Tell the user how much time they used */ printf ("You wasted %.2f seconds with this program.\n", time_elapsed); /* Free the memory from the timer */ g_timer_destroy (timer); /* Make the main event loop quit */ gtk_main_quit ();}gbooleanupdate_progress_bar (gpointer data){ gtk_progress_bar_pulse (GTK_PROGRESS_BAR (data)); /* Return true so the function will be called again; returning false removes * this timeout function. */ return TRUE;}intmain (int argc, char *argv[]){ GladeXML *what_a_waste; gtk_init (&argc, &argv); /* load the interface, but don't call glade_xml_signal_autoconnect * since we want to connect data to the callbacks--meaning that we * have to manually connect callbacks. */ what_a_waste = glade_xml_new ("example-2.glade", NULL, NULL); /* Get the progress bar widget and change it to "activity mode", i.e. a block * that bounces back and forth instead of a normal progress bar that fills * to completion. */ GtkWidget *progress_bar = glade_xml_get_widget (what_a_waste, "Progress Bar"); gtk_progress_bar_pulse (GTK_PROGRESS_BAR (progress_bar)); /* Add a timeout to update the progress bar every 100 milliseconds or so */ gint func_ref = g_timeout_add (100, update_progress_bar, progress_bar); /* Start the wasted_time_tracker timer, and connect it to the callback */ GTimer *wasted_time_tracker = g_timer_new (); glade_xml_signal_connect_data (what_a_waste, "inform_user_of_time_wasted", G_CALLBACK (inform_user_of_time_wasted), wasted_time_tracker); /* start the event loop */ gtk_main (); /* Remove the timeout function--not that it matters since we're about to end */ g_source_remove (func_ref); return 0;}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -