Skip to content

Commit 585fc3d

Browse files
committed
include progresswidgets within gui
1 parent 2da584e commit 585fc3d

File tree

2 files changed

+61
-5
lines changed

2 files changed

+61
-5
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
2+
from ipywidgets import HBox, HTML, Output, FloatProgress
3+
from tqdm.notebook import tqdm_notebook
4+
5+
class tqdm_notebook_noauto(tqdm_notebook):
6+
7+
@staticmethod
8+
def status_printer(_, total=None, desc=None, ncols=None):
9+
"""
10+
Manage the printing of an IPython/Jupyter Notebook progress bar widget.
11+
"""
12+
# Fallback to text bar if there's no total
13+
# DEPRECATED: replaced with an 'info' style bar
14+
# if not total:
15+
# return super(tqdm_notebook, tqdm_notebook).status_printer(file)
16+
17+
# fp = file
18+
19+
if total:
20+
pbar = FloatProgress(min=0, max=total)
21+
else: # No total? Show info style bar with no progress tqdm status
22+
pbar = FloatProgress(min=0, max=1)
23+
pbar.value = 1
24+
pbar.bar_style = 'info'
25+
if ncols is None:
26+
pbar.layout.width = "20px"
27+
28+
ltext = HTML()
29+
rtext = HTML()
30+
if desc:
31+
ltext.value = desc
32+
container = HBox(children=[ltext, pbar, rtext])
33+
# Prepare layout
34+
if ncols is not None: # use default style of ipywidgets
35+
# ncols could be 100, "100px", "100%"
36+
ncols = str(ncols) # ipywidgets only accepts string
37+
try:
38+
if int(ncols) > 0: # isnumeric and positive
39+
ncols += 'px'
40+
except ValueError:
41+
pass
42+
pbar.layout.flex = '2'
43+
container.layout.width = ncols
44+
container.layout.display = 'inline-flex'
45+
container.layout.flex_flow = 'row wrap'
46+
47+
return container

pypop/notebook_interface/wizard.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from .plotting import MetricTable, ScalingPlot
1111
from .bokeh_widget import BokehWidgetWrapper
1212
from .reporting import ReportGenerator
13+
from .tqdm_widget import tqdm_notebook_noauto
1314

1415
from pypop.utils.exceptions import ExtraePRVNoOnOffEventsError
1516

@@ -128,7 +129,7 @@ def __init__(self, metric_calc="auto", base_dir=".", starting_files=None, **kwar
128129
self._status_box = VBox()
129130

130131
super().__init__(
131-
children=[VBox([self._status_box, self._fileselector])],
132+
children=[VBox([self._fileselector, self._status_box])],
132133
layout=Layout(width="auto", max_width="1280px"),
133134
**kwargs
134135
)
@@ -139,19 +140,27 @@ def _calculate_callback_hook(self, callback_reference=None):
139140

140141
advanced_config = self._fileselector._advanced_config_controls
141142

143+
fileprogress = tqdm_notebook_noauto(self._fileselector.filenames, leave=False)
144+
self._status_box.children = [fileprogress.container]
145+
142146
try:
143147
statistics = TraceSet(
144-
self._fileselector.filenames,
148+
fileprogress,
145149
force_recalculation=advanced_config["Delete Cache"].value,
146-
chop_to_roi=advanced_config["Chop to ROI"].value
150+
chop_to_roi=advanced_config["Chop to ROI"].value,
151+
no_progress=True,
147152
)
148153
except ExtraePRVNoOnOffEventsError as err:
154+
fileprogress = tqdm_notebook_noauto(self._fileselector.filenames, leave=False)
149155
warnstr = "Warning: Disabling Chopping to ROI ({})".format(err)
150-
self._status_box.children = [Text(warnstr, layout=Layout(width='auto'))]
156+
self._status_box.children = [fileprogress.container,
157+
Text(warnstr, layout=Layout(width='auto'))]
158+
151159
statistics = TraceSet(
152-
self._fileselector.filenames,
160+
fileprogress,
153161
force_recalculation=advanced_config["Delete Cache"].value,
154162
chop_to_roi=False,
163+
no_progress=True,
155164
)
156165

157166
if self._metric_calculator in ("auto", None):

0 commit comments

Comments
 (0)