aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2020-08-21 16:07:02 +0200
committerThomas White <taw@physics.org>2020-08-21 16:07:02 +0200
commit9c57e7d61658fb79967e1b1a46c98995a1fed020 (patch)
treea75e25d5ec05d9c50cdf9657a4eff4455272be1b /src
parent0f0ff14be48f5e4d9679f30286614db3d9c062d3 (diff)
Framework for backend parameters via GUI
Diffstat (limited to 'src')
-rw-r--r--src/crystfel_gui.c11
-rw-r--r--src/crystfel_gui.h4
-rw-r--r--src/gui_backend_local.c10
-rw-r--r--src/gui_backend_local.h2
-rw-r--r--src/gui_backend_slurm.c82
-rw-r--r--src/gui_backend_slurm.h36
-rw-r--r--src/gui_index.c130
-rw-r--r--src/gui_project.h3
8 files changed, 232 insertions, 46 deletions
diff --git a/src/crystfel_gui.c b/src/crystfel_gui.c
index 7254119d..ffd62e57 100644
--- a/src/crystfel_gui.c
+++ b/src/crystfel_gui.c
@@ -48,9 +48,10 @@
#include "crystfel_gui.h"
#include "gui_peaksearch.h"
#include "gui_index.h"
-#include "gui_backend_local.h"
#include "gui_project.h"
#include "version.h"
+#include "gui_backend_local.h"
+#include "gui_backend_slurm.h"
static void show_help(const char *s)
@@ -803,6 +804,9 @@ static void add_gui_message(enum log_msg_type type, const char *msg,
}
+const struct crystfel_backend *backends[16];
+
+
int main(int argc, char *argv[])
{
int c;
@@ -816,6 +820,11 @@ int main(int argc, char *argv[])
GtkWidget *toolbar;
GtkWidget *button;
+ backends[0] = backend_local;
+ backends[1] = backend_slurm;
+ backends[2] = NULL;
+ /* Max 16 */
+
/* Long options */
const struct option longopts[] = {
{"help", 0, NULL, 'h'},
diff --git a/src/crystfel_gui.h b/src/crystfel_gui.h
index 683c9261..27b2e8b6 100644
--- a/src/crystfel_gui.h
+++ b/src/crystfel_gui.h
@@ -33,6 +33,8 @@
struct crystfel_backend {
const char *name;
+ const char *friendly_name;
+ GtkWidget *(*make_parameters)(void);
int (*run_unitcell)(struct crystfelproject *proj,
const char *algo);
void (*cancel)(struct crystfelproject *proj);
@@ -40,6 +42,8 @@ struct crystfel_backend {
void (*shutdown)(struct crystfelproject *proj);
};
+extern const struct crystfel_backend *backends[];
+
extern void remove_infobar(struct crystfelproject *proj);
diff --git a/src/gui_backend_local.c b/src/gui_backend_local.c
index e485ed35..fc729a41 100644
--- a/src/gui_backend_local.c
+++ b/src/gui_backend_local.c
@@ -284,13 +284,21 @@ static void init_backend(struct crystfelproject *proj)
}
+static GtkWidget *make_parameters(void)
+{
+ return gtk_label_new("Local params");
+}
+
+
struct crystfel_backend _backend_local =
{
.name = "local",
+ .friendly_name = "Local (run on this computer)",
+ .make_parameters = make_parameters,
.init = init_backend,
.shutdown = shutdown_backend,
.run_unitcell = run_unitcell,
.cancel = cancel,
};
-struct crystfel_backend *backend_local = &_backend_local;
+const struct crystfel_backend *backend_local = &_backend_local;
diff --git a/src/gui_backend_local.h b/src/gui_backend_local.h
index 4bb3d0b3..94724e98 100644
--- a/src/gui_backend_local.h
+++ b/src/gui_backend_local.h
@@ -31,6 +31,6 @@
#include "crystfel_gui.h"
-extern struct crystfel_backend *backend_local;
+extern const struct crystfel_backend *backend_local;
#endif
diff --git a/src/gui_backend_slurm.c b/src/gui_backend_slurm.c
new file mode 100644
index 00000000..1ac0328b
--- /dev/null
+++ b/src/gui_backend_slurm.c
@@ -0,0 +1,82 @@
+/*
+ * gui_backend_slurm.c
+ *
+ * GUI backend for running jobs via SLURM
+ *
+ * Copyright © 2020 Deutsches Elektronen-Synchrotron DESY,
+ * a research centre of the Helmholtz Association.
+ *
+ * Authors:
+ * 2020 Thomas White <taw@physics.org>
+ *
+ * This file is part of CrystFEL.
+ *
+ * CrystFEL is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * CrystFEL is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with CrystFEL. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <pty.h>
+#include <glib.h>
+#include <sys/wait.h>
+#include <gtk/gtk.h>
+
+#include "crystfel_gui.h"
+
+
+struct slurm_backend_priv
+{
+ int dummy;
+};
+
+
+static void init_backend(struct crystfelproject *proj)
+{
+}
+
+
+static void shutdown_backend(struct crystfelproject *proj)
+{
+}
+
+
+static void cancel(struct crystfelproject *proj)
+{
+}
+
+
+static int run_unitcell(struct crystfelproject *proj,
+ const char *algo)
+{
+ return 0;
+}
+
+
+static GtkWidget *make_parameters(void)
+{
+ return gtk_label_new("SLURM params");
+}
+
+
+const struct crystfel_backend _backend_slurm =
+ {
+ .name = "slurm",
+ .friendly_name = "SLURM",
+ .make_parameters = make_parameters,
+ .init = init_backend,
+ .shutdown = shutdown_backend,
+ .run_unitcell = run_unitcell,
+ .cancel = cancel,
+ };
+
+const struct crystfel_backend *backend_slurm = &_backend_slurm;
diff --git a/src/gui_backend_slurm.h b/src/gui_backend_slurm.h
new file mode 100644
index 00000000..9865aa2a
--- /dev/null
+++ b/src/gui_backend_slurm.h
@@ -0,0 +1,36 @@
+/*
+ * gui_backend_slurm.h
+ *
+ * GUI backend for running jobs via SLURM
+ *
+ * Copyright © 2020 Deutsches Elektronen-Synchrotron DESY,
+ * a research centre of the Helmholtz Association.
+ *
+ * Authors:
+ * 2020 Thomas White <taw@physics.org>
+ *
+ * This file is part of CrystFEL.
+ *
+ * CrystFEL is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * CrystFEL is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with CrystFEL. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef GUI_BACKEND_SLURM_H
+#define GUI_BACKEND_SLURM_H
+
+#include "crystfel_gui.h"
+
+extern const struct crystfel_backend *backend_slurm;
+
+#endif
diff --git a/src/gui_index.c b/src/gui_index.c
index 86ecab35..9fdc0c4e 100644
--- a/src/gui_index.c
+++ b/src/gui_index.c
@@ -80,12 +80,33 @@ static void index_all_response_sig(GtkWidget *dialog, gint resp,
}
+static void backend_changed_sig(GtkWidget *combo,
+ struct crystfelproject *proj)
+{
+ int backend_idx;
+
+ backend_idx = gtk_combo_box_get_active(GTK_COMBO_BOX(combo));
+ if ( backend_idx < 0 ) return;
+
+ if ( proj->backend_opts != NULL ) {
+ gtk_widget_destroy(proj->backend_opts);
+ }
+ proj->backend_opts = backends[backend_idx]->make_parameters();
+
+ gtk_box_pack_start(GTK_BOX(proj->backend_opts_box),
+ GTK_WIDGET(proj->backend_opts),
+ FALSE, FALSE, 0);
+ gtk_widget_show_all(proj->backend_opts);
+}
+
+
static GtkWidget *make_backend_opts(struct crystfelproject *proj)
{
GtkWidget *box;
GtkWidget *hbox;
GtkWidget *label;
GtkWidget *combo;
+ int i;
box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 8);
gtk_container_set_border_width(GTK_CONTAINER(box), 8);
@@ -96,55 +117,31 @@ static GtkWidget *make_backend_opts(struct crystfelproject *proj)
label = gtk_label_new("Batch system:");
gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(label),
FALSE, FALSE, 0);
+
combo = gtk_combo_box_text_new();
gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(combo),
FALSE, FALSE, 0);
- gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(combo), "local",
- "Local (run on this computer)");
- gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(combo), "slurm",
- "SLURM");
- return box;
-}
-
-
-gint index_all_sig(GtkWidget *widget, struct crystfelproject *proj)
-{
- GtkWidget *dialog;
- GtkWidget *content_area;
- GtkWidget *vbox;
- GtkWidget *indexing_opts;
-
- if ( proj->indexing_opts != NULL ) return FALSE;
-
- dialog = gtk_dialog_new_with_buttons("Index all frames",
- GTK_WINDOW(proj->window),
- GTK_DIALOG_DESTROY_WITH_PARENT,
- "Cancel", GTK_RESPONSE_CANCEL,
- "Run", GTK_RESPONSE_OK,
- NULL);
-
- g_signal_connect(G_OBJECT(dialog), "response",
- G_CALLBACK(index_all_response_sig), proj);
-
- vbox = gtk_vbox_new(FALSE, 0.0);
- content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
- gtk_container_add(GTK_CONTAINER(content_area), vbox);
- gtk_container_set_border_width(GTK_CONTAINER(content_area), 8);
-
- indexing_opts = crystfel_indexing_opts_new();
- gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(indexing_opts),
- FALSE, FALSE, 8.0);
-
- gtk_notebook_append_page(GTK_NOTEBOOK(indexing_opts),
- make_backend_opts(proj),
- gtk_label_new("Cluster/batch system"));
+ i = 0;
+ do {
+ gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(combo),
+ backends[i]->name,
+ backends[i]->friendly_name);
+ } while ( backends[++i] != NULL );
+
+ proj->backend_opts_box = gtk_box_new(GTK_ORIENTATION_VERTICAL,
+ 0);
+ gtk_box_pack_start(GTK_BOX(box),
+ GTK_WIDGET(proj->backend_opts_box),
+ FALSE, FALSE, 0);
+ proj->backend_opts = NULL;
- gtk_dialog_set_default_response(GTK_DIALOG(dialog),
- GTK_RESPONSE_OK);
- gtk_widget_show_all(dialog);
+ /* proj->backend_opts{_box} must exist before the following */
+ g_signal_connect(G_OBJECT(combo), "changed",
+ G_CALLBACK(backend_changed_sig), proj);
+ gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0);
- return FALSE;
+ return box;
}
@@ -189,6 +186,53 @@ static void get_indexing_opts(struct crystfelproject *proj,
}
+gint index_all_sig(GtkWidget *widget, struct crystfelproject *proj)
+{
+ GtkWidget *dialog;
+ GtkWidget *content_area;
+ GtkWidget *vbox;
+ GtkWidget *backend_page;
+
+ if ( proj->indexing_opts != NULL ) return FALSE;
+
+ dialog = gtk_dialog_new_with_buttons("Index all frames",
+ GTK_WINDOW(proj->window),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ "Cancel", GTK_RESPONSE_CANCEL,
+ "Run", GTK_RESPONSE_OK,
+ NULL);
+
+ g_signal_connect(G_OBJECT(dialog), "response",
+ G_CALLBACK(index_all_response_sig), proj);
+
+ vbox = gtk_vbox_new(FALSE, 0.0);
+ content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
+ gtk_container_add(GTK_CONTAINER(content_area), vbox);
+ gtk_container_set_border_width(GTK_CONTAINER(content_area), 8);
+
+ proj->indexing_opts = crystfel_indexing_opts_new();
+ gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(proj->indexing_opts),
+ FALSE, FALSE, 8.0);
+ set_indexing_opts(proj,
+ CRYSTFEL_INDEXING_OPTS(proj->indexing_opts));
+
+ backend_page = make_backend_opts(proj),
+ gtk_notebook_append_page(GTK_NOTEBOOK(proj->indexing_opts),
+ backend_page,
+ gtk_label_new("Cluster/batch system"));
+ proj->backend_opts_box = gtk_vbox_new(FALSE, 0.0);
+ gtk_box_pack_start(GTK_BOX(backend_page),
+ proj->backend_opts_box,
+ FALSE, FALSE, 8.0);
+
+ gtk_dialog_set_default_response(GTK_DIALOG(dialog),
+ GTK_RESPONSE_OK);
+ gtk_widget_show_all(dialog);
+
+ return FALSE;
+}
+
+
static IndexingFlags indexing_flags(struct index_params *params)
{
IndexingFlags fl = 0;
diff --git a/src/gui_project.h b/src/gui_project.h
index 313a748a..1a6688dc 100644
--- a/src/gui_project.h
+++ b/src/gui_project.h
@@ -125,6 +125,9 @@ struct crystfelproject {
GtkWidget *peak_params; /* Peak search parameter widgets */
struct peak_params original_params;
+ GtkWidget *backend_opts;
+ GtkWidget *backend_opts_box;
+
GtkWidget *info_bar;
void (*infobar_callback)(struct crystfelproject *proj);
GtkWidget *progressbar;