Skip to content

Commit

Permalink
Recursive Contents Viewing
Browse files Browse the repository at this point in the history
  • Loading branch information
rai-pranav committed Dec 3, 2022
1 parent 5ad0917 commit 9fa6984
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 72 deletions.
106 changes: 38 additions & 68 deletions src/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<egui::DroppedFile>,
picked_path: Option<String>,
h5_file: Option<hdf5::File>,
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) {
Expand All @@ -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);
// });
});
}

Expand Down Expand Up @@ -132,44 +143,3 @@ fn preview_files_being_dropped(ctx: &egui::Context) {
);
}
}

struct Tree {
children: Option<Vec<Tree>>,
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);
}
};
}
}
6 changes: 3 additions & 3 deletions src/hdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ pub(crate) fn read_nwb_file(path: &str) -> Option<hdf5::File> {
}
}

pub fn get_subgroups(group: &hdf5::Group) -> Vec<hdf5::Group> {
group.groups().unwrap()
}
// pub fn get_subgroups(group: &hdf5::Group) -> Vec<hdf5::Group> {
// group.groups().unwrap()
// }

// pub fn print_subgroups(group: &hdf5::Group) {
// let groups = get_subgroups(group);
Expand Down
2 changes: 1 addition & 1 deletion tests/test_hdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> = vec![
"/acquisition".to_string(),
"/analysis".to_string(),
Expand Down

0 comments on commit 9fa6984

Please sign in to comment.