From cd177cbba89fe87ba81f377b3bdd08ec9ec577fc Mon Sep 17 00:00:00 2001 From: muzing Date: Fri, 8 Dec 2023 01:50:05 +0800 Subject: [PATCH] Update `ArgumentsBrowser` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 更新 `ArgumentsBrowser`: 将显示的PyInstaller命令参数从列表转换为字符串,用户可直接复制字符串到终端中运行或保存为脚本; 添加命令行换行,提高命令可读性; --- src/py2exe_gui/Widgets/arguments_browser.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/py2exe_gui/Widgets/arguments_browser.py b/src/py2exe_gui/Widgets/arguments_browser.py index 7d969ef..8b4dafa 100644 --- a/src/py2exe_gui/Widgets/arguments_browser.py +++ b/src/py2exe_gui/Widgets/arguments_browser.py @@ -5,11 +5,13 @@ from typing import Optional from PySide6.QtWidgets import QTextBrowser, QWidget +from ..Constants import get_line_continuation + # 一组适合浅色背景的颜色 colors = ["#FD6D5A", "#FEB40B", "#6DC354", "#994487", "#518CD8", "#443295"] -def wrap_font_tag(raw_text: str, color: str, **kwargs): +def wrap_font_tag(raw_text: str, *, color: str, **kwargs): """ 辅助函数,用于为字符添加标签包裹,属性可通过可变关键字参数传入 \n :param raw_text: 原始字符文本 @@ -40,11 +42,16 @@ class ArgumentsBrowser(QTextBrowser): :param args_list: 参数列表 """ - text: list[str] = [wrap_font_tag(args_list[0], colors[4])] + enriched_arg_texts: list[str] = [ + wrap_font_tag(args_list[0], color=colors[4]) + ] # 首个参数一定为待打包的 Python 脚本名 for arg in args_list[1:]: if arg.startswith("--") or arg.startswith("-"): - text.append(wrap_font_tag(arg, colors[1])) + enriched_arg_texts.append( + get_line_continuation() + "
" + ) # 添加换行,便于阅读与复制导出脚本 + enriched_arg_texts.append(wrap_font_tag(arg, color=colors[1])) else: - text.append(arg) + enriched_arg_texts.append(arg) - self.setText(str(text)) + self.setText("pyinstaller " + " ".join(enriched_arg_texts))