From 9df20aacc1225ca94e0889c51371a96d626df5bd Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 11 Jan 2024 15:14:56 +0100 Subject: GUI: Switch to GtkFileChooserDialog for detector alignment Rationale: the refinement is very quick, and the output geometry file name is central to the process. --- src/gui_align.c | 74 ++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 55 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/gui_align.c b/src/gui_align.c index 5c559878..853919ae 100644 --- a/src/gui_align.c +++ b/src/gui_align.c @@ -46,14 +46,19 @@ struct align_window { struct crystfelproject *proj; GtkWidget *window; + GtkWidget *input_combo; GtkWidget *out_of_plane; GtkWidget *level; }; -static int run_align(struct align_window *win) +static int run_align(const char *input_name, int level, int out_of_plane, + const char *out_geom) { - STATUS("Mock detector alignment!\n"); + STATUS("Mock detector alignment from run '%s', level %i, %s -----> %s\n", + input_name, level, out_of_plane ? "out of plane" : "in plane", + out_geom); + return 0; } @@ -64,7 +69,26 @@ static void align_response_sig(GtkWidget *dialog, gint resp, int r = 0; if ( resp == GTK_RESPONSE_ACCEPT ) { - r = run_align(win); + + int level; + const char *input_name; + int out_of_plane; + gchar *filename; + + level = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(win->level)); + + input_name = get_combo_id(win->input_combo); + if ( input_name == NULL ) { + ERROR("Please select the input\n"); + r = 1; + } + + out_of_plane = get_bool(win->out_of_plane); + filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); + + r = run_align(input_name, level, out_of_plane, filename); + + g_free(filename); } if ( !r ) gtk_widget_destroy(dialog); @@ -73,33 +97,45 @@ static void align_response_sig(GtkWidget *dialog, gint resp, gint align_sig(GtkWidget *widget, struct crystfelproject *proj) { - GtkWidget *vbox; GtkWidget *hbox; GtkWidget *label; - GtkWidget *content_area; struct align_window *win; + int i; win = malloc(sizeof(struct align_window)); if ( win == NULL ) return 0; win->proj = proj; - win->window = gtk_dialog_new_with_buttons("Align detector", + win->window = gtk_file_chooser_dialog_new("Align detector", GTK_WINDOW(proj->window), - GTK_DIALOG_DESTROY_WITH_PARENT, - "Cancel", GTK_RESPONSE_CANCEL, - "Run", GTK_RESPONSE_OK, + GTK_FILE_CHOOSER_ACTION_SAVE, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL); + gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(win->window), + TRUE); + + hbox = gtk_hbox_new(FALSE, 0.0); + gtk_file_chooser_set_extra_widget(GTK_FILE_CHOOSER(win->window), + GTK_WIDGET(hbox)); + gtk_container_set_border_width(GTK_CONTAINER(hbox), 4); - vbox = gtk_vbox_new(FALSE, 0.0); - content_area = gtk_dialog_get_content_area(GTK_DIALOG(win->window)); - gtk_box_pack_start(GTK_BOX(content_area), GTK_WIDGET(vbox), TRUE, TRUE, 0.0); - gtk_container_set_border_width(GTK_CONTAINER(content_area), 8); + label = gtk_label_new("Refine using indexing result:"); + gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(label), + FALSE, FALSE, 4.0); + win->input_combo = gtk_combo_box_text_new(); + gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(win->input_combo), + FALSE, FALSE, 4.0); + for ( i=0; in_results; i++ ) { + gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(win->input_combo), + proj->results[i].name, + proj->results[i].name); + } + gtk_combo_box_set_active_id(GTK_COMBO_BOX(win->input_combo), + selected_result(proj)); - hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8); - gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(hbox), - FALSE, FALSE, 0.0); - label = gtk_label_new("Refinement level:"); + label = gtk_label_new("Hierarchy level:"); gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(label), FALSE, FALSE, 16.0); win->level = gtk_spin_button_new_with_range(0.0, 9.0, 1.0); @@ -107,8 +143,8 @@ gint align_sig(GtkWidget *widget, struct crystfelproject *proj) FALSE, FALSE, 4.0); gtk_widget_set_tooltip_text(win->level, "--level"); - win->out_of_plane = gtk_check_button_new_with_label("Refine out-of-plane positions and tilts"); - gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(win->out_of_plane), + win->out_of_plane = gtk_check_button_new_with_label("Include out-of-plane positions and tilts"); + gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(win->out_of_plane), FALSE, FALSE, 4.0); gtk_widget_set_tooltip_text(win->out_of_plane, "--out-of-plane"); -- cgit v1.2.3