Wow, I see your problem is that you did not understand what GtkBuilder and Gtk are doing, Because If I'm not wrong, each choice (entry) is a function to start something you want to do after the user/you clicked to the button called "restart". Here's my solution, it's maybe help you.
*) You can use gtk_widget_hide (target) function to hide any widget, in this case it's the main window. Then you can do your low-level functions what the other can see at the time after the signal "clicked" activated. Note: Some programs I saw the program did not exit when it's called to restart, there's only the changed/related data must be reload to buffer/ram, and the program must stop rendering/running at the time, after the reloading's done the program continues to render/display the new data in the screen. The reloading can be done in a new thread too, after used you can delete it too. On Wed, Jan 24, 2018 at 2:52 AM, Alexander Koeppe <alexander@koeppe.rocks> wrote: > I know about the possiblity to fire the low-level functions using an button > callback. However this would draw an exception for other UI choices the > application has: e.g. text, deamon. > > Therefore I'm looking for a way to keep the application structure for all > UIs the same. > > There is the test app I'm playing with: > > > #include <gtk/gtk.h> > > GtkApplication *app; > GtkWidget *window; > int initialized = 0; > > void quit_cb(GSimpleAction *action, GVariant *value, gpointer data) > { > g_print("quit!\n"); > g_object_unref(app); > exit(0); > } > > void restart_cb(GSimpleAction *action, GVariant *value, gpointer data) > { > g_print("restart!\n"); > g_application_quit(G_APPLICATION(app)); > } > > void test_cb(GSimpleAction *action, GVariant *value, gpointer data) > { > GtkWidget *dialog; > GtkDialogFlags flags = GTK_DIALOG_DESTROY_WITH_PARENT; > > > dialog = gtk_message_dialog_new(GTK_WINDOW(window), > flags, > GTK_MESSAGE_ERROR, > GTK_BUTTONS_CLOSE, > "TEst Message"); > g_signal_connect_swapped(dialog, "response", > G_CALLBACK(gtk_widget_destroy), > dialog); > gtk_dialog_run(GTK_DIALOG(dialog)); > } > > static void shutdown(GtkApplication *app, gpointer data) > { > initialized = 1; > } > > static void > activate (GtkApplication *app, > gpointer user_data) > { > GtkWidget *header, *menubutton, *frame, *overlay, *combo, *box; > GtkBuilder *builder; > > GActionEntry actions[] = { > {"test_action", test_cb, NULL, NULL, NULL,{}}, > {"restart", restart_cb, NULL, NULL, NULL, {}}, > {"quit", quit_cb, NULL, NULL, NULL, {}} > }; > > > g_action_map_add_action_entries(G_ACTION_MAP(app), actions, > G_N_ELEMENTS(actions), app); > > > > if (initialized == 0) { > window = gtk_application_window_new (app); > gtk_window_set_default_size (GTK_WINDOW (window), 500, 300); > } > else { > gtk_application_add_window(app, GTK_WINDOW(window)); > } > gtk_window_set_title (GTK_WINDOW (window), "buildertest"); > > /* Header Bar */ > header = gtk_header_bar_new(); > gtk_header_bar_set_title(GTK_HEADER_BAR(header), "Yeah"); > gtk_header_bar_set_show_close_button(GTK_HEADER_BAR(header), TRUE); > gtk_window_set_titlebar(GTK_WINDOW(window), header); > > /* Menu Button */ > menubutton = gtk_menu_button_new(); > > /* Menu for Menubutton */ > builder = gtk_builder_new(); > gtk_builder_add_from_string(builder, > "<interface>" > " <menu id='app-menu'>" > " <section>" > " <item>" > " <attribute name='label' > translatable='yes'>Restart</attribute>" > " <attribute name='action'>app.restart</attribute>" > " </item>" > " <item>" > " <attribute name='label' > translatable='yes'>Quit</attribute>" > " <attribute name='action'>app.quit</attribute>" > " </item>" > " </section>" > " </menu>" > " <menu id='test-menu'>" > " <section>" > " <attribute name='label' translatable='yes'>Test</attribute>" > " <item>" > " <attribute name='label' translatable='yes'>Test > Entry</attribute>" > " <attribute name='action'>app.test_action</attribute>" > " <attribute name='accel'>t</attribute>" > " </item>" > " </section>" > " </menu>" > "</interface>", -1, NULL); > > gtk_application_set_app_menu(GTK_APPLICATION(app), > G_MENU_MODEL(gtk_builder_get_object(builder, "app-menu"))); > > gtk_menu_button_set_menu_model(GTK_MENU_BUTTON(menubutton), > G_MENU_MODEL(gtk_builder_get_object(builder, "test-menu"))); > > gtk_button_set_image(GTK_BUTTON(menubutton), > gtk_image_new_from_icon_name("open-menu-symbolic", > GTK_ICON_SIZE_MENU)); > gtk_header_bar_pack_end(GTK_HEADER_BAR(header), menubutton); > > /* content area */ > if (initialized) { > overlay = gtk_bin_get_child(GTK_BIN(window)); > gtk_container_remove(GTK_CONTAINER(window), overlay); > } > > overlay = gtk_overlay_new(); > gtk_container_add(GTK_CONTAINER(window), overlay); > > frame = gtk_frame_new("Rahmen"); > gtk_container_add(GTK_CONTAINER(overlay), frame); > > box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5); > gtk_container_add(GTK_CONTAINER(frame), box); > > combo = gtk_combo_box_text_new(); > gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(combo), "id1", "Entry 1"); > gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(combo), "id2", "Entry 2"); > gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0); > gtk_widget_set_hexpand(combo, TRUE); > > gtk_box_pack_start(GTK_BOX(box), combo, FALSE, FALSE, 0); > > > > gtk_widget_show_all(window); > } > > int main(int argc, > char *argv[]) > { > app = NULL; > int status; > > app = gtk_application_new ("org.gnome.Buildertest", > G_APPLICATION_FLAGS_NONE); > g_signal_connect (app, "activate", G_CALLBACK (activate), NULL); > g_signal_connect (app, "shutdown", G_CALLBACK(shutdown), NULL); > status = g_application_run (G_APPLICATION (app), argc, argv); > > g_print("some things happen here\n"); > > g_object_unref(G_OBJECT(app)); > > app = gtk_application_new ("org.gnome.Buildertest", > G_APPLICATION_FLAGS_NONE); > g_signal_connect (app, "activate", G_CALLBACK (activate), NULL); > status = g_application_run (G_APPLICATION (app), argc, argv); > > return status; > } > > > Am 22.01.2018 um 22:09 schrieb Lucky B.C: > > Hi, can you show your demo about the way you did? But I think you should > keep the gtk_main() runs, because you can run your low-level functions by > "clicked" signal on button. > > On Jan 23, 2018 03:44, "Alexander Koeppe" <alexander@koeppe.rocks> wrote: > > Hi, > > I have an application where some things need to be setup in the UI, then > some low-level routines to be executed using the setup values and then > resuming the UI loop for further operation. > > Since I'm migrating the GTK code from GTK2/3 compatible to GNOME/GTK3, I > make use of g_application_run(). > > However, I find no simialar way to interrupt the loop (e.g. > gtk_main_quit()) and resuming the UI later (gtk_main()). > > The only way I found yet is to quit the application using > g_application_quit() but keep the window widget, clearing the > application (g_object_unref()) and creating a new application after > executing the low-level routines and finally adding the still existing > window widget to this new application using > gtk_application_add_window(). This way I can reuse the window and avoid > any flickering which is the required effect. > > The only caveat is, the added window is not considered being the primary > instance of the second application, hence the app-menu isn't displayed. > > Is there any way to define a window added being the primary instance of > the application or to show the app-menu (set using > gtk_application_set_app_menu()) in such an non-primary window, or even a > complete different approach? > > > Thanks and regards > > - Alex > > > _______________________________________________ > gtk-app-devel-list mailing list > gtk-app-devel-list@gnome.org > https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list > > > _______________________________________________ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list