aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorValerio Mariani <valerio.mariani@desy.de>2015-02-23 11:18:55 +0100
committerThomas White <taw@physics.org>2015-02-23 11:35:24 +0100
commit304e32d31ef70a7e355d4f7b9e9e4adc26856bc0 (patch)
tree9c6cdcba04479cfa637a7685421c4604e197c3a5 /src
parent28992aa01437f544538193108ff4a75b2874aef8 (diff)
Added option to jump to random event
Diffstat (limited to 'src')
-rw-r--r--src/dw-hdfsee.c29
-rw-r--r--src/dw-hdfsee.h1
2 files changed, 28 insertions, 2 deletions
diff --git a/src/dw-hdfsee.c b/src/dw-hdfsee.c
index 0c5852c5..833ac01c 100644
--- a/src/dw-hdfsee.c
+++ b/src/dw-hdfsee.c
@@ -964,6 +964,18 @@ static gint displaywindow_newevent(DisplayWindow *dw, int new_event)
}
+static gint displaywindow_randomevent(GtkWidget *widget, DisplayWindow *dw)
+{
+ int rand_event;
+
+ if ( dw->not_ready_yet ) return 0;
+
+ rand_event = gsl_rng_uniform_int(&dw->rng, dw->ev_list->num_events);
+
+ return displaywindow_newevent(dw, rand_event);
+}
+
+
static gint displaywindow_set_newevent_response(GtkWidget *widget,
gint response,
DisplayWindow *dw)
@@ -1489,6 +1501,11 @@ static void set_events_menu_sensitivity(DisplayWindow *dw, int val) {
gtk_action_set_sensitive(GTK_ACTION(a), val);
a = gtk_ui_manager_get_action(dw->ui,
"/ui/displaywindow/events/gotevent");
+ gtk_action_set_sensitive(GTK_ACTION(a), val);
+ a = gtk_ui_manager_get_action(dw->ui,
+ "/ui/displaywindow/events/randomevent");
+ gtk_action_set_sensitive(GTK_ACTION(a), val);
+
}
@@ -2110,8 +2127,6 @@ static void calibmode_prev(GtkWidget *widget, DisplayWindow *dw)
}
-
-
static void event_next(GtkWidget *widget, DisplayWindow *dw)
{
int new_event;
@@ -2184,6 +2199,8 @@ static void displaywindow_addmenubar(DisplayWindow *dw, GtkWidget *vbox,
G_CALLBACK(event_next) },
{ "GotoEventAction", NULL, "Go To Event", "e", NULL,
G_CALLBACK(displaywindow_set_newevent) },
+ { "RandomEventAction", NULL, "Go To Random Event", "r", NULL,
+ G_CALLBACK(displaywindow_randomevent) },
{ "HelpAction", NULL, "_Help", NULL, NULL, NULL },
{ "AboutAction", GTK_STOCK_ABOUT, "_About hdfsee...",
@@ -2742,6 +2759,14 @@ DisplayWindow *displaywindow_open(char *filename, char *geom_filename,
dw->statusbar = NULL;
dw->multi_event = 0;
dw->ev_list = NULL;
+ dw->rng = *gsl_rng_alloc(gsl_rng_mt19937);
+ FILE *fh;
+ unsigned long int seed;
+ fh = fopen("/dev/urandom", "r");
+ fread(&seed, sizeof(seed), 1, fh);
+ fclose(fh);
+ gsl_rng_set(&dw->rng, seed);
+
if ( geom_filename != NULL ) {
dw->geom_filename = strdup(geom_filename);
} else {
diff --git a/src/dw-hdfsee.h b/src/dw-hdfsee.h
index 9bb849a1..db6a81ce 100644
--- a/src/dw-hdfsee.h
+++ b/src/dw-hdfsee.h
@@ -146,6 +146,7 @@ typedef struct {
struct event_list *ev_list;
int curr_event;
+ gsl_rng rng;
} DisplayWindow;