From 31957b78353c675cd33fb7d45a2b633bbdeecb2a Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Mon, 17 Jun 2024 11:48:20 +0200 Subject: [PATCH] WIP: https://docs.gtk.org/gtk4/class.ToggleButton.html < TODO --- automaton.c | 49 +++++++++++++++++++++++++++++++------------------ automaton.h | 4 +--- callback.c | 24 +++++++++++++++++++----- callback.h | 2 ++ contain.c | 45 ++++++++++++++++++++++++++++++++++++--------- 5 files changed, 89 insertions(+), 35 deletions(-) diff --git a/automaton.c b/automaton.c index cc08492..0864498 100644 --- a/automaton.c +++ b/automaton.c @@ -13,8 +13,6 @@ * (state / rules / data) < VIEW * X * (measure / analyse / interpret) - * X - * (read / write) */ static int mode = RUN; @@ -30,24 +28,14 @@ int get_view () {return view;} /* T R A N S I T I O N S */ /******************************************************************************/ -void SWITCH_TO (int asked) { - switch (asked) { - case (INTER) : - view = INTER; printf ("SWITCH_TO INTER\n"); - break; - case (STATE) : // BEGIN_TO_EXEC_STOP - view = STATE; printf ("SWITCH_TO STATE\n"); - break; - case (RULES) : // EXEC_STOP_TO_RUN - view = RULES; printf ("SWITCH_TO RULES\n"); - break; - case (DATA) : // EXEC_RUN_TO_STOP - view = DATA; printf ("SWITCH_TO DATA\n"); - break; +void toggle_TO (int mode, int view) { + switch (view) { + case (INTER) : printf ("switch to INTER\n"); break; + case (STATE) : printf ("switch to STATE\n"); break; + case (RULES) : printf ("switch to RULES\n"); break; + case (DATA) : printf ("switch to DATA \n"); break; default : ; } - -//q gtk_window_present (GTK_WINDOW (main_window)); } @@ -58,6 +46,31 @@ void SWITCH_TO (int asked) { + + + + + + + + + + + + + + + + + + + + + + + + + /* enum { // S T A T E S INTER, diff --git a/automaton.h b/automaton.h index c7a9755..8596b4e 100644 --- a/automaton.h +++ b/automaton.h @@ -10,8 +10,6 @@ * (state / rules / data) < VIEW * X * (measure / analyse / interpret) < DATA - * X - * (read / write) < R__W */ /******************************************************************************/ @@ -24,4 +22,4 @@ enum mode { RUN, EDIT }; enum view { INTER, STATE, RULES, DATA }; // MEASURE, OBSERVE, INTERPRET, HELP, CONFIGURE }; -void SWITCH_TO (int asked); +void toggle_TO (int mode, int view); diff --git a/callback.c b/callback.c index 5bb61c7..bc757cb 100644 --- a/callback.c +++ b/callback.c @@ -186,20 +186,34 @@ void on_toggle_EXEC_EDIT (GtkWidget *btt_XOR_EXEC_EDIT, GtkWidget *btt_MODEL_RUN } -void on_open_STATE (GtkWidget *btt_open_STATE, gpointer data) {window_main_child (main_window, STATE); SWITCH_TO (STATE);} -void on_open_RULES (GtkWidget *btt_open_RULES, gpointer data) {window_main_child (main_window, RULES); SWITCH_TO (RULES);} -void on_open_DATA (GtkWidget *btt_open_DATA, gpointer data) {window_main_child (main_window, DATA); SWITCH_TO (DATA);} +void on_open_STATE (GtkWidget *btt_open_STATE, gpointer data) { + g_print ("Toggle button %s is active: %s\n", + gtk_button_get_label (GTK_TOGGLE_BUTTON (btt_open_STATE)), + gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (btt_open_STATE)) ? "Yes" : "No"); +}//{window_main_child (main_window, STATE); toggle_TO (RUN, STATE);} + +void on_open_RULES (GtkWidget *btt_open_RULES, gpointer data) { + g_print ("Toggle button %s is active: %s\n", + gtk_button_get_label (GTK_TOGGLE_BUTTON (btt_open_RULES)), + gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (btt_open_RULES)) ? "Yes" : "No"); +}//{window_main_child (main_window, RULES); toggle_TO (RUN, RULES);} + +void on_open_DATA (GtkWidget *btt_open_DATA, gpointer data) { + g_print ("Toggle button %s is active: %s\n", + gtk_button_get_label (GTK_TOGGLE_BUTTON (btt_open_DATA)), + gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (btt_open_DATA)) ? "Yes" : "No"); +}//{window_main_child (main_window, DATA); toggle_TO (RUN, DATA);} void on_SAVE_CURRENT_MODEL_BEFORE_EDITING (GtkWidget *btt_SAVE_CURRENT_MODEL, gpointer data) { gtk_widget_set_sensitive (GTK_WIDGET (data), TRUE); printf ("callback.c (line 201) - SAVE_CURRENT_MODEL_BEFORE_EDITING\n"); - SWITCH_TO (INTER); + toggle_TO (RUN, INTER); } void on_DISCARD_CURRENT_MODEL_AND_START_EDITING (GtkWidget *btt_SAVE_CURRENT_MODEL, gpointer data) { gtk_window_close (GTK_WINDOW (data)); printf ("callback.c (line 206) - DISCARD_CURRENT_MODEL_AND_START_EDITING\n"); - SWITCH_TO (RULES); + toggle_TO (RUN, RULES); } void on_WRITE_CURRENT_MODEL (GtkWidget *btt_WRITE_CURRENT_MODEL, gpointer data) { diff --git a/callback.h b/callback.h index ac26745..fc4bbd3 100644 --- a/callback.h +++ b/callback.h @@ -17,6 +17,8 @@ void on_axis_value_change (GtkAdjustment *adjustment, gpointer data); void on_toggle_EXEC_EDIT (GtkWidget *btt_XOR_EXEC_EDIT, GtkWidget *btt_MODEL_RUN_STOP); void on_toggle_MODEL_RUN_STOP (GtkWidget *btt_MODEL_RUN_STOP, gpointer data); +// https://docs.gtk.org/gtk4/class.ToggleButton.html + void on_open_STATE (GtkWidget *btt_open_STATE, gpointer data); void on_open_RULES (GtkWidget *btt_open_RULES, gpointer data); void on_open_DATA (GtkWidget *btt_open_DATA, gpointer data); diff --git a/contain.c b/contain.c index 85a55fa..40328c4 100644 --- a/contain.c +++ b/contain.c @@ -176,20 +176,29 @@ void window_header_bar (GtkWindow *window, char *title){ // gtk_header_bar_pack_start (GTK_HEADER_BAR (header_bar), GTK_WIDGET (separe)); GtkWidget *any_Label = GTK_WIDGET (gtk_label_new (" | ")); - GtkCheckButton *group_STATE_RULES_DATA = GTK_CHECK_BUTTON (gtk_check_button_new ()); - GtkButton *btt_open_STATE = GTK_BUTTON (gtk_check_button_new_with_label ("state")); - g_signal_connect (btt_open_STATE, "toggled", G_CALLBACK (on_open_STATE), no_local_data); - gtk_check_button_set_group (GTK_CHECK_BUTTON (btt_open_STATE), group_STATE_RULES_DATA); - GtkButton *btt_open_RULES = GTK_BUTTON (gtk_check_button_new_with_label ("rules")); - g_signal_connect (btt_open_RULES, "toggled", G_CALLBACK (on_open_RULES), no_local_data); - gtk_check_button_set_group (GTK_CHECK_BUTTON (btt_open_RULES), group_STATE_RULES_DATA); - GtkButton *btt_open_DATA = GTK_BUTTON (gtk_check_button_new_with_label ("data analysis")); - g_signal_connect (btt_open_DATA, "toggled", G_CALLBACK (on_open_DATA), no_local_data); + GtkCheckButton *group_STATE_RULES_DATA = GTK_CHECK_BUTTON (gtk_check_button_new ()); + gtk_check_button_set_group (GTK_CHECK_BUTTON (btt_open_STATE), group_STATE_RULES_DATA); + gtk_check_button_set_group (GTK_CHECK_BUTTON (btt_open_RULES), group_STATE_RULES_DATA); gtk_check_button_set_group (GTK_CHECK_BUTTON (btt_open_DATA), group_STATE_RULES_DATA); + int selected = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (btt_open_STATE)); + printf("%d\n", selected); + + if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (btt_open_STATE))) + g_signal_connect (btt_open_STATE, "toggled", G_CALLBACK (on_open_STATE), NULL); + else + g_signal_connect (btt_open_STATE, "toggled", G_CALLBACK (on_open_STATE), NULL); + + if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (btt_open_RULES))) + g_signal_connect (btt_open_RULES, "toggled", G_CALLBACK (on_open_RULES), NULL); + else + g_signal_connect (btt_open_RULES, "toggled", G_CALLBACK (on_open_RULES), NULL); + + g_signal_connect (btt_open_DATA, "toggled", G_CALLBACK (on_open_DATA), no_local_data); + gtk_check_button_set_active (GTK_CHECK_BUTTON (btt_open_STATE), TRUE); gtk_header_bar_pack_start (GTK_HEADER_BAR (header_bar), GTK_WIDGET (btt_XOR_EXEC_EDIT)); @@ -202,6 +211,24 @@ void window_header_bar (GtkWindow *window, char *title){ icons_for_fun (GTK_HEADER_BAR (header_bar)); // https://iconduck.com/sets/adwaita-icon-theme } +static void output_state (GtkToggleButton *source, gpointer user_data) { + g_print ("Toggle button %s is active: %s\n", + gtk_button_get_label (GTK_BUTTON (source)), + gtk_toggle_button_get_active (source) ? "Yes" : "No"); + + +} + +static void make_toggles (void) { + GtkWidget *toggle1, *toggle2; + + toggle1 = gtk_toggle_button_new_with_label ("Hi, I’m toggle button one"); + g_signal_connect (toggle1, "toggled", G_CALLBACK (output_state), NULL); + + toggle2 = gtk_toggle_button_new_with_label ("Hi, I’m toggle button two"); + g_signal_connect (toggle2, "toggled", G_CALLBACK (output_state), NULL); +} + void window_main_child (GtkWindow *main_window, int selected_page){ /* switch (selected_page) {