Wait for other window status/data to decide wether or not to display the main window

I have some code in which I need to display an introductory window, and based on the data collected in that window, then display the main window. How can it be achieved?

Here is the code where I hope to make it happen. How could I “wait” until proj_list be closed before checking for proj_list_status and then display the main window?

static void
memoapp_activate (GApplication *app)
{

  short proj_list_status = 1;

  MemoAppWindow *win;

  win = memoapp_window_new (MEMO_APP (app));

  MemoAppProjList *proj_list;
  proj_list = memoapp_proj_list_new (win, &proj_list_status);
  gtk_window_present (proj_list);

  if (proj_list_status == 0) {
    gtk_window_present (GTK_WINDOW (win));
  }
  else {
    g_print("%s\n", "error selecting project");
  }
}

You could use gtk_widget_show() and gtk_widget_hide() in a callback of your introduction window.

If it is a wizard built upon GtkDialog, you could could connect to “response” event:

https://developer.gnome.org/gtk3/stable/GtkDialog.html#GtkDialog-response

During the response event you would hide the wizard, like:

void
memo_app_wizard_response_callback(GtkDialog *dialog, gint response_id, gpointer user_data)
{
  MemoAppWindow *win;

  gtk_widget_hide(dialog);

  if(response_id == GTK_RESPONSE_OK){
    xmlDoc *doc;

    win = memoapp_window_new (MEMO_APP (app));

    doc = (xmlDoc *) user_data;

    /* ... */
  }
}

The user data passed to the response callback could be your collected data eg. as XML:

int
main(int argc, char **argv)
{
  GtkDialog *my_wizard;
  xmlDoc *doc;

  doc = xmlNewDoc("1.0");

  my_wizard = gtk_dialog_new_with_buttons("MemoApp Wizard",
    NULL,
    GTK_DIALOG_MODAL,
    "Ok",
    GTK_RESPONSE_OK,
    "Cancel",
    GTK_RESPONSE_REJECT,
    NULL);
  g_signal_connect(my_wizard, "response",
     G_CALLBACK(memo_app_wizard_response_callback), doc);

  /*
   * add custom widgets to the dialog by using gtk_dialog_get_content_area()
   */

  gtk_widget_show_all(my_wizard);

  gtk_main();

  return(0);
}

by Joël

Hi, @jkraehemann.

Thanks for your reply and insights. I’m using a GtkWindow (not GtkDialog), but I’ll try some stuff based on what you suggested. Thanks!

I tried using a different approach, namely, gtk_main () and gtk_main_quit ().

In the memoapp_proj_list_new () function, I run gtk_main () to create a new event loop, which “blocks” the main loop and does not display the main application window. Then, when I am done with the introductory window (an OK button or Cancel button is clicked), I invoke gtk_main_quit (), which ends the inner, nested event loop, and the main, original event loop comes back to life and the main application window is displayed.

In the manual, it reads:

You can nest calls to gtk_main() . In that case gtk_main_quit() will make the innermost invocation of the main loop return.

But it was not clear (from the manual) that one could use that to create this “wait for something to happen” effect. The first two links bellow enlightened me about it, though!

References:

https://hoad.io/blog/blocking-gtk-signal-handlers-without-freezing-your-application/

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.