c - Print variable in GTK+ assistant -
i want ask user in gtk+ assistant name, save name in global variable , use variable in same assistant on different site. problem assistant completly created , changes on new sites have no effect.
example: initialisize global variable "name" "empty". now, assistant create sites displays first site. user writes down name in "entryfield" , variable "name" contains name. assistant displays second site should contain users name, displays string "empty".
i need "refresh" created entry new variable. sorry bad english, hope can explain problem little bit. :)
complete sample code:
#include <gtk/gtk.h> #include <string.h> static void entry_changed (gtkeditable*, gtkassistant*); static void assistant_cancel (gtkassistant*, gpointer); static void assistant_close (gtkassistant*, gpointer); char *name = "empty"; typedef struct { gtkwidget *widget; gint index; const gchar *title; gtkassistantpagetype type; gboolean complete; } pageinfo; int main (int argc, char *argv[]) { gtkwidget *assistant, *entry, *label; guint i; pageinfo page[5] = { { null, -1, "introduction", gtk_assistant_page_intro, true}, { null, -1, null, gtk_assistant_page_content, false}, { null, -1, null, gtk_assistant_page_content, true}, { null, -1, "confirmation", gtk_assistant_page_confirm, true}, }; gtk_init (&argc, &argv); /* create new assistant widget no pages. */ assistant = gtk_assistant_new (); gtk_widget_set_size_request (assistant, 450, 300); gtk_window_set_title (gtk_window (assistant), "gtkassistant example"); g_signal_connect (g_object (assistant), "destroy", g_callback (gtk_main_quit), null); page[0].widget = gtk_label_new ("this example of gtkassistant. by\n"\ "clicking forward button, can continue\n"\ "to next section!"); page[1].widget = gtk_hbox_new (false, 5); page[2].widget = gtk_entry_new(); page[3].widget = gtk_label_new ("finish!"); /* create necessary widgets second page. */ label = gtk_label_new ("your name: "); entry = gtk_entry_new (); gtk_box_pack_start (gtk_box (page[1].widget), label, false, false, 5); gtk_box_pack_start (gtk_box (page[1].widget), entry, false, false, 5); gtk_entry_set_text(gtk_entry(page[2].widget), name); /* add 4 pages gtkassistant dialog. */ (i = 0; < 4; i++) { page[i].index = gtk_assistant_append_page (gtk_assistant (assistant), page[i].widget); gtk_assistant_set_page_title (gtk_assistant (assistant), page[i].widget, page[i].title); gtk_assistant_set_page_type (gtk_assistant (assistant), page[i].widget, page[i].type); /* set introduction , conclusion pages complete can * incremented or closed. */ gtk_assistant_set_page_complete (gtk_assistant (assistant), page[i].widget, page[i].complete); } /* update whether pages 2 through 4 complete based upon whether there * text in gtkentry, check button active, or progress bar * filled. */ g_signal_connect (g_object (entry), "changed", g_callback (entry_changed), (gpointer) assistant); g_signal_connect (g_object (assistant), "cancel", g_callback (assistant_cancel), null); g_signal_connect (g_object (assistant), "close", g_callback (assistant_close), null); gtk_widget_show_all (assistant); gtk_main (); return 0; } /* if there text in gtkentry, set page complete. otherwise, * stop user progressing next page. */ static void entry_changed (gtkeditable *entry, gtkassistant *assistant) { const gchar *text = gtk_entry_get_text (gtk_entry (entry)); gint num = gtk_assistant_get_current_page (assistant); gtkwidget *page = gtk_assistant_get_nth_page (assistant, num); gtk_assistant_set_page_complete (assistant, page, (strlen (text) > 0)); name = g_strdup(gtk_entry_get_text(gtk_entry(entry))); } /* if dialog cancelled, delete memory , clean after * assistant structure. */ static void assistant_cancel (gtkassistant *assistant, gpointer data) { gtk_widget_destroy (gtk_widget (assistant)); } /* function apply changes , destroy assistant. */ static void assistant_close (gtkassistant *assistant, gpointer data) { g_print ("you apply changes now!\n"); gtk_widget_destroy (gtk_widget (assistant)); }
in entry_changed
, have call gtk_entry_set_text(gtk_entry(page[2].widget), name);
again, set entry text once, thing matters. otherwise default value set when setting 3rd page sticks.
Comments
Post a Comment