From 14c1318432291b21f86bae50715d6ebbb0d0ee1f Mon Sep 17 00:00:00 2001 From: amks1 <68153785+amks1@users.noreply.github.com> Date: Sat, 20 Apr 2024 19:13:18 +0400 Subject: [PATCH] Added a `logbox_clear` function (#4) * Added logbox_clear function * add logbox_clear() to doc --------- Co-authored-by: WangWeimin --- pywebio_battery/__init__.py | 2 +- pywebio_battery/interaction.py | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pywebio_battery/__init__.py b/pywebio_battery/__init__.py index 88bef4a..faed832 100644 --- a/pywebio_battery/__init__.py +++ b/pywebio_battery/__init__.py @@ -35,7 +35,7 @@ * - `run_shell ` - Run command in shell - * - `put_logbox `, `logbox_append ` + * - `put_logbox `, `logbox_append `, `logbox_clear ` - Logbox widget * - `put_video ` diff --git a/pywebio_battery/interaction.py b/pywebio_battery/interaction.py index 94701d5..42180fa 100644 --- a/pywebio_battery/interaction.py +++ b/pywebio_battery/interaction.py @@ -12,8 +12,8 @@ from pywebio.session import * from pywebio.utils import random_str -__all__ = ['confirm', 'popup_input', 'redirect_stdout', 'run_shell', 'put_logbox', 'logbox_append', 'put_video', - 'put_audio', 'wait_scroll_to_bottom'] +__all__ = ['confirm', 'popup_input', 'redirect_stdout', 'run_shell', 'put_logbox', 'logbox_append', 'logbox_clear', + 'put_video', 'put_audio', 'wait_scroll_to_bottom'] def confirm( @@ -240,6 +240,11 @@ def logbox_append(name: str, text: str): run_js('$("#webio-logbox-%s").append(document.createTextNode(text))' % name, text=str(text)) +def logbox_clear(name: str): + """Clear all contents of a logbox widget""" + pywebio.session.run_js('$("#webio-logbox-%s").empty()' % name) + + def put_video(src: Union[str, bytes], autoplay: bool = False, loop: bool = False, height: int = None, width: int = None, muted: bool = False, poster: str = None, scope: str = None, position: int = OutputPosition.BOTTOM) -> Output: