Skip to content

Commit 9529398

Browse files
authored
improve the style of the live_info widget, closes #250 (#251)
Based on the default style of the Jupyterlab table.
1 parent 0295879 commit 9529398

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

adaptive/notebook_integration.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -228,14 +228,16 @@ async def update():
228228

229229
runner.ioloop.create_task(update())
230230

231-
display(
232-
ipywidgets.HBox(
233-
(status, cancel),
234-
layout=ipywidgets.Layout(
235-
border="solid 1px", width="200px", align_items="center"
236-
),
237-
)
238-
)
231+
display(ipywidgets.VBox((status, cancel)))
232+
233+
234+
def _table_row(i, key, value):
235+
"""Style the rows of a table. Based on the default Jupyterlab table style."""
236+
style_odd = "text-align: right; padding: 0.5em 0.5em; line-height: 1.0;"
237+
style_even = style_odd + "background: var(--md-grey-100);"
238+
template = '<tr><th style="{style}">{key}</th><th style="{style}">{value}</th></tr>'
239+
style = style_odd if i % 2 == 1 else style_even
240+
return template.format(style=style, key=key, value=value)
239241

240242

241243
def _info_html(runner):
@@ -260,11 +262,10 @@ def _info_html(runner):
260262
with suppress(Exception):
261263
info.append(("latest loss", f'{runner.learner._cache["loss"]:.3f}'))
262264

263-
template = '<dt class="ignore-css">{}</dt><dd>{}</dd>'
264-
table = "\n".join(template.format(k, v) for k, v in info)
265+
table = "\n".join(_table_row(i, k, v) for i, (k, v) in enumerate(info))
265266

266267
return f"""
267-
<dl>
268+
<table>
268269
{table}
269-
</dl>
270+
</table>
270271
"""

0 commit comments

Comments
 (0)