diff --git a/src/py2exe_gui/Constants/__init__.py b/src/py2exe_gui/Constants/__init__.py index e5a72d7..4ebb57a 100644 --- a/src/py2exe_gui/Constants/__init__.py +++ b/src/py2exe_gui/Constants/__init__.py @@ -1,3 +1,4 @@ from .app_constants import * from .packaging_constants import * -# from .type_constants import * +from .platform_constants import * +from .type_constants import * diff --git a/src/py2exe_gui/Constants/platform_constants.py b/src/py2exe_gui/Constants/platform_constants.py new file mode 100644 index 0000000..87c2e39 --- /dev/null +++ b/src/py2exe_gui/Constants/platform_constants.py @@ -0,0 +1,28 @@ +import sys + + +class PLATFORM: + """ + 运行平台相关的常量 \n + """ + + windows = "Windows" + linux = "Linux" + macos = "macOS" + others = "others" + + +def get_platform() -> str: + """ + 辅助函数,用于获取当前运行的平台 \n + :return: platform + """ + + if sys.platform.startswith("win32"): + return PLATFORM.windows + elif sys.platform.startswith("linux"): + return PLATFORM.linux + elif sys.platform.startswith("darwin"): + return PLATFORM.macos + else: + return PLATFORM.others diff --git a/src/py2exe_gui/Widgets/center_widget.py b/src/py2exe_gui/Widgets/center_widget.py index 492af2f..6bf2eee 100644 --- a/src/py2exe_gui/Widgets/center_widget.py +++ b/src/py2exe_gui/Widgets/center_widget.py @@ -16,6 +16,7 @@ from PySide6.QtWidgets import ( ) from ..Constants.packaging_constants import PyinstallerArgs +from ..Constants.platform_constants import PLATFORM from .arguments_browser import ArgumentsBrowser from .dialog_widgets import IconFileDlg, ScriptFileDlg @@ -52,14 +53,14 @@ class CenterWidget(QWidget): self.fd_group = QButtonGroup() # 应用图标(仅 Windows 与 macOS) - if self.parent().running_platform in ("Windows", "macOS"): + if self.parent().running_platform in (PLATFORM.windows, PLATFORM.macos): self.icon_path_label = QLabel() self.icon_file_dlg = IconFileDlg() self.icon_browse_btn = QPushButton() self.icon_path_le = QLineEdit() # 是否为stdio启用终端(仅 Windows 与 macOS) - if self.parent().running_platform in ("Windows", "macOS"): + if self.parent().running_platform in (PLATFORM.windows, PLATFORM.macos): self.console_checkbox = QCheckBox() # 预览生成的PyInstaller打包指令 @@ -92,7 +93,7 @@ class CenterWidget(QWidget): self.fd_group.addButton(self.one_dir_btn, 0) self.fd_group.addButton(self.one_file_btn, 1) - if self.parent().running_platform in ("Windows", "macOS"): + if self.parent().running_platform in (PLATFORM.windows, PLATFORM.macos): self.icon_path_label.setText("应用图标:") self.icon_path_le.setReadOnly(True) self.icon_path_le.setPlaceholderText("图标文件路径") @@ -182,7 +183,7 @@ class CenterWidget(QWidget): self.fd_group.idClicked.connect(one_fd_selected) # type: ignore self.run_packaging_btn.clicked.connect(run_packaging) # type: ignore - if self.parent().running_platform in ("Windows", "macOS"): + if self.parent().running_platform in (PLATFORM.windows, PLATFORM.macos): self.icon_browse_btn.clicked.connect(self.icon_file_dlg.open) # type: ignore self.icon_file_dlg.fileSelected.connect(icon_file_selected) # type: ignore self.console_checkbox.toggled.connect(console_selected) # type: ignore @@ -289,7 +290,7 @@ class CenterWidget(QWidget): main_layout.addLayout(fd_layout) main_layout.addSpacing(10) - if self.parent().running_platform in ("Windows", "macOS"): + if self.parent().running_platform in (PLATFORM.windows, PLATFORM.macos): main_layout.addWidget(self.console_checkbox) main_layout.addSpacing(10) diff --git a/src/py2exe_gui/__main__.py b/src/py2exe_gui/__main__.py index c1bba45..843337b 100644 --- a/src/py2exe_gui/__main__.py +++ b/src/py2exe_gui/__main__.py @@ -3,28 +3,12 @@ import sys from PySide6 import QtGui from PySide6.QtWidgets import QApplication +from .Constants.platform_constants import get_platform from .Core import Packaging, PackagingTask from .Resources.compiled_resources import * from .Widgets import MainWindow, SubProcessDlg -# TODO 将此辅助函数移至他处、将返回值保存到常量中而非普通字符串 -def get_platform() -> str: - """ - 辅助函数,用于获取当前运行的平台 \n - :return: platform - """ - - if sys.platform.startswith("win32"): - return "Windows" - elif sys.platform.startswith("linux"): - return "Linux" - elif sys.platform.startswith("darwin"): - return "macOS" - else: - return "others" - - class MainApp(MainWindow): """ 应用主程序 \n