From 5ae8201dbefdbd69741a2009704443655f98045a Mon Sep 17 00:00:00 2001 From: Thomas White Date: Fri, 30 Apr 2021 16:19:59 +0200 Subject: GUI: Take optional stream on command line Closes: https://gitlab.desy.de/thomas.white/crystfel/-/issues/12 --- src/crystfel_gui.c | 14 +++++++++++--- src/gui_import.c | 27 ++++++++++++++++++--------- src/gui_import.h | 2 ++ 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/crystfel_gui.c b/src/crystfel_gui.c index 8bd2abed..aef5cd1a 100644 --- a/src/crystfel_gui.c +++ b/src/crystfel_gui.c @@ -63,7 +63,7 @@ static void show_help(const char *s) { - printf("Syntax: %s\n\n", s); + printf("Syntax: %s [data.stream]\n\n", s); printf( "CrystFEL graphical user interface.\n" "\n" @@ -724,6 +724,7 @@ int main(int argc, char *argv[]) GtkWidget *button; GtkWidget *label; GtkWidget *w; + int load_result; /* Long options */ const struct option longopts[] = { @@ -904,8 +905,15 @@ int main(int argc, char *argv[]) /* Send messages to report region */ set_log_message_func(add_gui_message, &proj); - /* Load state from disk */ - if ( load_project(&proj) == 0 ) { + if ( optind < argc ) { + /* Create view of stream - probably temporary */ + load_result = load_stream(&proj, argv[optind++]); + } else { + /* Try to load state from disk */ + load_result = load_project(&proj); + } + + if ( load_result == 0 ) { DataTemplate *dtempl; GtkAction *w; proj.cur_frame = 0; diff --git a/src/gui_import.c b/src/gui_import.c index 11d5f7f2..4328cacf 100644 --- a/src/gui_import.c +++ b/src/gui_import.c @@ -243,32 +243,28 @@ static void import_via_search(struct finddata_ctx *ctx) } -static void import_stream(struct finddata_ctx *ctx) +/* stream_filename will be adopted */ +int load_stream(struct crystfelproject *proj, char *stream_filename) { - struct crystfelproject *proj = ctx->proj; Stream *st; - char *stream_filename; DataTemplate *dtempl; const char *geom_str; char **streams; - stream_filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(ctx->stream_chooser)); - if ( stream_filename == NULL ) return; - st = stream_open_for_read(stream_filename); - if ( st == NULL ) return; + if ( st == NULL ) return 1; geom_str = stream_geometry_file(st); if ( geom_str == NULL ) { ERROR("No geometry file\n"); stream_close(st); - return; + return 1; } dtempl = data_template_new_from_string(geom_str); if ( dtempl == NULL ) { stream_close(st); - return; + return 1; } /* If we do not yet have a DataTemplate, the one from the file @@ -291,6 +287,19 @@ static void import_stream(struct finddata_ctx *ctx) add_indexing_result(proj, result_name, streams, 1); select_result(proj, result_name); } + + return 0; +} + + +static void import_stream(struct finddata_ctx *ctx) +{ + char *stream_filename; + + stream_filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(ctx->stream_chooser)); + if ( stream_filename == NULL ) return; + + load_stream(ctx->proj, stream_filename); } diff --git a/src/gui_import.h b/src/gui_import.h index 6d25a32e..7389b1e9 100644 --- a/src/gui_import.h +++ b/src/gui_import.h @@ -34,5 +34,7 @@ #include "gui_project.h" extern gint import_sig(GtkWidget *widget, struct crystfelproject *proj); +extern int load_stream(struct crystfelproject *proj, + const char *stream_filename); #endif -- cgit v1.2.3