Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

include custom widget #149

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
29 changes: 28 additions & 1 deletion nwbwidgets/view.py
@@ -1,4 +1,5 @@
from collections import OrderedDict
from collections.abc import Iterable

import h5py
import hdmf
Expand Down Expand Up @@ -94,5 +95,31 @@ def show_dynamic_table(node, **kwargs) -> widgets.Widget:
}


def nwb2widget(node, neurodata_vis_spec=default_neurodata_vis_spec):
def nwb2widget(node, neurodata_vis_spec=default_neurodata_vis_spec, include_widgets: list=None):

# Include user custom widgets
if include_widgets is None:
include_widgets = list()
for item in include_widgets:
widget = item.get('widget', None)
label = item.get('label', None)
pynwb_class = item.get('pynwb_class', None)
if widget and label and pynwb_class:
neurodata_vis_spec = include_widget(
neurodata_vis_spec=neurodata_vis_spec,
widget=widget,
label=label,
pynwb_class=pynwb_class
)
else:
print(f'Failed to include widget {widget} with label {label} to pynwb_class {pynwb_class}')

return base.nwb2widget(node, neurodata_vis_spec)


def include_widget(neurodata_vis_spec, widget, label, pynwb_class):
if pynwb_class in neurodata_vis_spec:
neurodata_vis_spec[pynwb_class].update({label: widget})
else:
neurodata_vis_spec[pynwb_class] = {label: widget}
return neurodata_vis_spec