Want more features on Pastebin? Sign Up, it's FREE!
Guest

assistant_problem.c

By: a guest on Dec 27th, 2011  |  syntax: C  |  size: 6.85 KB  |  views: 74  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.  
  2. #include <gtk/gtk.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5.  
  6. //##########################
  7. //  Pages functions & var  #
  8. //##########################
  9. static GtkWidget *assistant = NULL;
  10. static GtkWidget *progress_bar = NULL;
  11.  
  12. static gboolean apply_changes_gradually (gpointer data) {
  13.         gdouble fraction;
  14.  
  15.         /* Work, work, work... */
  16.         fraction = gtk_progress_bar_get_fraction (GTK_PROGRESS_BAR (progress_bar));
  17.         fraction += 0.05;
  18.  
  19.         if (fraction < 1.0) {
  20.                 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), fraction);
  21.                 return TRUE;
  22.         }
  23.         else {
  24.         /* Close automatically once changes are fully applied. */
  25.                 g_print ("Exiting\n");
  26.                 gtk_main_quit ();
  27.                 assistant = NULL;
  28.                 return FALSE;
  29.         }
  30. }
  31.  
  32. static void on_assistant_apply (GtkWidget *widget, gpointer data) {
  33.         /* Start a timer to simulate changes taking a few seconds to apply. */
  34.         g_timeout_add (100, apply_changes_gradually, NULL);
  35. }
  36.  
  37. static void on_assistant_close_cancel (GtkWidget *widget, gpointer data) {
  38.         GtkWidget **assistant = (GtkWidget **) data;
  39.  
  40.         gtk_widget_destroy (*assistant);
  41.         *assistant = NULL;
  42. }
  43.  
  44. static void on_assistant_prepare (GtkWidget *widget, GtkWidget *page, gpointer data) {
  45.         gint current_page, n_pages;
  46.         gchar *title;
  47.  
  48.         current_page = gtk_assistant_get_current_page (GTK_ASSISTANT (widget));
  49.         n_pages = gtk_assistant_get_n_pages (GTK_ASSISTANT (widget));
  50.         g_print ("page :%d\n",current_page);
  51.         title = g_strdup_printf ("ShowBook client (%d/%d)", current_page + 1, n_pages);
  52.         gtk_window_set_title (GTK_WINDOW (widget), title);
  53.         g_free (title);
  54.  
  55.         /* The fourth page (counting from zero) is the progress page.  The
  56.         * user clicked Apply to get here so we tell the assistant to commit,
  57.         * which means the changes up to this point are permanent and cannot
  58.         * be cancelled or revisited. */
  59.         if (current_page == 4)
  60.                 gtk_assistant_commit (GTK_ASSISTANT (widget));
  61. }
  62.  
  63. static void on_entry_changed (GtkWidget *widget, gpointer data) {
  64.         GtkAssistant *assistant = GTK_ASSISTANT (data);
  65.         GtkWidget *current_page;
  66.         gint page_number;
  67.         const gchar *text;
  68.  
  69.         page_number = gtk_assistant_get_current_page (assistant);
  70.         current_page = gtk_assistant_get_nth_page (assistant, page_number);
  71.         text = gtk_entry_get_text (GTK_ENTRY (widget));
  72.  
  73.         if (text && *text)
  74.                 gtk_assistant_set_page_complete (assistant, current_page, TRUE);
  75.         else
  76.                 gtk_assistant_set_page_complete (assistant, current_page, FALSE);
  77. }
  78.  
  79. //######################
  80. //        Pages        #
  81. //######################
  82.  
  83. static void create_page1 (GtkWidget *assistant) {
  84.         GtkWidget *box, *label, *image, *current_page;
  85.        
  86.         box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
  87.         gtk_container_set_border_width (GTK_CONTAINER (box), 12);
  88.  
  89.         label = gtk_label_new ("Bienvenue dans l'assistant de réservation en ligne ShowBook.\n" "Cliquez sur le bouton en bas à droite pour continuer.");
  90.         //gtk_label_get_layout_offsets (GTK_LABEL(label), NULL, NULL);
  91.         gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
  92.  
  93.         image = gtk_image_new_from_file ("show.jpg");
  94.         gtk_box_pack_start (GTK_BOX (box), image, FALSE, FALSE, 0);
  95.  
  96.         gtk_widget_show_all (box);
  97.         gtk_assistant_append_page (GTK_ASSISTANT (assistant), box);
  98.         gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), box, "Bienvenue");
  99.         gtk_assistant_set_page_type (GTK_ASSISTANT (assistant), box, GTK_ASSISTANT_PAGE_INTRO);
  100.        
  101.         gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), box, TRUE);
  102. }
  103.  
  104.  
  105. static void create_page2 (GtkWidget *assistant) {
  106. GtkWidget *box, *label, *image, *current_page;
  107.        
  108.         box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
  109.         gtk_container_set_border_width (GTK_CONTAINER (box), 12);
  110.  
  111.         label = gtk_label_new ("Nom du spectacle");
  112.         //gtk_label_get_layout_offsets (GTK_LABEL(label), NULL, NULL);
  113.         gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
  114.  
  115.         image = gtk_image_new_from_file ("title.jpg");
  116.         gtk_box_pack_start (GTK_BOX (box), image, FALSE, FALSE, 0);
  117.  
  118.         gtk_widget_show_all (box);
  119.         gtk_assistant_append_page (GTK_ASSISTANT (assistant), box);
  120.         gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), box, "Choix");
  121.         gtk_assistant_set_page_type (GTK_ASSISTANT (assistant), box, GTK_ASSISTANT_PAGE_INTRO);
  122.        
  123.         current_page = gtk_assistant_get_nth_page (GTK_ASSISTANT (assistant), 0);
  124.         gtk_assistant_set_page_complete (GTK_ASSISTANT(assistant), current_page, TRUE);
  125. }
  126.  
  127. static void create_page3 (GtkWidget *assistant) {
  128.         GtkWidget *label;
  129.  
  130.         label = gtk_label_new ("This is a confirmation page, press 'Apply' to apply changes");
  131.  
  132.         gtk_widget_show (label);
  133.         gtk_assistant_append_page (GTK_ASSISTANT (assistant), label);
  134.         gtk_assistant_set_page_type (GTK_ASSISTANT (assistant), label, GTK_ASSISTANT_PAGE_CONFIRM);
  135.         gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), label, TRUE);
  136.         gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), label, "Confirmation");
  137. }
  138.  
  139.  
  140. //######################
  141. //  Window functions   #
  142. //######################
  143. static gboolean delete_event( GtkWidget *widget, GdkEvent *event, gpointer data )
  144. {
  145.     return FALSE;
  146. }
  147.  
  148. static void destroy( GtkWidget *widget, gpointer data )
  149. {
  150.     g_print ("Exiting\n");
  151.     gtk_main_quit ();
  152. }
  153.  
  154.  
  155. //######################
  156. //        Main         #
  157. //######################
  158. int main( int argc, char *argv[] ) {
  159.  
  160.         /* Declarations */
  161.         GtkWidget *window;
  162.         GtkWidget *mainbox;
  163.         GtkUIManager *ui;
  164.         GtkActionGroup *actions;
  165.         GError *error = NULL;
  166.  
  167.         gtk_init (&argc, &argv);
  168.    
  169.         /* Create a new window and set proprieties */
  170.         window = gtk_window_new (GTK_WINDOW_TOPLEVEL); 
  171.         assistant = gtk_assistant_new();
  172.         gtk_window_set_title (GTK_WINDOW(assistant), "ShowBook client");
  173.         gtk_window_set_default_size(GTK_WINDOW(assistant),800,600);
  174.        
  175.         gtk_window_set_screen (GTK_WINDOW (window),gtk_widget_get_screen (assistant));
  176.  
  177.         create_page1 (assistant);
  178.         create_page2 (assistant);
  179.         create_page3 (assistant);
  180.  
  181.  
  182.         /* Define the main window box */
  183. //      mainbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
  184. //      gtk_container_add (GTK_CONTAINER (assistant), mainbox);
  185.  
  186.  
  187.  
  188.         /* Define window signals */
  189.         g_signal_connect (assistant, "delete-event",G_CALLBACK (delete_event), NULL);
  190.         g_signal_connect (assistant, "destroy",G_CALLBACK (destroy), NULL);
  191.         g_signal_connect (G_OBJECT (assistant), "cancel",
  192.                         G_CALLBACK (on_assistant_close_cancel), &assistant);
  193.         g_signal_connect (G_OBJECT (assistant), "close",
  194.                         G_CALLBACK (on_assistant_close_cancel), &assistant);
  195.         g_signal_connect (G_OBJECT (assistant), "apply",
  196.                         G_CALLBACK (on_assistant_apply), NULL);
  197.         g_signal_connect (G_OBJECT (assistant), "prepare",
  198.                         G_CALLBACK (on_assistant_prepare), NULL);
  199.    
  200.         //gtk_container_set_border_width (GTK_CONTAINER (window), 10);
  201.    
  202.         /* Display the window */
  203.         gtk_widget_show_all (assistant);
  204.    
  205.         /* Launch gtk */
  206.         gtk_main ();
  207.  
  208.         //g_object_unref (ui);
  209.    
  210.         return 0;
  211. }
clone this paste RAW Paste Data