From f4e023a236483e58cc398d524c2c3545db29fb0c Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Fri, 6 Sep 2024 11:02:03 +0200 Subject: [PATCH] WIP: https://github.com/ToshioCP/Gtk4-tutorial/blob/main/gfm/sec17.md what is 'startup' for ? --- include/signal.h | 1 + include/widget.h | 6 +++--- src/fsm/dispatch.c | 8 ++++---- src/fsm/prefer.c | 8 ++++---- src/main.c | 15 ++++++++------- src/widget/dispatch.c | 21 ++++++++++++++++++++- src/widget/rules/selected/text.c | 8 +++++++- src/widget/topbar/dispatch.c | 4 ++-- src/widget/topbar/right.c | 13 +++++++++---- 9 files changed, 58 insertions(+), 26 deletions(-) diff --git a/include/signal.h b/include/signal.h index ebe3983..fe14892 100644 --- a/include/signal.h +++ b/include/signal.h @@ -56,6 +56,7 @@ * which is in "topbar.c" (last one) (see widget.h) */ void on_windows_activation (GtkApplication *app); +void on_windows_startup (GtkApplication *app); diff --git a/include/widget.h b/include/widget.h index c9f6e44..dce0a07 100644 --- a/include/widget.h +++ b/include/widget.h @@ -55,7 +55,7 @@ void *widget_get_text_window(); // - widget / topbar / polytext.c // (after gtk_application_window_new (app) x 3) -void widget_design_main_window (GtkWindow *main_window); +void widget_design_main_window (GtkWindow *main_window, GtkApplication *app); void widget_design_dialog_window (GtkWindow *main_window, GtkWindow *dialog_window); void widget_design_text_window (GtkWindow *main_window, GtkWindow *text_window); @@ -93,13 +93,13 @@ void *widget_get_btt_data(); // {return btt_DATA;} // - widget / topbar / right.c void window_design_topbar_left (GtkWidget *header_bar); -void window_design_topbar_right (GtkWidget *header_bar); +void window_design_topbar_right (GtkWidget *header_bar, GtkApplication *app); // called in signal.c / fsm_get_state_rules_data() // defined in widget / synth / dispatch.c // - widget / state / dispatch.c -// - widget / rules / dispatch.c +// - widgetvoid on_windows_activation (GtkApplication *app) / rules / dispatch.c // - widget / data / dispatch.c // - widget / measure / dispatch.c diff --git a/src/fsm/dispatch.c b/src/fsm/dispatch.c index 888f4d3..ad6d6bd 100644 --- a/src/fsm/dispatch.c +++ b/src/fsm/dispatch.c @@ -121,22 +121,22 @@ void fsm_msg (int choice, int value, char *string, int sub_automaton) switch (sub_automaton) { // sub_automaton 0 is EXEC_EDIT and // sub_automaton 1 is STATE_RULES_DATA // sub_automaton 2 is MEASURE - case (0) : printf ("fsm/dispatch.message |\ + case (0) : printf ("fsm/dispatch (message) |\ switch %5s x %5s > %5s x %5s\n", tab_0 [choice_EXEC_EDIT], tab_1 [choice_STATE_RULES_DATA], tab_0 [choice], tab_1 [choice_STATE_RULES_DATA]); break; - case (1) : printf ("fsm/dispatch.message |\ + case (1) : printf ("fsm/dispatch (message) |\ switch %5s x %5s > %5s x %5s\n", tab_0 [choice_EXEC_EDIT], tab_1 [choice_STATE_RULES_DATA], tab_0 [choice_EXEC_EDIT], tab_1 [choice]); break; - case (2) : printf ("fsm/dispatch.message | %s\n", string); + case (2) : printf ("fsm/dispatch (message) | %s\n", string); break; - case (3) : printf ("fsm/dispatch.message | %2d\n", choice); + case (3) : printf ("fsm/dispatch (message) | %2d\n", choice); break; diff --git a/src/fsm/prefer.c b/src/fsm/prefer.c index 8abffcd..1dbf05d 100644 --- a/src/fsm/prefer.c +++ b/src/fsm/prefer.c @@ -132,7 +132,7 @@ void fsm_add_displayable (char *displayable_name) /* P R E F E R E N C E S */ /******************************************************************************/ -void fsm_preferences_init () {printf("src/fsm/prefer.c\ - | src/fsm/prefer.c fsm_preferences_init()\n");} -void fsm_displayable_list_init () {printf("src/fsm/prefer.c\ - | src/fsm/prefer.c fsm_displayable_list_init()\n");} +void fsm_preferences_init () {printf("fsm/prefer.c |\ + src/fsm/prefer.c fsm_preferences_init()\n");} +void fsm_displayable_list_init () {printf("fsm/prefer.c |\ + src/fsm/prefer.c fsm_displayable_list_init()\n");} diff --git a/src/main.c b/src/main.c index 2194d7a..4b35ced 100644 --- a/src/main.c +++ b/src/main.c @@ -135,23 +135,24 @@ int main (int argc, char **argv) { - int status; - - GtkApplication *app = gtk_application_new ("org.gem-graph", G_APPLICATION_DEFAULT_FLAGS); - fsm_init (); // fsm = finite state machine (see : src/fsm/dispatch.c) + GtkApplication *app = gtk_application_new ("org.gem-graph", G_APPLICATION_DEFAULT_FLAGS); + g_signal_connect (app, "startup", G_CALLBACK (on_windows_startup), NULL); g_signal_connect (app, "activate", G_CALLBACK (on_windows_activation), NULL); - // on_windows_activation <> see: src/widget/dispatch.c (NOT src/signal.c) - - status = g_application_run (G_APPLICATION (app), argc, argv); + // ! WARNING ! 'on_windows_activation()' + // and 'on_windows_startup()' are in: src/widget/dispatch.c + // NOT in: src/signal.c + int status = g_application_run (G_APPLICATION (app), argc, argv); g_object_unref (app); return status; } + + // GTK itself does not support event sounds, << A GREAT WAY TO DEBUG ! TODO // you have to use a loadable module like the one that comes with libcanberra. diff --git a/src/widget/dispatch.c b/src/widget/dispatch.c index 3156dfd..510847f 100644 --- a/src/widget/dispatch.c +++ b/src/widget/dispatch.c @@ -57,8 +57,21 @@ void *widget_get_main_window() { return main_window; } void *widget_get_dialog_window() { return dialog_window; } void *widget_get_text_window() { return text_window; } +static void action_b (GSimpleAction *action, + GVariant *parameter, + GApplication *application) {printf ("action_b() in widget/dispatch.c\n");} + +void on_windows_startup (GtkApplication *app) +{ + printf ("widget/dispatch.c |\ + on_windows_startup() is in: widget/dispatch.c NOT in: src/signal.c\n"); + +} + void on_windows_activation (GtkApplication *app) { + printf ("widget/dispatch.c |\ + on_windows_activation() is in: widget/dispatch.c NOT in: src/signal.c\n"); // g_application_activate (G_APPLICATION (app)); < how ? > in main.c is // g_signal_connect (app, "activate", G_CALLBACK (on_windows_activation), NULL); @@ -66,9 +79,15 @@ void on_windows_activation (GtkApplication *app) dialog_window = GTK_WINDOW (gtk_application_window_new (app)); text_window = GTK_WINDOW (gtk_application_window_new (app)); - widget_design_main_window (main_window); // def: widget/topbar/dispatch + widget_design_main_window (main_window, app); // def: widget/topbar/dispatch widget_design_dialog_window (main_window, dialog_window); widget_design_text_window (main_window, text_window); + + //https://github.com/ToshioCP/Gtk4-tutorial/blob/main/gfm/sec17.md + GtkApplication *app2 = GTK_APPLICATION (app); + GSimpleAction *act_b = g_simple_action_new ("do_b", NULL); + g_action_map_add_action (G_ACTION_MAP (app), G_ACTION (act_b)); + g_signal_connect (act_b, "activate", G_CALLBACK (action_b), app2); } /******************************************************************************/ diff --git a/src/widget/rules/selected/text.c b/src/widget/rules/selected/text.c index 1c676cf..3f96bf7 100644 --- a/src/widget/rules/selected/text.c +++ b/src/widget/rules/selected/text.c @@ -89,7 +89,6 @@ static void *get_btt_rule_identity() GtkWidget *label_C = GTK_WIDGET (gtk_label_new("date")); gtk_list_box_append (GTK_LIST_BOX (list_box), label_C); GtkWidget *label_D = GTK_WIDGET (gtk_label_new("author")); gtk_list_box_append (GTK_LIST_BOX (list_box), label_D); GtkWidget *label_E = GTK_WIDGET (gtk_label_new("status, activity")); gtk_list_box_append (GTK_LIST_BOX (list_box), label_E); - GtkWidget *label_F = GTK_WIDGET (gtk_label_new("links to other rules")); gtk_list_box_append (GTK_LIST_BOX (list_box), label_F); GtkWidget *pop = gtk_popover_new (); gtk_popover_set_child (GTK_POPOVER (pop), list_box); @@ -120,6 +119,13 @@ void *widget_get_selected_rule_texts() gtk_box_append (conditions_actions_names_box, GTK_WIDGET (get_btt_conditions_list ())); gtk_box_append (conditions_actions_names_box, GTK_WIDGET (get_btt_assign_list())); gtk_box_append (conditions_actions_names_box, GTK_WIDGET (get_btt_rule_identity())); + return GTK_WIDGET (conditions_actions_names_box); } +// https://juliagtk.github.io/Gtk4.jl/stable/manual/listtreeview/ +// +// https://github.com/ToshioCP/Gtk4-tutorial/blob/main/gfm/sec17.md + + + diff --git a/src/widget/topbar/dispatch.c b/src/widget/topbar/dispatch.c index 64255cb..d9b29dc 100644 --- a/src/widget/topbar/dispatch.c +++ b/src/widget/topbar/dispatch.c @@ -41,11 +41,11 @@ static GtkWidget *window_topbar (GtkWindow *window); -void widget_design_main_window (GtkWindow *main_window) +void widget_design_main_window (GtkWindow *main_window, GtkApplication *app) { GtkWidget *topbar = window_topbar (main_window); window_design_topbar_left (topbar); - window_design_topbar_right (topbar); + window_design_topbar_right (topbar, app); gtk_window_present (GTK_WINDOW (main_window)); } diff --git a/src/widget/topbar/right.c b/src/widget/topbar/right.c index 3ed0fd5..c6a87ff 100644 --- a/src/widget/topbar/right.c +++ b/src/widget/topbar/right.c @@ -36,10 +36,10 @@ /******************************************************************************/ /* M A I N W I N D O W T O P B A R ( R I G H T ) */ /******************************************************************************/ - +static void action_a (GSimpleAction *action, GVariant *parameter, gpointer app) {puts("menu item A clicked.\n");} static void connect(GApplication *app, gpointer *data) { puts("Connect menu item clicked.\n"); } -void window_design_topbar_right (GtkWidget *header_bar) +void window_design_topbar_right (GtkWidget *header_bar, GtkApplication *app) { gpointer no_local_data = NULL; @@ -93,11 +93,16 @@ void window_design_topbar_right (GtkWidget *header_bar) g_signal_connect(act_connect, "activate", G_CALLBACK(connect), NULL); + GSimpleAction *act_a = g_simple_action_new ("do_a", NULL); + g_action_map_add_action (G_ACTION_MAP (app), G_ACTION (act_a)); + g_signal_connect (act_a, "activate", G_CALLBACK (action_a), app); +// GMenuItem *menu_item_do_a = g_menu_item_new ("do_a", "app.do_a"); + // gtk_menu_button_popup (open_menu); gtk_menu_button_popdown (open_menu); // gtk_menu_item_activate (label_C); // g_action_map_add_action(G_ACTION_MAP(app), G_ACTION(act_connect)); - // GMenuItem *label_E = g_menu_item_new("connect", "app.connect"); - // gtk_list_box_append (GTK_LIST_BOX (list_box), GTK_WIDGET (label_E)); + // GMenuItem *label_E = g_menu_item_new("connect", "app.do_a"); +// gtk_list_box_append (GTK_LIST_BOX (list_box), GTK_WIDGET (menu_item_do_a));