Skip to content

Commit 9e5f0d5

Browse files
committed
Version 0.1.2
项目版本更新至 `0.1.2`; 规范统一文档字符串;
1 parent 5c4f673 commit 9e5f0d5

7 files changed

Lines changed: 69 additions & 47 deletions

File tree

src/py2exe_gui/Core/packaging.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
from typing import List, Optional
22

33
from PySide6 import QtCore
4-
from PySide6.QtCore import QObject
54

65
from .subprocess_tool import SubProcessTool
76

87

9-
class Packaging(QObject):
10-
"""执行打包的类"""
8+
class Packaging(QtCore.QObject):
9+
"""
10+
执行打包的类
11+
"""
1112

1213
# 自定义信号
1314
args_settled = QtCore.Signal(list)
1415

15-
def __init__(self, parent: Optional[QObject] = None):
16+
def __init__(self, parent: Optional[QtCore.QObject] = None) -> None:
17+
"""
18+
:param parent: 父控件对象
19+
"""
20+
1621
super(Packaging, self).__init__(parent)
1722
pyinstaller_args: list = [
1823
"script_path",
@@ -39,7 +44,6 @@ def set_pyinstaller_args(self, arg: tuple[str, str]) -> None:
3944
def _add_pyinstaller_args(self) -> None:
4045
"""
4146
将命令参数字典中的参数按顺序添加到命令参数列表中 \n
42-
:return: None
4347
"""
4448

4549
self._args = [] # 避免重复添加
@@ -64,9 +68,8 @@ def _add_pyinstaller_args(self) -> None:
6468
def run_packaging_process(self) -> None:
6569
"""
6670
使用给定的参数启动打包子进程 \n
67-
:return: None
6871
"""
6972

70-
# self._subprocess.output.connect(lambda val: print(val)) # 测试用
73+
# self.subprocess.output.connect(lambda val: print(val)) # 测试用
7174
self.subprocess.set_arguments(self._args)
7275
self.subprocess.start_process()

src/py2exe_gui/Core/subprocess_tool.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66

77

88
class SubProcessTool(QtCore.QObject):
9-
"""辅助QProcess使用的工具类,将所有直接对子进程进行的操作都封装在此类中"""
9+
"""
10+
辅助QProcess使用的工具类,将所有直接对子进程进行的操作都封装在此类中
11+
"""
1012

11-
# 自定义信号,参数为 tuple[output_type: SubProcessTool.output_type, output_text: str]
13+
# 自定义信号,参数为 tuple[output_type: int, output_text: str]
1214
output = QtCore.Signal(tuple)
1315

1416
# output_types
@@ -30,7 +32,6 @@ def __init__(
3032
:param program: 待运行的子进程
3133
:param arguments: 运行参数
3234
:param working_directory: 子进程工作目录
33-
:return: None
3435
"""
3536

3637
super(SubProcessTool, self).__init__(parent)
@@ -50,7 +51,6 @@ def start_process(
5051
"""
5152
创建并启动子进程 \n
5253
:param mode: 设备打开的模式
53-
:return: None
5454
"""
5555

5656
if self._process is None: # 防止在子进程运行结束前重复启动
@@ -87,7 +87,6 @@ def set_arguments(self, arguments: Sequence[str]) -> None:
8787
"""
8888
设置子进程参数 \n
8989
:param arguments: 参数列表
90-
:return: None
9190
"""
9291

9392
self._arguments = arguments
@@ -108,7 +107,6 @@ def set_working_dir(self, work_dir: str) -> bool:
108107
def _process_started(self) -> None:
109108
"""
110109
处理子进程开始的槽 \n
111-
:return: None
112110
"""
113111

114112
pass
@@ -118,7 +116,6 @@ def _process_finished(self, code: int, status: QtCore.QProcess.ExitStatus) -> No
118116
处理子进程结束的槽 \n
119117
:param code: 退出码
120118
:param status: 退出状态
121-
:return: None
122119
"""
123120

124121
self.exit_code = code
@@ -129,7 +126,6 @@ def _process_finished(self, code: int, status: QtCore.QProcess.ExitStatus) -> No
129126
def _handle_stdout(self) -> None:
130127
"""
131128
处理标准输出的槽 \n
132-
:return: None
133129
"""
134130

135131
if self._process:
@@ -140,7 +136,6 @@ def _handle_stdout(self) -> None:
140136
def _handle_stderr(self) -> None:
141137
"""
142138
处理标准错误的槽 \n
143-
:return: None
144139
"""
145140

146141
if self._process:
@@ -152,13 +147,12 @@ def _handle_state(self, state: QtCore.QProcess.ProcessState) -> None:
152147
"""
153148
将子进程运行状态转换为易读形式 \n
154149
:param state: 进程运行状态
155-
:return: None
156150
"""
157151

158152
states = {
159-
QtCore.QProcess.NotRunning: "Not running",
160-
QtCore.QProcess.Starting: "Starting",
161-
QtCore.QProcess.Running: "Running",
153+
QtCore.QProcess.NotRunning: "非运行",
154+
QtCore.QProcess.Starting: "启动中……",
155+
QtCore.QProcess.Running: "正在运行中……",
162156
}
163157
state_name = states[state]
164158
self.output.emit((self.STATE, state_name))
@@ -167,7 +161,6 @@ def _handle_error(self, error: QtCore.QProcess.ProcessError) -> None:
167161
"""
168162
处理子进程错误 \n
169163
:param error: 子进程错误
170-
:return: None
171164
"""
172165

173166
pass

src/py2exe_gui/Widgets/arguments_browser.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,21 @@
44

55

66
class ArgumentsBrowser(QTextBrowser):
7-
"""针对命令行参数列表特别优化的文本浏览器"""
7+
"""
8+
针对命令行参数列表特别优化的文本浏览器
9+
"""
810

911
def __init__(self, parent: Optional[QWidget] = None) -> None:
12+
"""
13+
:param parent: 父控件对象
14+
"""
15+
1016
super(ArgumentsBrowser, self).__init__(parent)
1117

1218
def enrich_args_text(self, args_list: list[str]) -> None:
1319
"""
1420
对参数进行一定高亮美化后显示 \n
1521
:param args_list: 参数列表
16-
:return: None
1722
"""
1823

1924
text: list[str] = []

src/py2exe_gui/Widgets/center_widget.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,18 @@
1717

1818

1919
class CenterWidget(QWidget):
20-
"""主界面的中央控件"""
20+
"""
21+
主界面的中央控件
22+
"""
2123

2224
# 自定义信号
2325
option_selected = QtCore.Signal(tuple)
2426

2527
def __init__(self, parent: QMainWindow = None) -> None:
28+
"""
29+
:param parent: 父控件对象,应为主窗口
30+
"""
31+
2632
super(CenterWidget, self).__init__(parent)
2733

2834
# 待打包的入口脚本
@@ -63,7 +69,6 @@ def __init__(self, parent: QMainWindow = None) -> None:
6369
def setup_ui(self) -> None:
6470
"""
6571
设置各种控件的属性 \n
66-
:return: None
6772
"""
6873

6974
self.script_path_label.setText("脚本路径:")
@@ -99,16 +104,15 @@ def setup_ui(self) -> None:
99104
def _connect_slots(self) -> None:
100105
"""
101106
定义、连接信号与槽 \n
102-
:return: None
103107
"""
104108

105109
@QtCore.Slot(str)
106110
def script_file_selected(file_path: str) -> None:
107111
"""
108112
脚本文件完成选择的槽函数 \n
109113
:param file_path: 脚本文件路径
110-
:return: None
111114
"""
115+
112116
# TODO 验证有效性、将脚本名作为默认app名
113117
# 将字符串类型的文件路径转成pathlib型的?
114118
self.script_path_le.setText(file_path)
@@ -123,8 +127,8 @@ def script_file_selected(file_path: str) -> None:
123127
def project_name_selected() -> None:
124128
"""
125129
输出程序名称完成输入的槽 \n
126-
:return: None
127130
"""
131+
128132
pro_name: str = self.name_le.text()
129133
self.option_selected.emit(("out_name", pro_name))
130134

@@ -135,8 +139,8 @@ def one_fd_selected(btn_id: int) -> None:
135139
"""
136140
选择输出至单文件/单目录的槽 \n
137141
:param btn_id: fd_group按钮组中按钮的id
138-
:return: None
139142
"""
143+
140144
if btn_id == 0:
141145
self.option_selected.emit(("FD", "One Dir"))
142146
elif btn_id == 1:
@@ -149,8 +153,8 @@ def console_selected(console: bool) -> None:
149153
"""
150154
选择打包的程序是否为stdio启用终端的槽 \n
151155
:param console: 是否启用终端
152-
:return: None
153156
"""
157+
154158
if console:
155159
self.option_selected.emit(("console", "console"))
156160
else:
@@ -161,10 +165,10 @@ def console_selected(console: bool) -> None:
161165
@QtCore.Slot(str)
162166
def icon_file_selected(file_path: str) -> None:
163167
"""
164-
图标文件完成选择的槽函数
168+
图标文件完成选择的槽函数 \n
165169
:param file_path: 图标路径
166-
:return: None
167170
"""
171+
168172
self.icon_path_le.setText(file_path)
169173
self.parent().statusBar().showMessage(f"打开图标路径:{file_path}")
170174
self.option_selected.emit(("icon_path", file_path))
@@ -175,7 +179,6 @@ def icon_file_selected(file_path: str) -> None:
175179
def _set_layout(self) -> None:
176180
"""
177181
设置布局管理器 \n
178-
:return: None
179182
"""
180183

181184
script_layout = QGridLayout()

src/py2exe_gui/Widgets/dialog_widgets.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,21 @@
1313

1414

1515
class ScriptFileDlg(QFileDialog):
16-
"""用于获取入口脚本文件的对话框"""
16+
"""
17+
用于获取入口脚本文件的对话框
18+
"""
1719

1820
def __init__(self, parent: QWidget = None) -> None:
21+
"""
22+
:param parent: 父控件对象
23+
"""
24+
1925
super(ScriptFileDlg, self).__init__(parent)
2026
self._setup()
2127

2228
def _setup(self) -> None:
2329
"""
2430
配置脚本路径对话框 \n
25-
:return: None
2631
"""
2732

2833
self.setAcceptMode(QFileDialog.AcceptOpen)
@@ -36,16 +41,21 @@ def _setup(self) -> None:
3641

3742

3843
class IconFileDlg(QFileDialog):
39-
"""用于获取应用图标文件的对话框"""
44+
"""
45+
用于获取应用图标文件的对话框
46+
"""
4047

4148
def __init__(self, parent: QWidget = None) -> None:
49+
"""
50+
:param parent: 父控件对象
51+
"""
52+
4253
super(IconFileDlg, self).__init__(parent)
4354
self._setup()
4455

4556
def _setup(self) -> None:
4657
"""
4758
配置应用图标对话框 \n
48-
:return: None
4959
"""
5060

5161
self.setAcceptMode(QFileDialog.AcceptOpen)
@@ -59,17 +69,22 @@ def _setup(self) -> None:
5969

6070

6171
class AboutMessage(QMessageBox):
62-
"""用于显示关于信息的对话框"""
72+
"""
73+
用于显示关于信息的对话框
74+
"""
6375

6476
def __init__(self, parent: QWidget = None) -> None:
77+
"""
78+
:param parent: 父控件对象
79+
"""
80+
6581
super(AboutMessage, self).__init__(parent)
6682
self._about_text: str = ""
6783
self._setup()
6884

6985
def _setup(self) -> None:
7086
"""
7187
配置关于信息对话框 \n
72-
:return: None
7388
"""
7489

7590
self.setWindowTitle("关于Py2exe-GUI")
@@ -93,7 +108,9 @@ def about_text(self) -> str:
93108

94109

95110
class SubProcessDlg(QDialog):
96-
"""用于显示子进程信息的对话框"""
111+
"""
112+
用于显示子进程信息的对话框
113+
"""
97114

98115
def __init__(self, parent: QWidget = None) -> None:
99116
super(SubProcessDlg, self).__init__(parent)
@@ -118,7 +135,6 @@ def handle_output(self, subprocess_output: tuple[int, str]) -> None:
118135
"""
119136
处理子进程的输出 \n
120137
:param subprocess_output: 子进程输出
121-
:return: None
122138
"""
123139

124140
output_type, output_text = subprocess_output

src/py2exe_gui/Widgets/main_window.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88

99
class MainWindow(QMainWindow):
10-
"""主界面主窗口"""
10+
"""
11+
主界面主窗口
12+
"""
1113

1214
def __init__(self, *args, **kwargs) -> None:
1315
super().__init__(*args, **kwargs)
@@ -20,7 +22,7 @@ def __init__(self, *args, **kwargs) -> None:
2022

2123
def _setup(self) -> None:
2224
"""
23-
设置主窗口
25+
设置主窗口 \n
2426
"""
2527

2628
self.setWindowTitle("Py2exe-GUI")
@@ -38,7 +40,6 @@ def _setup(self) -> None:
3840
def _setup_menu_bar(self) -> None:
3941
"""
4042
配置主窗口菜单栏 \n
41-
:return: None
4243
"""
4344

4445
file_menu = self.menu_bar.addMenu("文件(&F)")
@@ -68,6 +69,6 @@ def open_url(url: str):
6869
def _setup_status_bar(self) -> None:
6970
"""
7071
配置主窗口状态栏 \n
71-
:return: None
7272
"""
73+
7374
pass

0 commit comments

Comments
 (0)