From 9fa698495a3dbc5956a0251f01393229a7fb0b27 Mon Sep 17 00:00:00 2001 From: Rai Pranav Date: Sat, 3 Dec 2022 09:58:35 +0100 Subject: [PATCH] Recursive Contents Viewing --- src/gui.rs | 106 +++++++++++++++++----------------------------- src/hdf.rs | 6 +-- tests/test_hdf.rs | 2 +- 3 files changed, 42 insertions(+), 72 deletions(-) diff --git a/src/gui.rs b/src/gui.rs index 1db0018..86e236e 100644 --- a/src/gui.rs +++ b/src/gui.rs @@ -2,26 +2,45 @@ use crate::gui::egui::Ui; use crate::hdf; use eframe::egui; -use eframe::egui::containers::CollapsingHeader; +// use eframe::egui::containers::CollapsingHeader; + +pub fn create_group_recurision(group: &hdf5::Group, ui: &mut Ui) { + // println!("Group Starting {}",group.name()); + ui.collapsing(group.name(), |ui| { + let subgroups = group.groups().unwrap(); + if !subgroups.is_empty() { + for subgroup in subgroups { + // println!("{}",subgroup.name()); + create_group_recurision(&subgroup, ui); + } + } -// #[derive(Default)] + let datasets = group.datasets().unwrap(); + if !datasets.is_empty() { + for dataset in datasets { + ui.monospace(dataset.name()); + } + } + }); + // println!("Group Ending {}",group.name()); +} + +#[derive(Default)] pub(super) struct NWBView { dropped_files: Vec, picked_path: Option, h5_file: Option, - tree: Tree, } -impl Default for NWBView { - fn default() -> Self { - NWBView { - dropped_files: Default::default(), - picked_path: None, - h5_file: None, - tree: Tree::demo(), - } - } -} +// impl Default for NWBView { +// fn default() -> Self { +// NWBView { +// dropped_files: Default::default(), +// picked_path: None, +// h5_file: None, +// } +// } +// } impl eframe::App for NWBView { fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { @@ -42,20 +61,12 @@ impl eframe::App for NWBView { if let Some(hdf_file) = &self.h5_file { ui.horizontal(|ui| { - ui.label("Picked file:"); - let groups = hdf::get_subgroups(hdf_file); - - ui.collapsing("groups", |ui| { - ui.collapsing("subgroups", |ui| { - for group in groups { - ui.monospace(group.name()); - hdf::get_subgroups(&group); - } - }); - }); - CollapsingHeader::new("Tree") - .default_open(false) - .show(ui, |ui| self.tree.ui(ui)); + ui.label("NWB Contents"); + // let groups = hdf::get_subgroups(hdf_file); + create_group_recurision(hdf_file, ui); + // ui.collapsing(hdf_file.name(), |ui| { + // create_group_recurision(hdf_file, ui); + // }); }); } @@ -132,44 +143,3 @@ fn preview_files_being_dropped(ctx: &egui::Context) { ); } } - -struct Tree { - children: Option>, - name: String, -} - -impl Default for Tree { - fn default() -> Self { - Tree { - children: Some(Vec::new()), - name: "default".to_string(), - } - } -} - -impl Tree { - pub fn demo() -> Self { - Tree::default() - } - - pub fn ui(&mut self, ui: &mut Ui) { - self.ui_impl(ui, 0) - } -} - -impl Tree { - fn ui_impl(&self, ui: &mut Ui, depth: usize) { - CollapsingHeader::new(&self.name) - .default_open(depth < 1) - .show(ui, |ui| self.children_ui(ui, depth)); - } - - fn children_ui(&self, ui: &mut Ui, depth: usize) { - // make the two possible - if let Some(children) = &self.children { - for child in children { - child.ui_impl(ui, depth + 1); - } - }; - } -} diff --git a/src/hdf.rs b/src/hdf.rs index 16a5701..7f5da2c 100644 --- a/src/hdf.rs +++ b/src/hdf.rs @@ -7,9 +7,9 @@ pub(crate) fn read_nwb_file(path: &str) -> Option { } } -pub fn get_subgroups(group: &hdf5::Group) -> Vec { - group.groups().unwrap() -} +// pub fn get_subgroups(group: &hdf5::Group) -> Vec { +// group.groups().unwrap() +// } // pub fn print_subgroups(group: &hdf5::Group) { // let groups = get_subgroups(group); diff --git a/tests/test_hdf.rs b/tests/test_hdf.rs index 495da44..87f1d7c 100644 --- a/tests/test_hdf.rs +++ b/tests/test_hdf.rs @@ -21,7 +21,7 @@ fn read_invalid_file() { fn get_subgroups_from_file() { let input_file = hdf::read_nwb_file("data/sub-anm266951_ses-20141201_behavior+icephys+ogen.nwb"); - let groups = hdf::get_subgroups(&input_file.unwrap()); + let groups = input_file.unwrap().groups().unwrap(); let expected_groups: Vec = vec![ "/acquisition".to_string(), "/analysis".to_string(),