From fe6c0298cb7b1986ccf057d84c0c1e71c949f6ea Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Sat, 20 Jan 2024 12:40:52 +0100 Subject: [PATCH] WIP: cleaning... cleaning... cleaning... --- include/ui.h | 2 +- src/main.c | 16 ++++--- src/ui/application.c | 9 +++- src/ui/{bac-a-sable.c => sand_box_2.c} | 61 +++----------------------- 4 files changed, 26 insertions(+), 62 deletions(-) rename src/ui/{bac-a-sable.c => sand_box_2.c} (69%) diff --git a/include/ui.h b/include/ui.h index 14f7e1b..1ddc6f0 100644 --- a/include/ui.h +++ b/include/ui.h @@ -130,4 +130,4 @@ GtkWidget *create_my_list_view_test(GtkBox *runlib_objects); GtkWidget *create_my_editable_cells (GtkBox *my_box); GtkWidget *hello_it_s_me(); -void on_activate_window_creation (GtkApplication *app); +void on_activate_window_creation (GtkApplication *app, gpointer data); diff --git a/src/main.c b/src/main.c index eb9607c..07d24b4 100644 --- a/src/main.c +++ b/src/main.c @@ -50,7 +50,7 @@ * La suite est décrite dans * - application.c (activation / désactivation des actions, ajouts d'accélérateurs) * - gemgraph.ui (description statique de la fenêtre) - * - window.c (description dynamique de la fenêtre) + * - window.c (initialisation, description dynamique de la fenêtre - pas de "free" ?) * - events.c (description individuelle des actions élémentaires) * - tree.c (description d'une structure particulière) (sera répartie ultérieurement ?) * - base.h (définitions 'transversales'/(communes) utilisables par plusieurs ressources @@ -58,17 +58,21 @@ int main(int argc, char **argv) { - GtkWidget *my_window = hello_it_s_me(); // in : "bac-à-sable.c" - g_autoptr(GemGraphClientApplication) app = NULL; int res; app = gem_graph_client_application_new("org.alec.gemgraph", G_APPLICATION_DEFAULT_FLAGS); - g_signal_connect (app, "activate", G_CALLBACK (on_activate_window_creation), "creating a new window\n"); -// g_signal_connect (app, "activate", G_CALLBACK (on_activate), my_window); -// g_signal_connect (app, "activate", G_CALLBACK (on_activate), my_window); + g_signal_connect (app, "activate", G_CALLBACK (on_activate_window_creation), // in : "sand_box_2.c :" + "the signal comes from main.c and is displayed by sand_box_2 -> on_activate_window_creation()\n"); + + + // Jean 2024-01-20 Je désactive la visualisation de la fenêtre principale + // pour travailler dans une fenêtre minimale (cf. sand_box) + // + // gtk_window_present(window); < cf. application.c ligne 122 + res = g_application_run(G_APPLICATION(app), argc, argv); return res; diff --git a/src/ui/application.c b/src/ui/application.c index ab5d61c..8ad585a 100644 --- a/src/ui/application.c +++ b/src/ui/application.c @@ -112,7 +112,14 @@ static void gem_graph_client_application_activate(GApplication *app) ui_enable_action("togglesidebar"); ui_set_stack("run"); - gtk_window_present(window); + // XXX + // + // v + // + // Jean 2024-01-20 Je désactive la visualisation de cette fenêtre + // pour travailler dans une fenêtre minimale (cf. sand_box) + // + // gtk_window_present(window); } /* diff --git a/src/ui/bac-a-sable.c b/src/ui/sand_box_2.c similarity index 69% rename from src/ui/bac-a-sable.c rename to src/ui/sand_box_2.c index e78547d..b56c4f9 100644 --- a/src/ui/bac-a-sable.c +++ b/src/ui/sand_box_2.c @@ -30,9 +30,9 @@ #include "../../include/ui.h" static void on_button_action (GtkWidget *widget, gpointer data) {if (data) g_print (data);} -static void on_destroy (GtkWidget *widget, gpointer data) { exit(0);} +static void on_destroy (GtkWidget *widget, gpointer data) { if (data) g_print (data); exit(0);} -enum { NAME_COLUMN }; +static enum { NAME_COLUMN }; /* custom function to fill the model with data */ static GtkWidget populate_tree_model (my_store){ @@ -53,7 +53,7 @@ static GtkWidget populate_tree_model (my_store){ -void on_activate_window_creation (GtkApplication *app) { +void on_activate_window_creation (GtkApplication *app, gpointer data) { GtkWidget *my_window_2; GtkWidget *my_box_2; GtkWidget *my_button_2; @@ -63,6 +63,7 @@ void on_activate_window_creation (GtkApplication *app) { // Create a new window // GtkWidget *window = gtk_application_window_new (app); // gtk_init(); + if (data) g_print (data); my_window_2 = gtk_window_new (); gtk_window_set_title (GTK_WINDOW(my_window_2), my_window_title_2); gtk_window_set_default_size (GTK_WINDOW(my_window_2), 400, 34); @@ -70,66 +71,18 @@ void on_activate_window_creation (GtkApplication *app) { gtk_window_set_child(GTK_WINDOW(my_window_2), GTK_WIDGET(my_box_2)); gtk_widget_show (my_window_2); - // Create a new button my_button_2 = gtk_button_new_with_label (my_button_title_2); // When the button is clicked, close the window passed as an argument g_signal_connect(G_OBJECT (my_button_2), "clicked", G_CALLBACK(on_button_action), "some data from window 2\n"); g_signal_connect_swapped (my_button_2, "clicked", G_CALLBACK (gtk_window_close), my_window_2); -// gtk_window_set_child (GTK_WINDOW (my_window_2), my_button_2); // < écrase + g_signal_connect(G_OBJECT (my_window_2), "destroy", G_CALLBACK(on_destroy), "window 2 destruction ! (alone <> no exit(0) here)\n"); + + // gtk_window_set_child (GTK_WINDOW (my_window_2), my_button_2); // < écrase gtk_box_append(GTK_BOX(my_box_2), GTK_WIDGET(my_button_2)); // gtk_window_present (GTK_WINDOW (my_window)); } -GtkWidget *hello_it_s_me() -{ - GtkWidget *my_window; - GtkWidget *my_box; - GtkWidget *my_button; - char *my_window_title = "Hello, it's me !"; - char *my_button_title = "Yep ! I'm the button."; - GtkListStore *my_store; - GtkTreeIter my_iter_1, my_iter_2; - GtkWidget *my_tree; - /* GtkCellRenderer *my_renderer; */ - /* GtkTreeViewColumn *my_column; */ - - gtk_init(); // < nécessaire ici car, pour ne pas désorganiser l'écriture de main(), - // hello_it_s_me() est appelé avant l'initialisation de l'application - - my_window = gtk_window_new (); - - g_signal_connect(G_OBJECT (my_window), "destroy", G_CALLBACK(on_destroy), NULL); - - gtk_window_set_title (GTK_WINDOW(my_window), my_window_title); - gtk_window_set_default_size (GTK_WINDOW(my_window), 200, 34); - - my_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); - - my_button = gtk_button_new_with_label (my_button_title); - - g_signal_connect(G_OBJECT (my_button), "clicked", G_CALLBACK(on_button_action), "some data from window 1\n"); - gtk_box_append(GTK_BOX(my_box), GTK_WIDGET(my_button)); -// gtk_widget_show (my_button); < inutile (appels récursifs) - - gtk_window_set_child(GTK_WINDOW(my_window), GTK_WIDGET(my_box)); - - my_store = gtk_list_store_new (1, G_TYPE_STRING); // G_TYPE_CHAR); - // store = new GtkListStore(Gobject::TYPE_STRING, Gobject::TYPE_LONG); << GTK 3 ? - *my_tree = populate_tree_model (my_store); - /* my_tree = gtk_tree_view_new_with_model (GTK_TREE_MODEL (my_store)); */ - /* my_renderer = gtk_cell_renderer_text_new (); */ - - g_object_unref (G_OBJECT (my_store)); - - gtk_widget_show (my_window); - - printf("Window ('%s') with button ('%s') -[see the sand box]-\n", - my_window_title, my_button_title); - - return my_window; -} - //------------------------------------------------------------------------------ // guix shell -m manifest.scm make clean && clear && time make run