1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
|
/*
* crystfel_gui.c
*
* CrystFEL's main graphical user interface
*
* 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 <stdarg.h>
#include <stdio.h>
#include <getopt.h>
#include <string.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms-compat.h>
#include <assert.h>
#include <datatemplate.h>
#include "crystfelimageview.h"
static void show_help(const char *s)
{
printf("Syntax: %s\n\n", s);
printf(
"CrystFEL graphical user interface.\n"
"\n"
" -h, --help Display this help message.\n"
" --version Print CrystFEL version number and exit.\n"
);
}
struct crystfelproject {
GtkWidget *window;
GtkUIManager *ui;
GtkActionGroup *action_group;
GtkWidget *imageview;
GtkWidget *icons; /* Drawing area for task icons */
GtkWidget *report; /* Text view at the bottom for messages */
};
static void error_box(struct crystfelproject *proj, const char *message)
{
GtkWidget *window;
window = gtk_message_dialog_new(GTK_WINDOW(proj->window),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_WARNING,
GTK_BUTTONS_CLOSE, "%s", message);
gtk_window_set_title(GTK_WINDOW(window), "Error");
g_signal_connect_swapped(window, "response",
G_CALLBACK(gtk_widget_destroy), window);
gtk_widget_show(window);
}
static gboolean destroy_sig(GtkWidget *da, struct crystfelproject *proj)
{
gtk_main_quit();
return FALSE;
}
static void add_ui_sig(GtkUIManager *ui, GtkWidget *widget,
GtkContainer *container)
{
gtk_box_pack_start(GTK_BOX(container), widget, FALSE, FALSE, 0);
if ( GTK_IS_TOOLBAR(widget) ) {
gtk_toolbar_set_show_arrow(GTK_TOOLBAR(widget), TRUE);
}
}
static gint quit_sig(GtkWidget *widget, struct crystfelproject *proj)
{
gtk_main_quit();
return FALSE;
}
static gint about_sig(GtkWidget *widget, struct crystfelproject *proj)
{
GtkWidget *window;
const gchar *authors[] = {
"Thomas White <taw@physics.org>",
NULL
};
window = gtk_about_dialog_new();
gtk_window_set_transient_for(GTK_WINDOW(window), GTK_WINDOW(proj->window));
gtk_about_dialog_set_program_name(GTK_ABOUT_DIALOG(window),
"CrystFEL graphical user interface");
gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(window), CRYSTFEL_VERSIONSTRING);
gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(window),
"© 2020 Deutsches Elektronen-Synchrotron DESY, "
"a research centre of the Helmholtz Association.");
gtk_about_dialog_set_website(GTK_ABOUT_DIALOG(window),
"https://www.desy.de/~twhite/crystfel");
gtk_about_dialog_set_authors(GTK_ABOUT_DIALOG(window), authors);
g_signal_connect(window, "response", G_CALLBACK(gtk_widget_destroy),
NULL);
gtk_widget_show_all(window);
return 0;
}
static void add_menu_bar(struct crystfelproject *proj, GtkWidget *vbox)
{
GError *error = NULL;
const char *ui = "<ui> <menubar name=\"cellwindow\">"
"<menu name=\"file\" action=\"FileAction\">"
" <menuitem name=\"quit\" action=\"QuitAction\" />"
"</menu>"
"<menu name=\"tools\" action=\"ToolsAction\" >"
"</menu>"
"<menu name=\"help\" action=\"HelpAction\">"
" <menuitem name=\"about\" action=\"AboutAction\" />"
"</menu>"
"</menubar></ui>";
GtkActionEntry entries[] = {
{ "FileAction", NULL, "_File", NULL, NULL, NULL },
{ "QuitAction", GTK_STOCK_QUIT, "_Quit", NULL, NULL,
G_CALLBACK(quit_sig) },
{ "ToolsAction", NULL, "_Tools", NULL, NULL, NULL },
{ "HelpAction", NULL, "_Help", NULL, NULL, NULL },
{ "AboutAction", GTK_STOCK_ABOUT, "_About", NULL, NULL,
G_CALLBACK(about_sig) },
};
guint n_entries = G_N_ELEMENTS(entries);
proj->action_group = gtk_action_group_new("cellwindow");
gtk_action_group_add_actions(proj->action_group, entries, n_entries, proj);
proj->ui = gtk_ui_manager_new();
gtk_ui_manager_insert_action_group(proj->ui, proj->action_group, 0);
g_signal_connect(proj->ui, "add_widget", G_CALLBACK(add_ui_sig), vbox);
if ( gtk_ui_manager_add_ui_from_string(proj->ui, ui, -1, &error) == 0 )
{
fprintf(stderr, "Error loading message window menu bar: %s\n",
error->message);
return;
}
gtk_window_add_accel_group(GTK_WINDOW(proj->window),
gtk_ui_manager_get_accel_group(proj->ui));
gtk_ui_manager_ensure_update(proj->ui);
}
int main(int argc, char *argv[])
{
int c;
struct crystfelproject proj;
GtkWidget *vbox;
GtkWidget *vpaned;
GtkWidget *hpaned;
GtkWidget *scroll;
GtkWidget *frame;
DataTemplate *dtempl;
/* Long options */
const struct option longopts[] = {
{"help", 0, NULL, 'h'},
{"version", 0, NULL, 1 },
{0, 0, NULL, 0}
};
/* Short options */
while ((c = getopt_long(argc, argv, "h",
longopts, NULL)) != -1) {
switch (c) {
case 'h' :
show_help(argv[0]);
return 0;
case 1 :
printf("CrystFEL: " CRYSTFEL_VERSIONSTRING "\n");
printf(CRYSTFEL_BOILERPLATE"\n");
return 0;
default :
return 1;
}
}
/* This isn't great, but necessary to make the command-line UI and file
* formats consistent with the other programs, which all use the C
* locale. Better would be to have all the programs call
* setlocale(LC_ALL, "") and use the C locale temporarily when reading
* or writing a stream, reflection file, geometry file etc. */
gtk_disable_setlocale();
gtk_init(&argc, &argv);
proj.window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(proj.window), "CrystFEL");
g_signal_connect(G_OBJECT(proj.window), "destroy", G_CALLBACK(destroy_sig),
&proj);
vbox = gtk_vbox_new(FALSE, 0.0);
gtk_container_add(GTK_CONTAINER(proj.window), vbox);
add_menu_bar(&proj, vbox);
vpaned = gtk_paned_new(GTK_ORIENTATION_VERTICAL);
gtk_box_pack_end(GTK_BOX(vbox), vpaned, TRUE, TRUE, 0.0);
hpaned = gtk_paned_new(GTK_ORIENTATION_HORIZONTAL);
gtk_paned_pack1(GTK_PANED(vpaned), hpaned, TRUE, TRUE);
proj.imageview = crystfel_image_view_new();
/* CrystFELImage into main area */
frame = gtk_frame_new(NULL);
gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN);
scroll = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll),
GTK_POLICY_ALWAYS, GTK_POLICY_ALWAYS);
gtk_container_add(GTK_CONTAINER(scroll), GTK_WIDGET(proj.imageview));
gtk_container_add(GTK_CONTAINER(frame), GTK_WIDGET(scroll));
gtk_paned_pack2(GTK_PANED(hpaned), GTK_WIDGET(frame), TRUE, TRUE);
/* Icon region at left */
proj.icons = gtk_drawing_area_new();
frame = gtk_frame_new(NULL);
gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN);
gtk_container_add(GTK_CONTAINER(frame), GTK_WIDGET(proj.icons));
gtk_paned_pack1(GTK_PANED(hpaned), GTK_WIDGET(frame), FALSE, FALSE);
/* Report (text) region at bottom */
proj.report = gtk_text_view_new();
frame = gtk_frame_new(NULL);
gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN);
gtk_container_add(GTK_CONTAINER(frame), GTK_WIDGET(proj.report));
gtk_paned_pack2(GTK_PANED(vpaned), GTK_WIDGET(frame), FALSE, FALSE);
gtk_window_set_default_size(GTK_WINDOW(proj.window), 1024, 768);
gtk_paned_set_position(GTK_PANED(hpaned), 172);
gtk_paned_set_position(GTK_PANED(vpaned), 600);
gtk_widget_show_all(proj.window);
gtk_main();
return 0;
}
|