aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2020-03-31 15:38:35 +0200
committerThomas White <taw@physics.org>2020-07-29 18:42:57 +0200
commit5d5e6434d7e2d1f1bced3ae8eb55cf951ff21937 (patch)
treea2d0cafb0e9cc9dbc9a4a534456030014a524167
parentbdd0dba7a832331f712740ddffc86e3d750a82f2 (diff)
Info/progress bar stuff
-rw-r--r--src/crystfel_gui.c103
-rw-r--r--src/crystfel_gui.h8
-rw-r--r--src/gui_backend_local.c14
-rw-r--r--src/gui_index.c17
4 files changed, 100 insertions, 42 deletions
diff --git a/src/crystfel_gui.c b/src/crystfel_gui.c
index aa548e24..4a6b4d91 100644
--- a/src/crystfel_gui.c
+++ b/src/crystfel_gui.c
@@ -541,19 +541,6 @@ static void add_gui_message(enum log_msg_type type, const char *msg,
}
-static void infobar_response_sig(GtkInfoBar *infobar, gint resp,
- gpointer data)
-{
- struct crystfelproject *proj = data;
-
- if ( resp == GTK_RESPONSE_CANCEL ) {
- proj->backend->cancel(proj);
- }
-
- gtk_info_bar_set_revealed(GTK_INFO_BAR(proj->info_bar), FALSE);
-}
-
-
int main(int argc, char *argv[])
{
int c;
@@ -566,7 +553,6 @@ int main(int argc, char *argv[])
GtkWidget *main_vbox;
GtkWidget *toolbar;
GtkWidget *button;
- GtkWidget *bar_area;
/* Long options */
const struct option longopts[] = {
@@ -616,6 +602,7 @@ int main(int argc, char *argv[])
proj.events = NULL;
proj.peak_params = NULL;
proj.unitcell_combo = NULL;
+ proj.info_bar = NULL;
proj.peak_search_params.method = PEAK_ZAEF;
proj.peak_search_params.threshold = 800.0;
proj.peak_search_params.min_sq_gradient = 100000;
@@ -696,23 +683,7 @@ int main(int argc, char *argv[])
gtk_box_pack_start(GTK_BOX(main_vbox), scroll, TRUE, TRUE, 0.0);
gtk_container_add(GTK_CONTAINER(frame), GTK_WIDGET(main_vbox));
gtk_paned_pack2(GTK_PANED(hpaned), GTK_WIDGET(frame), TRUE, TRUE);
-
- /* Progress info bar */
- proj.info_bar = gtk_info_bar_new_with_buttons(GTK_STOCK_CANCEL,
- GTK_RESPONSE_CANCEL,
- NULL);
- gtk_box_pack_end(GTK_BOX(main_vbox), GTK_WIDGET(proj.info_bar),
- FALSE, FALSE, 0.0);
- bar_area = gtk_info_bar_get_content_area(GTK_INFO_BAR(proj.info_bar));
- proj.progressbar = gtk_progress_bar_new();
- gtk_box_pack_start(GTK_BOX(bar_area),
- GTK_WIDGET(proj.progressbar),
- TRUE, TRUE, 0.0);
- gtk_progress_bar_set_show_text(GTK_PROGRESS_BAR(proj.progressbar),
- TRUE);
- gtk_info_bar_set_revealed(GTK_INFO_BAR(proj.info_bar), FALSE);
- g_signal_connect(G_OBJECT(proj.info_bar), "response",
- G_CALLBACK(infobar_response_sig), &proj);
+ proj.main_vbox = main_vbox;
/* Icon region at left */
proj.icons = gtk_vbox_new(FALSE, 0.0);
@@ -754,3 +725,73 @@ int main(int argc, char *argv[])
return 0;
}
+
+
+static void infobar_response_sig(GtkInfoBar *infobar, gint resp,
+ gpointer data)
+{
+ struct crystfelproject *proj = data;
+
+ if ( resp == GTK_RESPONSE_CANCEL ) {
+ proj->backend->cancel(proj);
+
+ } else if ( resp == GTK_RESPONSE_OK ) {
+ proj->infobar_callback(proj);
+
+ } else {
+ ERROR("Unrecognised infobar response!\n");
+
+ }
+}
+
+
+void remove_infobar(struct crystfelproject *proj)
+{
+ gtk_widget_destroy(proj->info_bar);
+ proj->info_bar = NULL;
+}
+
+
+GtkWidget *create_infobar(struct crystfelproject *proj, const char *task,
+ const char *extra_button,
+ void (*cbfunc)(struct crystfelproject *proj))
+{
+ GtkWidget *info_bar;
+ GtkWidget *bar_area;
+
+ if ( proj->info_bar != NULL ) {
+ STATUS("Can't create info bar - task already running\n");
+ return NULL;
+ }
+
+ /* Progress info bar */
+ info_bar = gtk_info_bar_new_with_buttons(GTK_STOCK_CANCEL,
+ GTK_RESPONSE_CANCEL,
+ extra_button,
+ GTK_RESPONSE_OK,
+ NULL);
+ gtk_box_pack_end(GTK_BOX(proj->main_vbox), GTK_WIDGET(info_bar),
+ FALSE, FALSE, 0.0);
+ proj->info_bar = info_bar;
+ proj->infobar_callback = cbfunc;
+
+ bar_area = gtk_info_bar_get_content_area(GTK_INFO_BAR(info_bar));
+
+ /* Create progress bar */
+ proj->progressbar = gtk_progress_bar_new();
+ gtk_box_pack_start(GTK_BOX(bar_area),
+ GTK_WIDGET(proj->progressbar),
+ TRUE, TRUE, 0.0);
+ gtk_progress_bar_set_text(GTK_PROGRESS_BAR(proj->progressbar),
+ task);
+ gtk_progress_bar_set_show_text(GTK_PROGRESS_BAR(proj->progressbar),
+ TRUE);
+
+ g_signal_connect(G_OBJECT(info_bar), "response",
+ G_CALLBACK(infobar_response_sig), proj);
+
+ gtk_widget_show_all(info_bar);
+ gtk_info_bar_set_revealed(GTK_INFO_BAR(info_bar), TRUE);
+
+ return info_bar;
+}
diff --git a/src/crystfel_gui.h b/src/crystfel_gui.h
index ee588e73..fc286e5d 100644
--- a/src/crystfel_gui.h
+++ b/src/crystfel_gui.h
@@ -74,6 +74,7 @@ struct crystfelproject {
GtkWidget *imageview;
GtkWidget *icons; /* Drawing area for task icons */
GtkWidget *report; /* Text view at the bottom for messages */
+ GtkWidget *main_vbox;
GtkWidget *image_info;
int cur_frame;
@@ -99,10 +100,17 @@ struct crystfelproject {
GtkWidget *unitcell_combo;
GtkWidget *info_bar;
+ void (*infobar_callback)(struct crystfelproject *proj);
GtkWidget *progressbar;
struct crystfel_backend *backend;
void *backend_private;
};
+extern void remove_infobar(struct crystfelproject *proj);
+
+extern GtkWidget *create_infobar(struct crystfelproject *proj, const char *task,
+ const char *extra_button,
+ void (*cbfunc)(struct crystfelproject *proj));
+
#endif
diff --git a/src/gui_backend_local.c b/src/gui_backend_local.c
index 90465ed6..bd856f18 100644
--- a/src/gui_backend_local.c
+++ b/src/gui_backend_local.c
@@ -42,10 +42,11 @@ struct local_backend_priv
};
-static void check_zombies(struct local_backend_priv *priv)
+static void check_zombies(struct crystfelproject *proj)
{
pid_t r;
int status;
+ struct local_backend_priv *priv = proj->backend_private;
if ( !at_zombies ) return;
@@ -55,6 +56,10 @@ static void check_zombies(struct local_backend_priv *priv)
} else {
STATUS("indexamajig process exited "
"with status %i\n", status);
+ if ( status != 0 ) {
+ gtk_progress_bar_set_text(GTK_PROGRESS_BAR(proj->progressbar),
+ "Failed");
+ }
}
priv->indexamajig_pid = 0;
at_zombies = 0;
@@ -67,10 +72,9 @@ static gboolean index_readable(GIOChannel *source, GIOCondition cond,
GIOStatus r;
GError *err = NULL;
struct crystfelproject *proj = vp;
- struct local_backend_priv *priv = proj->backend_private;
gchar *line;
- check_zombies(priv);
+ check_zombies(proj);
r = g_io_channel_read_line(source, &line, NULL, NULL, &err);
if ( r == G_IO_STATUS_EOF ) {
@@ -246,7 +250,7 @@ static void cancel(struct crystfelproject *proj)
struct local_backend_priv *priv = proj->backend_private;
if ( priv->indexamajig_pid == 0 ) {
- ERROR("Indexamajig not running!\n");
+ remove_infobar(proj);
return;
}
@@ -293,7 +297,7 @@ static void init_backend(struct crystfelproject *proj)
}
/* Callback to check on signals */
- g_timeout_add_seconds(1, G_SOURCE_FUNC(check_zombies), priv);
+ g_timeout_add_seconds(1, G_SOURCE_FUNC(check_zombies), proj);
proj->backend_private = priv;
STATUS("Local backend initialised.\n");
diff --git a/src/gui_index.c b/src/gui_index.c
index 68514a16..29ad829d 100644
--- a/src/gui_index.c
+++ b/src/gui_index.c
@@ -45,6 +45,12 @@
#include "crystfel_gui.h"
#include "crystfelimageview.h"
+static void cell_explorer_sig(struct crystfelproject *proj)
+{
+ STATUS("Run cell_explorer\n");
+}
+
+
static void unitcell_response_sig(GtkWidget *dialog, gint resp,
struct crystfelproject *proj)
{
@@ -59,14 +65,13 @@ static void unitcell_response_sig(GtkWidget *dialog, gint resp,
}
if ( proj->backend->run_unitcell(proj, algo) == 0 ) {
+
proj->unitcell_combo = NULL;
- gtk_progress_bar_set_text(GTK_PROGRESS_BAR(proj->progressbar),
- "Indexing (determine unit cell parameters)");
- gtk_info_bar_add_button(GTK_INFO_BAR(proj->info_bar),
- "Show cell histograms",
- 2);
- gtk_info_bar_set_revealed(GTK_INFO_BAR(proj->info_bar), TRUE);
+ create_infobar(proj,
+ "Indexing (determine unit cell parameters)",
+ "Show cell histograms", cell_explorer_sig);
+
}
}