diff options
author | Thomas White <taw@bitwiz.org.uk> | 2009-12-20 20:13:00 +0100 |
---|---|---|
committer | Thomas White <taw@bitwiz.org.uk> | 2009-12-20 20:13:00 +0100 |
commit | 563b05331db465e0e5ef0434de79e2cc06674d63 (patch) | |
tree | 51b38dc6958a152e9206c68a322d01316eab26de /src | |
parent | 24ce4a9e2becccb6f7e9a15ae29ba57042ce4e2e (diff) |
Show values of simple fields in menu
Diffstat (limited to 'src')
-rw-r--r-- | src/displaywindow.c | 20 | ||||
-rw-r--r-- | src/hdf5-file.c | 71 | ||||
-rw-r--r-- | src/hdf5-file.h | 2 |
3 files changed, 92 insertions, 1 deletions
diff --git a/src/displaywindow.c b/src/displaywindow.c index 8c1d0b01..ffcce983 100644 --- a/src/displaywindow.c +++ b/src/displaywindow.c @@ -692,12 +692,28 @@ static GtkWidget *displaywindow_addhdfgroup(struct hdfile *hdfile, } else { + char *tmp; + item = gtk_menu_item_new_with_label(names[i]); + tmp = hdfile_get_string_value(hdfile, names[i]); + if ( tmp != NULL ) { + + GtkWidget *ss; + GtkWidget *mss; + + mss = gtk_menu_new(); + ss = gtk_menu_item_new_with_label(tmp); + gtk_menu_shell_append(GTK_MENU_SHELL(mss), ss); + gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), + mss); + + } + + } gtk_menu_shell_append(GTK_MENU_SHELL(ms), item); - gtk_widget_show(item); free(names[i]); @@ -739,6 +755,8 @@ static void displaywindow_update_menus(DisplayWindow *dw) /* Make new menu be the submenu for File->Images */ w = gtk_ui_manager_get_widget(dw->ui, "/ui/displaywindow/file/images"); gtk_menu_item_set_submenu(GTK_MENU_ITEM(w), ms); + + gtk_widget_show_all(ms); } diff --git a/src/hdf5-file.c b/src/hdf5-file.c index 9368ca0e..c1f4f70e 100644 --- a/src/hdf5-file.c +++ b/src/hdf5-file.c @@ -273,6 +273,77 @@ static int looks_like_image(hid_t h) } +char *hdfile_get_string_value(struct hdfile *f, const char *name) +{ + hid_t dh; + hid_t sh; + hsize_t size; + hsize_t max_size; + hid_t type; + hid_t class; + + dh = H5Dopen(f->fh, name, H5P_DEFAULT); + if ( dh < 0 ) { + return NULL; + } + + sh = H5Dget_space(dh); + if ( H5Sget_simple_extent_ndims(sh) != 1 ) { + return NULL; + } + + H5Sget_simple_extent_dims(sh, &size, &max_size); + if ( size != 1 ) { + H5Dclose(dh); + return NULL; + } + + type = H5Dget_type(dh); + class = H5Tget_class(type); + switch ( class ) { + case H5T_FLOAT : { + + herr_t r; + double buf; + char *tmp; + + r = H5Dread(dh, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, + H5P_DEFAULT, &buf); + if ( r < 0 ) goto fail; + + tmp = malloc(256); + snprintf(tmp, 255, "%f", buf); + + return tmp; + + } + case H5T_INTEGER : { + + herr_t r; + int buf; + char *tmp; + + r = H5Dread(dh, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, + H5P_DEFAULT, &buf); + if ( r < 0 ) goto fail; + + tmp = malloc(256); + snprintf(tmp, 255, "%d", buf); + + return tmp; + } + default : { + goto fail; + } + } + +fail: + H5Tclose(type); + H5Dclose(dh); + return NULL; +} + + char **hdfile_read_group(struct hdfile *f, int *n, const char *parent, int **p_is_group, int **p_is_image) { diff --git a/src/hdf5-file.h b/src/hdf5-file.h index 0d1dbc48..a212f677 100644 --- a/src/hdf5-file.h +++ b/src/hdf5-file.h @@ -41,4 +41,6 @@ extern char **hdfile_read_group(struct hdfile *f, int *n, const char *parent, extern int hdfile_set_first_image(struct hdfile *f, const char *group); extern void hdfile_close(struct hdfile *f); +extern char *hdfile_get_string_value(struct hdfile *f, const char *name); + #endif /* HDF5_H */ |