From dbb3f4c83fe4a0a5ae8109e823b64b888bfba78f Mon Sep 17 00:00:00 2001 From: EillesWan Date: Tue, 23 Jan 2024 18:36:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E5=B0=8F=E5=85=BC=E5=AE=B9=E6=80=A7bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Musicreater/plugin/main.py | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/Musicreater/plugin/main.py b/Musicreater/plugin/main.py index 8b726ae..bf467cc 100644 --- a/Musicreater/plugin/main.py +++ b/Musicreater/plugin/main.py @@ -19,7 +19,7 @@ Terms & Conditions: License.md in the root directory from dataclasses import dataclass from typing import Literal, Tuple, Union -from ..constants import DEFAULT_PROGRESSBAR_STYLE +from ..subclass import DEFAULT_PROGRESSBAR_STYLE, ProgressBarStyle @dataclass(init=False) @@ -34,8 +34,8 @@ class ConvertConfig: speed_multiplier: float """速度倍率""" - progressbar_style: Union[Tuple[str, Tuple[str, str]], Literal[None]] - """进度条样式组""" + progressbar_style: Union[ProgressBarStyle, None] + """进度条样式""" dist_path: str """输出目录""" @@ -45,7 +45,8 @@ class ConvertConfig: output_path: str, volume: float = 1.0, speed: float = 1.0, - progressbar: Union[bool, Tuple[str, Tuple[str, str]]] = True, + progressbar: Union[bool, Tuple[str, Tuple[str, str]], ProgressBarStyle] = True, + ignore_progressbar_param_error: bool = False, ): """ 将已经转换好的数据内容指令载入MC可读格式 @@ -77,10 +78,20 @@ class ConvertConfig: # 改这一段没🐎 if progressbar is True: self.progressbar_style = DEFAULT_PROGRESSBAR_STYLE - """进度条样式组""" - else: + """进度条样式""" + return + elif isinstance(progressbar, ProgressBarStyle): self.progressbar_style = progressbar - """进度条样式组""" - else: - self.progressbar_style = None - """进度条样式组""" + """进度条样式""" + return + elif isinstance(progressbar, tuple): + if isinstance(progressbar[0],str) and isinstance(progressbar[1], tuple): + if isinstance(progressbar[1][0], str) and isinstance(progressbar[1][1], str): + self.progressbar_style = ProgressBarStyle(progressbar[0],progressbar[1][0],progressbar[1][1]) + return + if not ignore_progressbar_param_error: + raise TypeError("参数 {} 的类型 {} 与所需类型 Union[bool, Tuple[str, Tuple[str, str]], ProgressBarStyle] 不符。".format(progressbar,type(progressbar))) + + self.progressbar_style = None + """进度条样式组""" +