Skip to content

Commit ff685a2

Browse files
author
Brennen Raimer
committed
fixed suboptimal usage of ipywidgets.Output widget
resolves #140
1 parent fd6d5fb commit ff685a2

File tree

1 file changed

+14
-35
lines changed

1 file changed

+14
-35
lines changed

halo/halo_notebook.py

Lines changed: 14 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,23 @@ def _make_output_widget(self):
4040

4141
return Output()
4242

43-
# TODO: using property and setter
44-
def _output(self, text=""):
45-
return ({"name": "stdout", "output_type": "stream", "text": text},)
46-
4743
def clear(self):
4844
if not self.enabled:
4945
return self
5046

5147
with self.output:
52-
self.output.outputs += self._output("\r")
53-
self.output.outputs += self._output(self.CLEAR_LINE)
48+
print('\r', end="")
49+
print(self.CLEAR_LINE, end="")
5450

55-
self.output.outputs = self._output()
5651
return self
5752

5853
def _render_frame(self):
54+
self.output.clear_output(wait=True)
5955
frame = self.frame()
60-
output = "\r{}".format(frame)
56+
output = '\r{}'.format(frame)
57+
6158
with self.output:
62-
self.output.outputs += self._output(output)
59+
print(output, end="")
6360

6461
def start(self, text=None):
6562
if text is not None:
@@ -114,31 +111,13 @@ def stop_and_persist(self, symbol=" ", text=None):
114111

115112
self.stop()
116113

117-
output = "\r{} {}\n".format(
118-
*[(text, symbol) if self._placement == "right" else (symbol, text)][0]
119-
)
114+
output = '\r{} {}\n'.format(*[
115+
(text, symbol)
116+
if self._placement == 'right' else
117+
(symbol, text)
118+
][0])
119+
120+
self.output.clear_output(wait=True)
120121

121122
with self.output:
122-
self.output.outputs = self._output(output)
123-
124-
def _get_spinner(self, spinner):
125-
"""Extracts spinner value from options and returns value
126-
containing spinner frames and interval, defaults to 'dots' spinner.
127-
Parameters
128-
----------
129-
spinner : dict, str
130-
Contains spinner value or type of spinner to be used
131-
Returns
132-
-------
133-
dict
134-
Contains frames and interval defining spinner
135-
"""
136-
default_spinner = Spinners['dots'].value
137-
138-
if spinner and type(spinner) == dict:
139-
return spinner
140-
141-
if all([is_text_type(spinner), spinner in Spinners.__members__]):
142-
return Spinners[spinner].value
143-
else:
144-
return default_spinner
123+
print(output, end="")

0 commit comments

Comments
 (0)