Skip to content

Commit

Permalink
fixed suboptimal usage of ipywidgets.Output widget
Browse files Browse the repository at this point in the history
resolves #140
  • Loading branch information
Brennen Raimer authored and norweeg committed Nov 24, 2020
1 parent 36a4d0d commit 58c0080
Showing 1 changed file with 14 additions and 35 deletions.
49 changes: 14 additions & 35 deletions halo/halo_notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,23 @@ def _make_output_widget(self):

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)
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 @@ -114,31 +111,13 @@ def stop_and_persist(self, symbol=" ", text=None):

self.stop()

output = "\r{} {}\n".format(
*[(text, symbol) if self._placement == "right" else (symbol, text)][0]
)
output = '\r{} {}\n'.format(*[
(text, symbol)
if self._placement == 'right' else
(symbol, text)
][0])

self.output.clear_output(wait=True)

with self.output:
self.output.outputs = self._output(output)

def _get_spinner(self, spinner):
"""Extracts spinner value from options and returns value
containing spinner frames and interval, defaults to 'dots' spinner.
Parameters
----------
spinner : dict, str
Contains spinner value or type of spinner to be used
Returns
-------
dict
Contains frames and interval defining spinner
"""
default_spinner = Spinners['dots'].value

if spinner and type(spinner) == dict:
return spinner

if all([is_text_type(spinner), spinner in Spinners.__members__]):
return Spinners[spinner].value
else:
return default_spinner
print(output, end="")

0 comments on commit 58c0080

Please sign in to comment.