Set the progress of progress bar :param str name: The name of the progress bar :param float value: The progress value of the progress bar. The value is between 0 and 1 :param str label: The label of progress bar. The default is the percentage value of the current progress. See also
(name: str, value: float, label: str = None)
| 1017 | |
| 1018 | |
| 1019 | def set_progressbar(name: str, value: float, label: str = None): |
| 1020 | """Set the progress of progress bar |
| 1021 | |
| 1022 | :param str name: The name of the progress bar |
| 1023 | :param float value: The progress value of the progress bar. The value is between 0 and 1 |
| 1024 | :param str label: The label of progress bar. The default is the percentage value of the current progress. |
| 1025 | |
| 1026 | See also: `put_progressbar()` |
| 1027 | """ |
| 1028 | from pywebio.session import run_js |
| 1029 | |
| 1030 | check_dom_name_value(name) |
| 1031 | |
| 1032 | progressbar_id = 'webio-progressbar-%s' % name |
| 1033 | percentage = value * 100 |
| 1034 | label = '%.1f%%' % percentage if label is None else label |
| 1035 | |
| 1036 | js_code = """ |
| 1037 | let bar = $("#{progressbar_id}"); |
| 1038 | bar[0].style.width = "{percentage}%"; |
| 1039 | bar.attr("aria-valuenow", "{value}"); |
| 1040 | bar.text({label!r}); |
| 1041 | """.format(progressbar_id=progressbar_id, percentage=percentage, value=value, label=label) |
| 1042 | if value == 1: |
| 1043 | js_code += "if(bar.data('autoClose')=='1')bar.parent().remove();" |
| 1044 | |
| 1045 | run_js(js_code) |
| 1046 | |
| 1047 | |
| 1048 | put_processbar = put_progressbar |
nothing calls this directly
no test coverage detected
searching dependent graphs…