Just need to close a secondary window via a button.




This seems like it should be a breeze, but I am missing something.
Turning to the pros for assistance.

Just trying to whip up a quickie 'error dialog' function, that either

Displays an error with an OK button that closes the dialog, or
displays a fatal error with a QUIT button that shuts the whole prog down.

The fatal error stuff is working fine.
Simply closing the window isn't (via the OK button.)

Instead of the error dialog closing, the button itself is removed.

I've tried delete_event/destroy stuff, which works fine as a binding to the
window itself, but not when bound to the button.

Here's the code.  Even if I pass NULL to gtk_widget_delete, it does the
same thing.  There must be another way (a right way) to do this.  The
tutorial only gives one window examples as far I saw - help.  :)


-Mahlon



/* Spit out an error message to a Gtk dialogbox. */
/* Quit or continue, based on severity. */

#include <gtk/gtk.h>

void gerror(
            char err_message[], 
            int fatal
            ) 
{

  void destroy();
  gint delete_event();
  char buttontext[] = "   Quit   ";
  
  /* Create widgets */
  GtkWidget *errwindow, *errmessage, *errbutton;
  
  if (fatal == 0) {
    strcpy(buttontext, "   OK   ");
  }

  /* Create window using dialog shortcut */
  errwindow = gtk_dialog_new();
  gtk_window_set_title(GTK_WINDOW(errwindow), "error");
  gtk_window_set_modal(GTK_WINDOW(errwindow), TRUE);
  gtk_widget_set_usize(GTK_WIDGET(errwindow), 300, 100);
  gtk_window_set_position(GTK_WINDOW(errwindow), GTK_WIN_POS_CENTER);
  gtk_window_set_policy(GTK_WINDOW(errwindow), FALSE, FALSE, FALSE);
  gtk_signal_connect(GTK_OBJECT(errwindow), "delete_event",
                     GTK_SIGNAL_FUNC(delete_event), NULL);

  if (fatal == 1) {
    gtk_signal_connect(GTK_OBJECT(errwindow), "destroy",
                       GTK_SIGNAL_FUNC(destroy), NULL);
  }

  /* Place message */
  errmessage = gtk_label_new(err_message);
  gtk_box_pack_start(GTK_BOX (GTK_DIALOG(errwindow)->vbox),
                     errmessage, TRUE, TRUE, 10);
  
  /* Place button */
  errbutton = gtk_button_new_with_label(buttontext);
  gtk_box_pack_start(GTK_BOX (GTK_DIALOG(errwindow)->action_area),
                     errbutton, FALSE, FALSE, 10);




  /* Attach signals to button */
/* -------------------------------------------------- */
/* THERE IS A PROBLEM SOMEWHERE IN HERE  */

  if (fatal == 0) {
    /* just close the error window */
    gtk_signal_connect(GTK_OBJECT(errbutton), "clicked",
                       GTK_SIGNAL_FUNC(gtk_widget_destroy),
                       GTK_WIDGET(errwindow));

/* END PROBLEM */
/* -------------------------------------------------- */



  } else {
    /* Fatal error - close the app. 
       Perhaps link a logging function here later */
    gtk_signal_connect(GTK_OBJECT(errbutton), "clicked",
                       GTK_SIGNAL_FUNC(destroy), NULL);
  }
  
  /* Show widgets */
  gtk_widget_show(errmessage);
  gtk_widget_show(errbutton);
  gtk_widget_show(errwindow);

}







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