From 12cfd861ad224b9c28f4fe4dd66468875da865e7 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Fri, 4 Dec 2020 18:58:01 +0100 Subject: CrystFELMergeOpts: Checkbox disable/deactivation logic --- src/crystfelmergeopts.c | 72 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 61 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/crystfelmergeopts.c b/src/crystfelmergeopts.c index e922fec9..73ebff3b 100644 --- a/src/crystfelmergeopts.c +++ b/src/crystfelmergeopts.c @@ -62,21 +62,67 @@ static void crystfel_merge_opts_init(CrystFELMergeOpts *mo) } -static int maybe_disable(GtkWidget *toggle, GtkWidget *widget) +static void disable_if_inactive(GtkWidget *toggle, GtkWidget *widget) { gtk_widget_set_sensitive(GTK_WIDGET(widget), gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toggle))); +} + + +static void deactivate_if_inactive(GtkWidget *toggle, GtkWidget *widget) +{ + if ( !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toggle)) ) { + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), FALSE); + } +} + + +static void disable_and_deactivate(GtkWidget *toggle) +{ + gtk_widget_set_sensitive(toggle, FALSE); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle), FALSE); +} + + +static int check_greyout(GtkWidget *nothing, CrystFELMergeOpts *mo) +{ + int partialate; + + partialate = (gtk_combo_box_get_active(GTK_COMBO_BOX(mo->model_combo)) != 0); + + if ( !partialate ) { + gtk_widget_set_sensitive(GTK_WIDGET(mo->niter), FALSE); + disable_and_deactivate(mo->bscale); + disable_and_deactivate(mo->postref); + disable_and_deactivate(mo->deltacchalf); + disable_and_deactivate(mo->custom_split); + disable_and_deactivate(mo->detwin); + } else { + gtk_widget_set_sensitive(GTK_WIDGET(mo->niter), TRUE); + gtk_widget_set_sensitive(GTK_WIDGET(mo->bscale), TRUE); + gtk_widget_set_sensitive(GTK_WIDGET(mo->postref), TRUE); + gtk_widget_set_sensitive(GTK_WIDGET(mo->deltacchalf), TRUE); + gtk_widget_set_sensitive(GTK_WIDGET(mo->custom_split), TRUE); + gtk_widget_set_sensitive(GTK_WIDGET(mo->detwin), TRUE); + disable_if_inactive(mo->use_max_adu, mo->max_adu); + disable_if_inactive(mo->custom_split, mo->custom_split_file); + disable_if_inactive(mo->min_res, mo->min_res_val); + disable_if_inactive(mo->limit_res, mo->push_res); + disable_if_inactive(mo->detwin, mo->detwin_sym); + disable_if_inactive(mo->scale, mo->bscale); + deactivate_if_inactive(mo->scale, mo->bscale); + } + return FALSE; } -static void disable_if_not(GtkWidget *toggle, GtkWidget *widget) +static void check_on_toggle(GtkWidget *toggle, CrystFELMergeOpts *mo) { - maybe_disable(toggle, widget); g_signal_connect(G_OBJECT(toggle), "toggled", - G_CALLBACK(maybe_disable), - widget); + G_CALLBACK(check_greyout), + mo); } @@ -110,6 +156,8 @@ static GtkWidget *merge_parameters(CrystFELMergeOpts *mo) gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(mo->model_combo), "offset", "Monochromatic Ewald sphere offset (offset)"); + g_signal_connect(G_OBJECT(mo->model_combo), "changed", + G_CALLBACK(check_greyout), mo); /* Symmetry */ hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8); @@ -135,7 +183,7 @@ static GtkWidget *merge_parameters(CrystFELMergeOpts *mo) mo->postref = gtk_check_button_new_with_label("Post-refinement"); gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(mo->postref), FALSE, FALSE, 0); - disable_if_not(mo->scale, mo->bscale); + check_on_toggle(mo->scale, mo); /* Number of iterations */ hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8); @@ -184,7 +232,7 @@ static GtkWidget *merge_parameters(CrystFELMergeOpts *mo) gtk_entry_set_width_chars(GTK_ENTRY(mo->max_adu), 8); gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(mo->max_adu), FALSE, FALSE, 0); - disable_if_not(mo->use_max_adu, mo->max_adu); + check_on_toggle(mo->use_max_adu, mo); /* Minimum measurements */ hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8); @@ -209,7 +257,7 @@ static GtkWidget *merge_parameters(CrystFELMergeOpts *mo) GTK_FILE_CHOOSER_ACTION_OPEN); gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(mo->custom_split_file), FALSE, FALSE, 0); - disable_if_not(mo->custom_split, mo->custom_split_file); + check_on_toggle(mo->custom_split, mo); /* Minimum pattern resolution */ hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8); @@ -225,7 +273,7 @@ static GtkWidget *merge_parameters(CrystFELMergeOpts *mo) label = gtk_label_new("Å"); gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(label), FALSE, FALSE, 0); - disable_if_not(mo->min_res, mo->min_res_val); + check_on_toggle(mo->min_res, mo); /* push-res */ hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8); @@ -242,7 +290,7 @@ static GtkWidget *merge_parameters(CrystFELMergeOpts *mo) gtk_label_set_markup(GTK_LABEL(label), "nm-1 above resolution limit"); gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(label), FALSE, FALSE, 0); - disable_if_not(mo->limit_res, mo->push_res); + check_on_toggle(mo->limit_res, mo); /* Detwin */ hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8); @@ -254,7 +302,9 @@ static GtkWidget *merge_parameters(CrystFELMergeOpts *mo) mo->detwin_sym = crystfel_symmetry_selector_new(); gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(mo->detwin_sym), FALSE, FALSE, 0); - disable_if_not(mo->detwin, mo->detwin_sym); + check_on_toggle(mo->detwin, mo); + + check_greyout(NULL, mo); return box; } -- cgit v1.2.3