From 641c142e9a2b6043649c9bf536ec7668aa8da273 Mon Sep 17 00:00:00 2001 From: muzing Date: Tue, 6 Feb 2024 17:22:40 +0800 Subject: [PATCH] Reformat code with black --- dev_scripts/build.py | 5 +++- src/py2exe_gui/Core/packaging_task.py | 27 ++++++++++--------- src/py2exe_gui/Core/subprocess_tool.py | 8 ++++-- src/py2exe_gui/Widgets/add_data_widget.py | 3 ++- src/py2exe_gui/Widgets/arguments_browser.py | 9 ++++--- src/py2exe_gui/Widgets/main_window.py | 4 ++- .../Widgets/multi_item_edit_widget.py | 3 ++- src/py2exe_gui/Widgets/subprocess_widget.py | 3 ++- 8 files changed, 38 insertions(+), 24 deletions(-) diff --git a/dev_scripts/build.py b/dev_scripts/build.py index 7029ce6..dfbb83e 100644 --- a/dev_scripts/build.py +++ b/dev_scripts/build.py @@ -39,7 +39,10 @@ def export_requirements() -> int: print(f"poetry export 进程错误:{e}") raise e else: - print(f"已将当前项目依赖导出至 requirements.txt,poetry export 返回码:{result.returncode}") + print( + "已将当前项目依赖导出至 requirements.txt," + f"poetry export 返回码:{result.returncode}" + ) return result.returncode diff --git a/src/py2exe_gui/Core/packaging_task.py b/src/py2exe_gui/Core/packaging_task.py index 538d821..0f03def 100644 --- a/src/py2exe_gui/Core/packaging_task.py +++ b/src/py2exe_gui/Core/packaging_task.py @@ -42,19 +42,19 @@ class PackagingTask(QtCore.QObject): # 保存打包时使用的 Python 环境 self.pyenv: Optional[PyEnv] = None - # 保存所有参数值,None表示未设置 + # 保存所有参数值,None 表示未设置 self.using_option: dict[PyInstOpt, Any] = {value: None for value in PyInstOpt} - # TODO: 设法为值补充类型注解 - - # self.script_path: Optional[Path] = None - # self.icon_path: Optional[Path] = None - # self.add_data_list: Optional[list[AddDataWindow.data_item]] = None - # self.add_binary_list: Optional[list[AddDataWindow.data_item]] = None - # self.out_name: Optional[str] = None - # self.FD: Optional[bool] = None - # self.console: Optional[str] = None - # self.hidden_import: Optional[list[str]] = None - # self.clean: Optional[bool] = None + # self.using_option = { + # PyInstOpt.script_path: Path, + # PyInstOpt.icon_path: Path, + # PyInstOpt.FD: bool, + # PyInstOpt.console: str, + # PyInstOpt.out_name: str, + # PyInstOpt.add_data: list[tuple[Path, str]], + # PyInstOpt.add_binary: list[tuple[Path, str]], + # PyInstOpt.hidden_import: list[str], + # PyInstOpt.clean: bool, + # } @QtCore.Slot(tuple) def on_opt_selected(self, option: tuple[PyInstOpt, Any]) -> None: @@ -73,7 +73,8 @@ class PackagingTask(QtCore.QObject): self.using_option[PyInstOpt.script_path] = script_path self.ready_to_pack.emit(True) self.option_set.emit(option) - self.using_option[PyInstOpt.out_name] = script_path.stem # 输出名默认与脚本名相同 + # 输出名默认与脚本名相同 + self.using_option[PyInstOpt.out_name] = script_path.stem self.option_set.emit((PyInstOpt.out_name, script_path.stem)) else: self.ready_to_pack.emit(False) diff --git a/src/py2exe_gui/Core/subprocess_tool.py b/src/py2exe_gui/Core/subprocess_tool.py index 3f892df..d663dae 100644 --- a/src/py2exe_gui/Core/subprocess_tool.py +++ b/src/py2exe_gui/Core/subprocess_tool.py @@ -87,7 +87,9 @@ class SubProcessTool(QObject): self._connect_signals() self._process.setWorkingDirectory(self._working_directory) self._process.start(self.program, self._arguments, mode) - return self._process.waitForStarted(time_out) # 阻塞,直到成功启动子进程或超时 + return self._process.waitForStarted( + time_out + ) # 阻塞,直到成功启动子进程或超时 return False def abort_process(self, timeout: int = 5000) -> bool: @@ -99,7 +101,9 @@ class SubProcessTool(QObject): if self._process: self._process.terminate() - is_finished = self._process.waitForFinished(timeout) # 阻塞,直到进程终止或超时 + is_finished = self._process.waitForFinished( + timeout + ) # 阻塞,直到进程终止或超时 if not is_finished: self._process.kill() # 超时后杀死子进程 return is_finished diff --git a/src/py2exe_gui/Widgets/add_data_widget.py b/src/py2exe_gui/Widgets/add_data_widget.py index 9d1c7d9..0ad754e 100644 --- a/src/py2exe_gui/Widgets/add_data_widget.py +++ b/src/py2exe_gui/Widgets/add_data_widget.py @@ -29,7 +29,8 @@ class AddDataWindow(QObjTr, QWidget): """用于提供 PyInstaller --add-data 和 --add-binary 功能的窗口""" # 类型别名 - data_item = tuple[Path, str] # 数据条目,第一项为在文件系统中的路径,第二项为捆绑后环境中的路径 + # 数据条目,第一项为在文件系统中的路径,第二项为捆绑后环境中的路径 + data_item = tuple[Path, str] # 自定义信号 data_selected = Signal(list) # 用户在添加数据窗口完成所有编辑后,提交的信号 diff --git a/src/py2exe_gui/Widgets/arguments_browser.py b/src/py2exe_gui/Widgets/arguments_browser.py index c55ddba..8317e42 100644 --- a/src/py2exe_gui/Widgets/arguments_browser.py +++ b/src/py2exe_gui/Widgets/arguments_browser.py @@ -78,13 +78,13 @@ class ArgumentsBrowser(QObjTr, QTextBrowser): def _handle_copy_action(self) -> None: """处理复制事件""" - # TODO 实现复制到系统剪切板 + self.selectAll() self.copy() def _handle_export_action(self) -> None: """处理导出事件""" - # TODO 实现到处到 PowerShell/Bash 脚本 + # TODO 实现导出至 PowerShell/Bash 脚本 pass def enrich_args_text(self, args_list: list[str]) -> None: @@ -93,7 +93,7 @@ class ArgumentsBrowser(QObjTr, QTextBrowser): :param args_list: 参数列表 """ - # 不间断换行(续行)符 + # 不间断换行 line_continuation = get_line_continuation() + "
" + (" " * 4) # 首个参数一定为待打包的 Python 脚本名 @@ -101,7 +101,8 @@ class ArgumentsBrowser(QObjTr, QTextBrowser): for arg in args_list[1:]: if arg.startswith("--") or arg.startswith("-"): - enriched_arg_texts.append(line_continuation) # 添加换行,便于阅读与复制导出脚本 + # 添加换行,便于阅读与复制导出脚本 + enriched_arg_texts.append(line_continuation) enriched_arg_texts.append(wrap_font_tag(arg, color=colors[1])) else: enriched_arg_texts.append(arg) diff --git a/src/py2exe_gui/Widgets/main_window.py b/src/py2exe_gui/Widgets/main_window.py index 34e543b..a89f021 100644 --- a/src/py2exe_gui/Widgets/main_window.py +++ b/src/py2exe_gui/Widgets/main_window.py @@ -65,7 +65,9 @@ class MainWindow(QObjTr, QMainWindow): """配置主窗口菜单栏""" file_menu = self.menu_bar.addMenu(MainWindow.tr("&File")) - file_menu.addAction(MainWindow.tr("Import Config From JSON File")) # 暂时只为占位 + file_menu.addAction( + MainWindow.tr("Import Config From JSON File") + ) # 暂时只为占位 file_menu.addAction(MainWindow.tr("Export Config To JSON File")) # 暂时只为占位 file_menu.addSeparator() file_menu.addAction(MainWindow.tr("&Settings")) # 暂时只为占位 diff --git a/src/py2exe_gui/Widgets/multi_item_edit_widget.py b/src/py2exe_gui/Widgets/multi_item_edit_widget.py index 3e7b33c..37fdcd8 100644 --- a/src/py2exe_gui/Widgets/multi_item_edit_widget.py +++ b/src/py2exe_gui/Widgets/multi_item_edit_widget.py @@ -33,7 +33,8 @@ from .dialog_widgets import PkgBrowserDlg class MultiItemEditWindow(QObjTr, QWidget): """用于添加多个条目的窗口控件,实现如 --hidden-import、--collect-submodules 等功能""" - items_selected = Signal(list) # 用户在添加条目窗口完成所有编辑后,提交的信号.完整数据类型为 list[str] + # 用户在添加条目窗口完成所有编辑后,提交的信号.完整数据类型为 list[str] + items_selected = Signal(list) def __init__(self, parent: Optional[QWidget] = None) -> None: """ diff --git a/src/py2exe_gui/Widgets/subprocess_widget.py b/src/py2exe_gui/Widgets/subprocess_widget.py index 56ef438..802d7a4 100644 --- a/src/py2exe_gui/Widgets/subprocess_widget.py +++ b/src/py2exe_gui/Widgets/subprocess_widget.py @@ -33,7 +33,8 @@ class SubProcessDlg(QObjTr, QDialog): self.info_label = QLabel(self) self.text_browser = QTextBrowser(self) # 用于显示子进程输出内容 - self.multifunction_btn = QPushButton(self) # 可用于“取消”“打开输出位置”等的多功能按钮 + # 可用于“取消”“打开输出位置”等的多功能按钮 + self.multifunction_btn = QPushButton(self) self._setup() def _setup(self) -> None: