mirror of
https://github.com/muziing/Py2exe-GUI.git
synced 2025-01-27 17:02:55 +08:00
Add platform_constants
添加运行平台相关的常量,使相关接口更统一;
This commit is contained in:
parent
fc89196bea
commit
4f43837065
@ -1,3 +1,4 @@
|
||||
from .app_constants import *
|
||||
from .packaging_constants import *
|
||||
# from .type_constants import *
|
||||
from .platform_constants import *
|
||||
from .type_constants import *
|
||||
|
28
src/py2exe_gui/Constants/platform_constants.py
Normal file
28
src/py2exe_gui/Constants/platform_constants.py
Normal file
@ -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
|
@ -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)
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user