diff options
author | Thomas White <taw@physics.org> | 2019-09-24 15:29:41 +0200 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2019-09-24 15:29:41 +0200 |
commit | 622ed418cc955fab261c75f7e89e478ec6d7ff33 (patch) | |
tree | 62c7f1c0d78c68f9a045215a527a9a7259665363 /crystfel-demo.c | |
parent | ac6aecf008b2a29088a7a4dbf445381b649bea8e (diff) |
Work on actual demos
Diffstat (limited to 'crystfel-demo.c')
-rw-r--r-- | crystfel-demo.c | 172 |
1 files changed, 170 insertions, 2 deletions
diff --git a/crystfel-demo.c b/crystfel-demo.c index 1f00c9b..2686e2f 100644 --- a/crystfel-demo.c +++ b/crystfel-demo.c @@ -28,17 +28,169 @@ #include <gtk/gtk.h> +#include <sys/stat.h> +#include <errno.h> struct crystfeldemo { - int dummy; + GSubprocess *examine_raw_files; + GSubprocess *check_peak_detection; }; +gint stop_examine_raw(GtkWidget *widget, struct crystfeldemo *demo) +{ + if ( demo->examine_raw_files == NULL ) { + printf("Not running!\n"); + return 0; + } + + g_subprocess_send_signal(demo->examine_raw_files, SIGTERM); + g_subprocess_wait(demo->examine_raw_files, NULL, NULL); + demo->examine_raw_files = NULL; + + return 0; +} + + gint examine_raw_files(GtkWidget *widget, struct crystfeldemo *demo) { - printf("Demo!\n"); + GError *error = NULL; + + if ( demo->examine_raw_files != NULL ) { + printf("Already running!\n"); + return 0; + } + + demo->examine_raw_files = g_subprocess_new(G_SUBPROCESS_FLAGS_NONE, + &error, + "/home/taw/crystfel-demo/files/random-image", + "/home/taw/crystfel-demo/files/files.lst", + NULL); + + if ( demo->examine_raw_files == NULL ) { + printf("Failed to start demo process\n"); + } + return 0; +} + + +gint stop_peak_detection(GtkWidget *widget, struct crystfeldemo *demo) +{ + if ( demo->check_peak_detection == NULL ) { + printf("Not running!\n"); + return 0; + } + + g_subprocess_send_signal(demo->check_peak_detection, SIGTERM); + g_subprocess_wait(demo->check_peak_detection, NULL, NULL); + demo->check_peak_detection = NULL; + + return 0; +} + + +gint check_peak_detection(GtkWidget *widget, struct crystfeldemo *demo) +{ + GError *error = NULL; + + if ( demo->check_peak_detection != NULL ) { + printf("Already running!\n"); + return 0; + } + + demo->check_peak_detection = g_subprocess_new(G_SUBPROCESS_FLAGS_NONE, + &error, + "/home/taw/crystfel-demo/files/check-peak-detection", + "/home/taw/crystfel-demo/files/peaks.stream", + "--geometry=/home/taw/crystfel-demo/files/5HT2B.geom", + NULL); + + if ( demo->check_peak_detection == NULL ) { + printf("Failed to start demo process\n"); + } + return 0; +} + + +gint examine_geom_files(GtkWidget *widget, struct crystfeldemo *demo) +{ + GError *error = NULL; + + if ( demo->examine_raw_files != NULL ) { + printf("Already running!\n"); + return 0; + } + + demo->examine_raw_files = g_subprocess_new(G_SUBPROCESS_FLAGS_NONE, + &error, "sh", + "/home/taw/crystfel-demo/files/random-image", + "/home/taw/crystfel-demo/files/files.lst", + "--geometry=/home/taw/crystfel-demo/files/5HT2B.geom", + NULL); + + if ( demo->examine_raw_files == NULL ) { + printf("Failed to start demo process\n"); + } + return 0; +} + + +gint show_stream(GtkWidget *widget, struct crystfeldemo *demo) +{ + GError *error = NULL; + + if ( demo->examine_raw_files != NULL ) { + printf("Already running!\n"); + return 0; + } + + demo->examine_raw_files = g_subprocess_new(G_SUBPROCESS_FLAGS_NONE, + &error, "xfce4-terminal", + "-e", + "less", + "/home/taw/crystfel-demo/files/nocell.stream", + NULL); + + if ( demo->examine_raw_files == NULL ) { + printf("Failed to start demo process\n"); + } + return 0; +} + + +static int change_to_tempdir() +{ + char tmpdir[64]; + struct stat s; + + snprintf(tmpdir, 64, "crystfel_demo_dir.%i", getpid()); + + if ( stat(tmpdir, &s) == -1 ) { + + int r; + + if ( errno != ENOENT ) { + printf("Failed to stat temporary folder.\n"); + return 1; + } + + r = mkdir(tmpdir, S_IRWXU); + if ( r ) { + printf("Failed to create temporary folder: %s\n", + strerror(errno)); + return 1; + } + + } + + if ( chdir(tmpdir) ) { + printf("Failed to chdir to temporary folder: %s\n", + strerror(errno)); + return 1; + } + return 0; } @@ -49,12 +201,28 @@ int main(int argc, char *argv[]) GtkWidget *window; struct crystfeldemo demo; + if ( change_to_tempdir() ) return 1; + + demo.examine_raw_files = NULL; + gtk_init(&argc, &argv); builder = gtk_builder_new_from_resource("/de/desy/crystfel-demo/crystfel-demo.glade"); window = GTK_WIDGET(gtk_builder_get_object(builder, "mainwindow")); gtk_builder_add_callback_symbol(builder, "examine_raw_files", G_CALLBACK(examine_raw_files)); + gtk_builder_add_callback_symbol(builder, "examine_geom_files", + G_CALLBACK(examine_geom_files)); + gtk_builder_add_callback_symbol(builder, "stop_examine_raw", + G_CALLBACK(stop_examine_raw)); + + gtk_builder_add_callback_symbol(builder, "check_peak_detection", + G_CALLBACK(check_peak_detection)); + gtk_builder_add_callback_symbol(builder, "stop_peak_detection", + G_CALLBACK(stop_peak_detection)); + + gtk_builder_add_callback_symbol(builder, "show_stream", + G_CALLBACK(show_stream)); gtk_builder_connect_signals(builder, &demo); gtk_widget_show_all(window); |