From 97d47ef33bf40831e2224b0b363c392595a352c8 Mon Sep 17 00:00:00 2001 From: muzing Date: Mon, 18 Dec 2023 08:52:06 +0800 Subject: [PATCH] Use `open_dir_in_explorer()` --- src/py2exe_gui/Utilities/platform_specifc_funcs.py | 4 +++- src/py2exe_gui/__main__.py | 10 ++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/py2exe_gui/Utilities/platform_specifc_funcs.py b/src/py2exe_gui/Utilities/platform_specifc_funcs.py index d6de55e..0300f68 100644 --- a/src/py2exe_gui/Utilities/platform_specifc_funcs.py +++ b/src/py2exe_gui/Utilities/platform_specifc_funcs.py @@ -7,11 +7,13 @@ """ import subprocess +from pathlib import Path +from typing import Union from ..Constants import PLATFORM, RUNTIME_INFO -def open_dir_in_explorer(dir_path: str) -> None: +def open_dir_in_explorer(dir_path: Union[str, Path]) -> None: """ 在操作系统文件资源管理器中打开指定目录 \n :param dir_path: 待打开的目录路径 diff --git a/src/py2exe_gui/__main__.py b/src/py2exe_gui/__main__.py index 19bf4c3..8ff4ae4 100644 --- a/src/py2exe_gui/__main__.py +++ b/src/py2exe_gui/__main__.py @@ -2,7 +2,6 @@ # For details: https://github.com/muziing/Py2exe-GUI/blob/main/README.md#license import sys -from subprocess import call as subprocess_call from PySide6.QtCore import Slot from PySide6.QtGui import QCloseEvent @@ -11,6 +10,7 @@ from PySide6.QtWidgets import QApplication from .Constants import PLATFORM, RUNTIME_INFO # noqa from .Core import Packaging, PackagingTask # noqa from .Resources import COMPILED_RESOURCES # noqa +from .Utilities import open_dir_in_explorer # noqa from .Widgets import MainWindow, SubProcessDlg # noqa @@ -83,13 +83,7 @@ class MainApp(MainWindow): self.subprocess_dlg.close() elif btn_text == "打开输出位置": dist_path = self.packaging_task.script_path.parent / "dist" - if PLATFORM.windows == RUNTIME_INFO.platform: - from os import startfile as os_startfile # fmt: skip - os_startfile(dist_path) # noqa - elif PLATFORM.linux == RUNTIME_INFO.platform: - subprocess_call(["xdg-open", dist_path]) - elif PLATFORM.macos == RUNTIME_INFO.platform: - subprocess_call(["open", dist_path]) + open_dir_in_explorer(dist_path) elif btn_text == "关闭": self.subprocess_dlg.close()