|
42 | 42 | | +---------------------------+------------------------------------------------------------+
|
43 | 43 | | | `put_link` | Output link |
|
44 | 44 | | +---------------------------+------------------------------------------------------------+
|
45 |
| -| | `put_processbar` | Output a process bar | |
| 45 | +| | `put_progressbar` | Output a progress bar | |
46 | 46 | | +---------------------------+------------------------------------------------------------+
|
47 | 47 | | | `put_loading`:sup:`†` | Output loading prompt |
|
48 | 48 | | +---------------------------+------------------------------------------------------------+
|
|
173 | 173 |
|
174 | 174 | .. autofunction:: put_html
|
175 | 175 | .. autofunction:: put_link
|
176 |
| -.. autofunction:: put_processbar |
177 |
| -.. autofunction:: set_processbar |
| 176 | +.. autofunction:: put_progressbar |
| 177 | +.. autofunction:: set_progressbar |
178 | 178 | .. autofunction:: put_loading
|
179 | 179 | .. autofunction:: put_code
|
180 | 180 | .. autofunction:: put_table
|
|
226 | 226 |
|
227 | 227 | logger = logging.getLogger(__name__)
|
228 | 228 |
|
229 |
| -__all__ = ['Position', 'remove', 'scroll_to', 'put_tabs', 'put_scope', |
| 229 | +__all__ = ['Position', 'OutputPosition', 'remove', 'scroll_to', 'put_tabs', 'put_scope', |
230 | 230 | 'put_text', 'put_html', 'put_code', 'put_markdown', 'use_scope', 'set_scope', 'clear', 'remove',
|
231 | 231 | 'put_table', 'put_buttons', 'put_image', 'put_file', 'PopupSize', 'popup', 'put_button',
|
232 | 232 | 'close_popup', 'put_widget', 'put_collapse', 'put_link', 'put_scrollable', 'style', 'put_column',
|
233 |
| - 'put_row', 'put_grid', 'span', 'put_processbar', 'set_processbar', 'put_loading', |
234 |
| - 'output', 'toast', 'get_scope', 'put_info', 'put_error', 'put_warning', 'put_success'] |
| 233 | + 'put_row', 'put_grid', 'span', 'put_progressbar', 'set_progressbar', 'put_processbar', 'set_processbar', |
| 234 | + 'put_loading', 'output', 'toast', 'get_scope', 'put_info', 'put_error', 'put_warning', 'put_success'] |
235 | 235 |
|
236 | 236 |
|
237 | 237 | # popup size
|
@@ -958,74 +958,78 @@ def put_link(name: str, url: str = None, app: str = None, new_window: bool = Fal
|
958 | 958 | return put_html(tag, scope=scope, position=position)
|
959 | 959 |
|
960 | 960 |
|
961 |
| -def put_processbar(name: str, init: float = 0, label: str = None, auto_close: bool = False, scope: str = None, |
962 |
| - position: int = OutputPosition.BOTTOM) -> Output: |
963 |
| - """Output a process bar |
| 961 | +def put_progressbar(name: str, init: float = 0, label: str = None, auto_close: bool = False, scope: str = None, |
| 962 | + position: int = OutputPosition.BOTTOM) -> Output: |
| 963 | + """Output a progress bar |
964 | 964 |
|
965 | 965 | :param str name: The name of the progress bar, which is the unique identifier of the progress bar
|
966 | 966 | :param float init: The initial progress value of the progress bar. The value is between 0 and 1
|
967 |
| - :param str label: The label of process bar. The default is the percentage value of the current progress. |
| 967 | + :param str label: The label of progress bar. The default is the percentage value of the current progress. |
968 | 968 | :param bool auto_close: Whether to remove the progress bar after the progress is completed
|
969 | 969 | :param int scope, position: Those arguments have the same meaning as for `put_text()`
|
970 | 970 |
|
971 | 971 | Example:
|
972 | 972 |
|
973 | 973 | .. exportable-codeblock::
|
974 |
| - :name: put_processbar |
975 |
| - :summary: `put_processbar()` usage |
| 974 | + :name: put_progressbar |
| 975 | + :summary: `put_progressbar()` usage |
976 | 976 |
|
977 | 977 | import time
|
978 | 978 |
|
979 |
| - put_processbar('bar'); |
| 979 | + put_progressbar('bar'); |
980 | 980 | for i in range(1, 11):
|
981 |
| - set_processbar('bar', i / 10) |
| 981 | + set_progressbar('bar', i / 10) |
982 | 982 | time.sleep(0.1)
|
983 | 983 |
|
984 |
| - .. seealso:: use `set_processbar()` to set the progress of progress bar |
| 984 | + .. seealso:: use `set_progressbar()` to set the progress of progress bar |
985 | 985 | """
|
986 | 986 | check_dom_name_value(name)
|
987 |
| - processbar_id = 'webio-processbar-%s' % name |
| 987 | + progressbar_id = 'webio-progressbar-%s' % name |
988 | 988 | percentage = init * 100
|
989 | 989 | label = '%.1f%%' % percentage if label is None else label
|
990 | 990 | tpl = """<div class="progress" style="margin-top: 4px;">
|
991 | 991 | <div id="{{elem_id}}" class="progress-bar bg-info progress-bar-striped progress-bar-animated" role="progressbar"
|
992 | 992 | style="width: {{percentage}}%;" aria-valuenow="{{init}}" aria-valuemin="0" aria-valuemax="1" data-auto-close="{{auto_close}}">{{label}}
|
993 | 993 | </div>
|
994 | 994 | </div>"""
|
995 |
| - return put_widget(tpl, data=dict(elem_id=processbar_id, init=init, label=label, |
| 995 | + return put_widget(tpl, data=dict(elem_id=progressbar_id, init=init, label=label, |
996 | 996 | percentage=percentage, auto_close=int(bool(auto_close))), scope=scope,
|
997 | 997 | position=position)
|
998 | 998 |
|
999 | 999 |
|
1000 |
| -def set_processbar(name: str, value: float, label: str = None): |
| 1000 | +def set_progressbar(name: str, value: float, label: str = None): |
1001 | 1001 | """Set the progress of progress bar
|
1002 | 1002 |
|
1003 | 1003 | :param str name: The name of the progress bar
|
1004 | 1004 | :param float value: The progress value of the progress bar. The value is between 0 and 1
|
1005 |
| - :param str label: The label of process bar. The default is the percentage value of the current progress. |
| 1005 | + :param str label: The label of progress bar. The default is the percentage value of the current progress. |
1006 | 1006 |
|
1007 |
| - See also: `put_processbar()` |
| 1007 | + See also: `put_progressbar()` |
1008 | 1008 | """
|
1009 | 1009 | from pywebio.session import run_js
|
1010 | 1010 |
|
1011 | 1011 | check_dom_name_value(name)
|
1012 | 1012 |
|
1013 |
| - processbar_id = 'webio-processbar-%s' % name |
| 1013 | + progressbar_id = 'webio-progressbar-%s' % name |
1014 | 1014 | percentage = value * 100
|
1015 | 1015 | label = '%.1f%%' % percentage if label is None else label
|
1016 | 1016 |
|
1017 | 1017 | js_code = """
|
1018 |
| - let bar = $("#{processbar_id}"); |
| 1018 | + let bar = $("#{progressbar_id}"); |
1019 | 1019 | bar[0].style.width = "{percentage}%";
|
1020 | 1020 | bar.attr("aria-valuenow", "{value}");
|
1021 | 1021 | bar.text({label!r});
|
1022 |
| - """.format(processbar_id=processbar_id, percentage=percentage, value=value, label=label) |
| 1022 | + """.format(progressbar_id=progressbar_id, percentage=percentage, value=value, label=label) |
1023 | 1023 | if value == 1:
|
1024 | 1024 | js_code += "if(bar.data('autoClose')=='1')bar.parent().remove();"
|
1025 | 1025 |
|
1026 | 1026 | run_js(js_code)
|
1027 | 1027 |
|
1028 | 1028 |
|
| 1029 | +put_processbar = put_progressbar |
| 1030 | +set_processbar = set_progressbar |
| 1031 | + |
| 1032 | + |
1029 | 1033 | def put_loading(shape: str = 'border', color: str = 'dark', scope: str = None,
|
1030 | 1034 | position: int = OutputPosition.BOTTOM) -> Output:
|
1031 | 1035 | """Output loading prompt
|
|
0 commit comments