|
1 | 1 | # AUTOGENERATED! DO NOT EDIT! File to edit: nbs/01_fastprogress.ipynb (unless otherwise specified).
|
2 | 2 |
|
3 |
| -__all__ = ['ProgressBar', 'MasterBar', 'NBProgressBar', 'NBMasterBar', 'NO_BAR', 'WRITER_FN', 'FLUSH', 'SAVE_PATH', |
4 |
| - 'SAVE_APPEND', 'MAX_COLS', 'printing', 'ConsoleProgressBar', 'print_and_maybe_save', 'ConsoleMasterBar', |
5 |
| - 'master_bar', 'progress_bar', 'force_console_behavior', 'workaround_empty_console_output'] |
| 3 | +__all__ = ['ProgressBar', 'MasterBar', 'NBOutput', 'NBProgressBar', 'NBMasterBar', 'NO_BAR', 'WRITER_FN', 'FLUSH', |
| 4 | + 'SAVE_PATH', 'SAVE_APPEND', 'MAX_COLS', 'printing', 'ConsoleProgressBar', 'print_and_maybe_save', |
| 5 | + 'ConsoleMasterBar', 'master_bar', 'progress_bar', 'force_console_behavior', |
| 6 | + 'workaround_empty_console_output'] |
6 | 7 |
|
7 | 8 | # Cell
|
8 | 9 | import time,os,shutil
|
@@ -98,16 +99,30 @@ def update(self, val): self.main_bar.update(val)
|
98 | 99 | try:
|
99 | 100 | from IPython.display import clear_output, display, HTML
|
100 | 101 | import matplotlib.pyplot as plt
|
| 102 | + import ipywidgets as widgets |
101 | 103 | except:
|
102 | 104 | warn("Couldn't import ipywidgets properly, progress bar will use console behavior")
|
103 | 105 | IN_NOTEBOOK = False
|
104 | 106 |
|
| 107 | +# Cell |
| 108 | +class NBOutput(): |
| 109 | + def __init__(self, to_display): |
| 110 | + self.out = widgets.Output() |
| 111 | + display(self.out) |
| 112 | + with self.out: |
| 113 | + display(to_display) |
| 114 | + |
| 115 | + def update(self, to_update): |
| 116 | + with self.out: |
| 117 | + clear_output(wait=True) |
| 118 | + display(to_update) |
| 119 | + |
105 | 120 | # Cell
|
106 | 121 | class NBProgressBar(ProgressBar):
|
107 | 122 | def on_iter_begin(self):
|
108 | 123 | super().on_iter_begin()
|
109 | 124 | self.progress = html_progress_bar(0, self.total, "")
|
110 |
| - if self.display: self.out = display(HTML(self.progress), display_id=True) |
| 125 | + if self.display: self.out = NBOutput(HTML(self.progress)) |
111 | 126 | self.is_active=True
|
112 | 127 |
|
113 | 128 | def on_interrupt(self):
|
@@ -138,7 +153,7 @@ def __init__(self, gen, total=None, hide_graph=False, order=None, clean_on_inter
|
138 | 153 |
|
139 | 154 | def on_iter_begin(self):
|
140 | 155 | self.html_code = '\n'.join([html_progress_bar(0, self.main_bar.total, ""), ""])
|
141 |
| - self.out = display(HTML(self.html_code), display_id=True) |
| 156 | + self.out = NBOutput(HTML(self.html_code)) |
142 | 157 |
|
143 | 158 | def on_interrupt(self):
|
144 | 159 | if self.clean_on_interrupt: self.out.update(HTML(''))
|
@@ -182,14 +197,14 @@ def show_imgs(self, imgs, titles=None, cols=4, imgsize=4, figsize=None):
|
182 | 197 | if titles is None: titles = [None] * len(imgs)
|
183 | 198 | for img, ax, title in zip(imgs, imgs_axs.flatten(), titles): img.show(ax=ax, title=title)
|
184 | 199 | for ax in imgs_axs.flatten()[len(imgs):]: ax.axis('off')
|
185 |
| - if not hasattr(self, 'imgs_out'): self.imgs_out = display(self.imgs_fig, display_id=True) |
| 200 | + if not hasattr(self, 'imgs_out'): self.imgs_out = NBOutput(self.imgs_fig) |
186 | 201 | else: self.imgs_out.update(self.imgs_fig)
|
187 | 202 |
|
188 | 203 | def update_graph(self, graphs, x_bounds=None, y_bounds=None, figsize=(6,4)):
|
189 | 204 | if self.hide_graph: return
|
190 | 205 | if not hasattr(self, 'graph_fig'):
|
191 | 206 | self.graph_fig, self.graph_ax = plt.subplots(1, figsize=figsize)
|
192 |
| - self.graph_out = display(self.graph_ax.figure, display_id=True) |
| 207 | + self.graph_out = NBOutput(self.graph_ax.figure) |
193 | 208 | self.graph_ax.clear()
|
194 | 209 | if len(self.names) < len(graphs): self.names += [''] * (len(graphs) - len(self.names))
|
195 | 210 | for g,n in zip(graphs,self.names): self.graph_ax.plot(*g, label=n)
|
|
0 commit comments