Skip to content

Commit

Permalink
fixed suboptimal usage of ipywidgets.Output widget
Browse files Browse the repository at this point in the history
  • Loading branch information
Brennen Raimer committed Mar 7, 2020
1 parent e773f3b commit 95e6828
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions halo/halo_notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,23 @@ def _make_output_widget(self):
from ipywidgets.widgets import Output
return Output()

# TODO: using property and setter
def _output(self, text=''):
return ({'name': 'stdout', 'output_type': 'stream', 'text': text},)

def clear(self):
if not self.enabled:
return self

with self.output:
self.output.outputs += self._output('\r')
self.output.outputs += self._output(self.CLEAR_LINE)
print('\r', end="")
print(self.CLEAR_LINE, end="")

self.output.outputs = self._output()
return self

def _render_frame(self):
self.output.clear_output(wait=True)
frame = self.frame()
output = '\r{}'.format(frame)

with self.output:
self.output.outputs += self._output(output)
print(output, end="")

def start(self, text=None):
if text is not None:
Expand Down Expand Up @@ -105,6 +102,8 @@ def stop_and_persist(self, symbol=' ', text=None):
if self._placement == 'right' else
(symbol, text)
][0])

self.output.clear_output(wait=True)

with self.output:
self.output.outputs = self._output(output)
print(output, end="")

0 comments on commit 95e6828

Please sign in to comment.