Skip to content

Commit 583ec44

Browse files
enable/disable caching (#316)
* enable/disable caching * create_cache_row * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 9885afc commit 583ec44

1 file changed

Lines changed: 34 additions & 24 deletions

File tree

nwbwidgets/panel.py

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def __init__(
2727
enable_dandi_source: bool = True,
2828
enable_s3_source: bool = True,
2929
enable_local_source: bool = True,
30+
enable_cache: bool = True,
3031
show_warnings: bool = False,
3132
**kwargs,
3233
):
@@ -44,6 +45,8 @@ def __init__(
4445
Enable S3 source option.
4546
enable_local_source : bool, default: True
4647
Enable local source option.
48+
enable_cache : bool, default: True
49+
Enable caching data.
4750
show_warnings : bool, default: False
4851
Show warnings.
4952
"""
@@ -64,6 +67,7 @@ def __init__(
6467
if enable_s3_source:
6568
self.source_options_names.append("S3")
6669

70+
self.enable_cache = enable_cache
6771
self.all_dandisets_metadata = None
6872

6973
self.source_options_radio = widgets.RadioButtons(
@@ -107,6 +111,19 @@ def updated_source(self, args=None):
107111
elif args["new"] == "Local file":
108112
self.create_components_local_file_source()
109113

114+
def create_cache_row(self):
115+
"""Create cache row"""
116+
if self.enable_cache:
117+
self.cache_checkbox = widgets.Checkbox(description="cache")
118+
self.cache_checkbox.observe(self.toggle_cache)
119+
self.cache_path_text = widgets.Text("nwb-cache")
120+
self.cache_path_text.layout.visibility = "hidden"
121+
self.cache_row = widgets.HBox([self.cache_checkbox, self.cache_path_text])
122+
else:
123+
self.cache_checkbox = None
124+
self.cache_path_text = None
125+
self.cache_row = None
126+
110127
def create_components_dandi_source(self, args=None):
111128
"""Create widgets components for DANDI option"""
112129
if self.all_dandisets_metadata is None:
@@ -127,20 +144,16 @@ def create_components_dandi_source(self, args=None):
127144
description="File:",
128145
layout=widgets.Layout(width="400px", overflow=None),
129146
)
130-
self.cache_checkbox = widgets.Checkbox(
131-
description="cache",
132-
)
133-
self.cache_path_text = widgets.Text("nwb-cache")
134-
self.cache_path_text.layout.visibility = "hidden"
147+
148+
self.create_cache_row()
135149
self.source_dandi_file_button = widgets.Button(icon="check", description="Load file")
136150

151+
children_list = [self.source_dandi_id, self.source_dandi_file_dropdown, self.source_dandi_file_button]
152+
if self.cache_row is not None:
153+
children_list.insert(2, self.cache_row)
154+
137155
self.source_dandi_vbox = widgets.VBox(
138-
children=[
139-
self.source_dandi_id,
140-
self.source_dandi_file_dropdown,
141-
widgets.HBox([self.cache_checkbox, self.cache_path_text]),
142-
self.source_dandi_file_button,
143-
],
156+
children=children_list,
144157
layout=widgets.Layout(padding="5px 0px 5px 0px"),
145158
)
146159

@@ -150,12 +163,10 @@ def create_components_dandi_source(self, args=None):
150163
)
151164

152165
self.dandi_panel = widgets.HBox([self.source_dandi_vbox, self.dandi_summary])
153-
154166
self.source_changing_panel.children = [self.dandi_panel]
155167

156168
self.source_dandi_id.observe(self.list_dandiset_files_dropdown, "value")
157169
self.source_dandi_file_button.on_click(self.stream_dandiset_file)
158-
self.cache_checkbox.observe(self.toggle_cache)
159170
self.list_dandiset_files_dropdown()
160171

161172
def toggle_cache(self, args):
@@ -172,22 +183,21 @@ def create_components_s3_source(self):
172183
description="URL:",
173184
)
174185
self.source_s3_button = widgets.Button(icon="check", description="Load file")
175-
self.cache_checkbox = widgets.Checkbox(
176-
description="cache",
177-
)
178-
self.cache_path_text = widgets.Text("nwb-cache")
179-
self.cache_path_text.layout.visibility = "hidden"
186+
187+
self.create_cache_row()
188+
children_list = [
189+
self.source_s3_file_url,
190+
self.source_s3_button,
191+
]
192+
if self.cache_row is not None:
193+
children_list.insert(1, self.cache_row)
194+
180195
self.s3_panel = widgets.VBox(
181-
children=[
182-
self.source_s3_file_url,
183-
widgets.HBox([self.cache_checkbox, self.cache_path_text]),
184-
self.source_s3_button,
185-
],
196+
children=children_list,
186197
layout=widgets.Layout(padding="5px 0px 5px 0px"),
187198
)
188199
self.source_changing_panel.children = [self.s3_panel]
189200
self.source_s3_button.on_click(self.stream_s3_file)
190-
self.cache_checkbox.observe(self.toggle_cache)
191201

192202
def create_components_local_file_source(self):
193203
"""Create widgets components for Local file option"""

0 commit comments

Comments
 (0)