Skip to content

Commit 89b642c

Browse files
committed
Add scripts of constants
将在多处用到的常量提取至单独的常量模块中; 修改 `pyinstaller_args` 存储的数据结构(仍待进一步完善);
1 parent b21f7a8 commit 89b642c

5 files changed

Lines changed: 52 additions & 22 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .app_constants import *
2+
from .packaging_constants import *
3+
# from .type_constants import *
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"""
2+
应用程序级的常量
3+
"""
4+
5+
NAME = "Py2exe-GUI"
6+
VERSION = "0.1.3"
7+
AUTHORS = ["muzing <muzi2001@foxmail.com>"]
8+
LICENSE = "GPL-3.0-or-later"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""
2+
打包相关的常量
3+
"""
4+
5+
# TODO 优化打包选项列表的数据结构
6+
7+
pyinstaller_args_list: list = [
8+
"script_path",
9+
"icon_path",
10+
"FD",
11+
"console",
12+
"out_name",
13+
]
14+
15+
16+
class PyinstallerArgs:
17+
script_path = "script_path"
18+
icon_path = "icon_path"
19+
FD = "FD"
20+
console = "console"
21+
out_name = "out_name"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"""
2+
自定义的数据类型,用于Mypy静态类型检查
3+
"""
4+
5+
import typing

src/py2exe_gui/Core/packaging.py

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,9 @@
22

33
from PySide6 import QtCore
44

5+
from ..Constants.packaging_constants import *
56
from .subprocess_tool import SubProcessTool
67

7-
pyinstaller_args: list = [
8-
"script_path",
9-
"icon_path",
10-
"FD",
11-
"console",
12-
"out_name",
13-
]
14-
158

169
class Packaging(QtCore.QObject):
1710
"""
@@ -28,7 +21,7 @@ def __init__(self, parent: Optional[QtCore.QObject] = None) -> None:
2821

2922
super(Packaging, self).__init__(parent)
3023

31-
self.args_dict: dict = dict.fromkeys(pyinstaller_args, "")
24+
self.args_dict: dict = dict.fromkeys(pyinstaller_args_list, "")
3225
self._args: List[str] = []
3326
self.subprocess: SubProcessTool = SubProcessTool(self, program="pyinstaller")
3427

@@ -40,8 +33,8 @@ def set_pyinstaller_args(self, arg: tuple[str, str]) -> None:
4033
"""
4134

4235
arg_key, arg_value = arg
43-
if arg_key in self.args_dict.keys():
44-
self.args_dict[arg_key] = arg_value
36+
# if arg_key in pyinstaller_args_list:
37+
self.args_dict[arg_key] = arg_value
4538
self._add_pyinstaller_args()
4639

4740
def _add_pyinstaller_args(self) -> None:
@@ -50,21 +43,21 @@ def _add_pyinstaller_args(self) -> None:
5043
"""
5144

5245
self._args = [] # 避免重复添加
53-
self._args.extend([self.args_dict["script_path"]])
54-
if self.args_dict["icon_path"]:
55-
self._args.extend(["--icon", self.args_dict["icon_path"]])
56-
if self.args_dict["FD"]:
57-
if self.args_dict["FD"] == "One Dir":
46+
self._args.extend([self.args_dict[PyinstallerArgs.script_path]])
47+
if self.args_dict[PyinstallerArgs.icon_path]:
48+
self._args.extend(["--icon", self.args_dict[PyinstallerArgs.icon_path]])
49+
if self.args_dict[PyinstallerArgs.FD]:
50+
if self.args_dict[PyinstallerArgs.FD] == "One Dir":
5851
self._args.extend(["--onedir"])
59-
elif self.args_dict["FD"] == "One File":
52+
elif self.args_dict[PyinstallerArgs.FD] == "One File":
6053
self._args.extend(["--onefile"])
61-
if self.args_dict["console"]:
62-
if self.args_dict["console"] == "console":
54+
if self.args_dict[PyinstallerArgs.console]:
55+
if self.args_dict[PyinstallerArgs.console] == "console":
6356
self._args.extend(["--console"])
64-
elif self.args_dict["console"] == "windowed":
57+
elif self.args_dict[PyinstallerArgs.console] == "windowed":
6558
self._args.extend(["--windowed"])
66-
if self.args_dict["out_name"]:
67-
self._args.extend(["--name", self.args_dict["out_name"]])
59+
if self.args_dict[PyinstallerArgs.out_name]:
60+
self._args.extend(["--name", self.args_dict[PyinstallerArgs.out_name]])
6861

6962
self.args_settled.emit(self._args)
7063

0 commit comments

Comments
 (0)