aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2020-10-30 16:07:13 +0100
committerThomas White <taw@physics.org>2020-10-30 16:07:13 +0100
commit5e61ee1322a30ee505782697ff4b762dcec9b947 (patch)
tree45277a6108f9cf9e98d195b7af94de1acaa4a27a
parentfe1e61a9c28b25c759a609d5eb4d174c7d90a5c7 (diff)
Bring common GTK routines into separate file
-rw-r--r--CMakeLists.txt2
-rw-r--r--meson.build1
-rw-r--r--src/crystfelmergeopts.c35
-rw-r--r--src/gtk-util-routines.c86
-rw-r--r--src/gtk-util-routines.h39
-rw-r--r--src/gui_index.c15
-rw-r--r--src/gui_merge.c15
7 files changed, 130 insertions, 63 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b8a0569a..a3328c2a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -394,7 +394,7 @@ if (GTK_FOUND)
set(CRYSTFEL_GUI_SOURCES src/crystfel_gui.c src/crystfelimageview.c
src/gui_peaksearch.c src/gui_index.c src/gui_merge.c src/gui_backend_local.c
src/gui_project.c src/crystfelindexingopts.c src/crystfelmergeopts.c
- src/crystfelsymmetryselector.c)
+ src/crystfelsymmetryselector.c src/gtk-util-routines.c)
if (HAVE_SLURM)
set(CRYSTFEL_GUI_SOURCES ${CRYSTFEL_GUI_SOURCES} src/gui_backend_slurm.c)
diff --git a/meson.build b/meson.build
index acfc293a..69a4b9e6 100644
--- a/meson.build
+++ b/meson.build
@@ -211,6 +211,7 @@ if gtkdep.found()
'src/crystfelindexingopts.c',
'src/crystfelmergeopts.c',
'src/crystfelsymmetryselector.c',
+ 'src/gtk-util-routines.c',
'src/gui_peaksearch.c',
'src/gui_index.c',
'src/gui_merge.c',
diff --git a/src/crystfelmergeopts.c b/src/crystfelmergeopts.c
index aa357235..eb5f0665 100644
--- a/src/crystfelmergeopts.c
+++ b/src/crystfelmergeopts.c
@@ -44,6 +44,7 @@
#include "crystfelmergeopts.h"
#include "crystfelsymmetryselector.h"
+#include "gtk-util-routines.h"
G_DEFINE_TYPE(CrystFELMergeOpts,
@@ -431,40 +432,6 @@ void crystfel_merge_opts_set_push_res(CrystFELMergeOpts *mo,
}
-static float get_float(GtkWidget *entry)
-{
- const gchar *text;
- char *rval;
- float val;
- text = gtk_entry_get_text(GTK_ENTRY(entry));
- errno = 0;
- val = strtof(text, &rval);
- if ( *rval != '\0' ) return NAN;
- return val;
-}
-
-
-static unsigned int get_uint(GtkWidget *entry)
-{
- const gchar *text;
- char *rval;
- unsigned long int val;
- text = gtk_entry_get_text(GTK_ENTRY(entry));
- errno = 0;
- val = strtoul(text, &rval, 10);
- if ( *rval != '\0' ) {
- printf("Invalid integer '%s'\n", text);
- return 0;
- }
- return val;
-}
-
-static int get_bool(GtkWidget *widget)
-{
- return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
-}
-
-
const char *crystfel_merge_opts_get_model(CrystFELMergeOpts *opts)
{
return gtk_combo_box_get_active_id(GTK_COMBO_BOX(opts->model_combo));
diff --git a/src/gtk-util-routines.c b/src/gtk-util-routines.c
new file mode 100644
index 00000000..e0a2d705
--- /dev/null
+++ b/src/gtk-util-routines.c
@@ -0,0 +1,86 @@
+/*
+ * gtk-util-routines.h
+ *
+ * GTK utilities
+ *
+ * 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/>.
+ *
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <errno.h>
+#include <math.h>
+#include <gtk/gtk.h>
+
+
+char *get_all_text(GtkTextView *view)
+{
+ GtkTextBuffer *buf;
+ GtkTextIter start, end;
+
+ buf = gtk_text_view_get_buffer(view);
+
+ gtk_text_buffer_get_start_iter(buf, &start);
+ gtk_text_buffer_get_end_iter(buf, &end);
+
+ return gtk_text_buffer_get_text(buf, &start, &end, FALSE);
+}
+
+
+float get_float(GtkWidget *entry)
+{
+ const gchar *text;
+ char *rval;
+ float val;
+ text = gtk_entry_get_text(GTK_ENTRY(entry));
+ errno = 0;
+ val = strtof(text, &rval);
+ if ( *rval != '\0' ) return NAN;
+ return val;
+}
+
+
+unsigned int get_uint(GtkWidget *entry)
+{
+ const gchar *text;
+ char *rval;
+ unsigned long int val;
+ text = gtk_entry_get_text(GTK_ENTRY(entry));
+ errno = 0;
+ val = strtoul(text, &rval, 10);
+ if ( *rval != '\0' ) {
+ printf("Invalid integer '%s'\n", text);
+ return 0;
+ }
+ return val;
+}
+
+
+int get_bool(GtkWidget *widget)
+{
+ return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
+}
diff --git a/src/gtk-util-routines.h b/src/gtk-util-routines.h
new file mode 100644
index 00000000..7ad56fd7
--- /dev/null
+++ b/src/gtk-util-routines.h
@@ -0,0 +1,39 @@
+/*
+ * gtk-util-routines.h
+ *
+ * GTK utilities
+ *
+ * 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 GTK_UTIL_ROUTINES_H
+#define GTK_UTIL_ROUTINES_H
+
+#include <gtk/gtk.h>
+
+extern char *get_all_text(GtkTextView *view);
+extern int get_bool(GtkWidget *widget);
+extern unsigned int get_uint(GtkWidget *entry);
+extern float get_float(GtkWidget *entry);
+
+#endif
diff --git a/src/gui_index.c b/src/gui_index.c
index 42df35e7..96c7117f 100644
--- a/src/gui_index.c
+++ b/src/gui_index.c
@@ -54,6 +54,7 @@
#include "gui_project.h"
#include "crystfel_gui.h"
#include "gui_peaksearch.h"
+#include "gtk-util-routines.h"
static GFile *get_crystfel_path_gfile()
{
@@ -219,20 +220,6 @@ struct new_index_job_params {
};
-static char *get_all_text(GtkTextView *view)
-{
- GtkTextBuffer *buf;
- GtkTextIter start, end;
-
- buf = gtk_text_view_get_buffer(view);
-
- gtk_text_buffer_get_start_iter(buf, &start);
- gtk_text_buffer_get_end_iter(buf, &end);
-
- return gtk_text_buffer_get_text(buf, &start, &end, FALSE);
-}
-
-
static void index_all_response_sig(GtkWidget *dialog, gint resp,
struct new_index_job_params *njp)
{
diff --git a/src/gui_merge.c b/src/gui_merge.c
index 096a6ad1..971f49fc 100644
--- a/src/gui_merge.c
+++ b/src/gui_merge.c
@@ -42,6 +42,7 @@
#include "gui_project.h"
#include "crystfel_gui.h"
#include "crystfelmergeopts.h"
+#include "gtk-util-routines.h"
struct new_merging_job_params {
@@ -55,20 +56,6 @@ struct new_merging_job_params {
};
-static char *get_all_text(GtkTextView *view)
-{
- GtkTextBuffer *buf;
- GtkTextIter start, end;
-
- buf = gtk_text_view_get_buffer(view);
-
- gtk_text_buffer_get_start_iter(buf, &start);
- gtk_text_buffer_get_end_iter(buf, &end);
-
- return gtk_text_buffer_get_text(buf, &start, &end, FALSE);
-}
-
-
static void free_new_merging_job_params(gpointer njp, GClosure *closure)
{
free(njp);