Skip to content

Commit 5a25333

Browse files
committed
Add PyInstaller-args Browser and fix some bugs
添加`PyInstaller`的选项预览浏览窗口; 通过界面初始值与`PyInstaller`默认值相同,绕开了启动时单目录/单文件选项不生效的问题; `Packaging`类改为继承自`QObject`,解决了无法获取子进程输出、无法创建自定义信号的问题;
1 parent 735ba7c commit 5a25333

3 files changed

Lines changed: 42 additions & 26 deletions

File tree

src/py2exe-gui/Core/packaging.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
from typing import List, Optional, Sequence
22

33
from PySide6 import QtCore
4+
from PySide6.QtCore import QObject
45

56

6-
class Packaging:
7+
class Packaging(QObject):
78
"""执行打包的类"""
89

910
# 自定义信号
10-
args_settled = QtCore.Signal(tuple)
11+
args_settled = QtCore.Signal(list)
1112

12-
def __init__(self):
13+
def __init__(self, parent: Optional[QObject] = None):
14+
super(Packaging, self).__init__(parent)
1315
pyinstaller_args: list = [
1416
"script_path",
1517
"icon_path",
@@ -54,9 +56,7 @@ def set_pyinstaller_args(self) -> None:
5456
if self.args_dict["out_name"]:
5557
self._args.extend(["--name", self.args_dict["out_name"]])
5658

57-
print(self._args)
58-
# FIXME 修复无法发射信号的问题
59-
# self.args_settled.emit(tuple(self._args))
59+
self.args_settled.emit(self._args)
6060

6161
def run_packaging_process(self) -> None:
6262
"""

src/py2exe-gui/Widgets/center_widget.py

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
QMainWindow,
99
QPushButton,
1010
QRadioButton,
11+
QTextBrowser,
1112
QVBoxLayout,
1213
QWidget,
1314
)
@@ -24,28 +25,36 @@ class CenterWidget(QWidget):
2425
def __init__(self, parent: QMainWindow = None) -> None:
2526
super(CenterWidget, self).__init__(parent)
2627

27-
self.script_path_label = QLabel(self)
28-
self.script_file_dlg = ScriptFileDlg(self)
29-
self.script_browse_btn = QPushButton(self)
30-
self.script_path_le = QLineEdit(self)
28+
# 待打包的入口脚本
29+
self.script_path_label = QLabel()
30+
self.script_file_dlg = ScriptFileDlg()
31+
self.script_browse_btn = QPushButton()
32+
self.script_path_le = QLineEdit()
3133

32-
self.name_label = QLabel(self)
33-
self.name_le = QLineEdit(self)
34+
# 打包后输出的项目名称
35+
self.name_label = QLabel()
36+
self.name_le = QLineEdit()
3437

35-
self.fd_label = QLabel(self)
36-
self.one_dir_btn = QRadioButton(self)
37-
self.one_file_btn = QRadioButton(self)
38-
self.fd_group = QButtonGroup(self)
38+
# 输出至单目录/单文件
39+
self.fd_label = QLabel()
40+
self.one_dir_btn = QRadioButton()
41+
self.one_file_btn = QRadioButton()
42+
self.fd_group = QButtonGroup()
3943

40-
self.icon_path_label = QLabel(self)
41-
self.icon_file_dlg = IconFileDlg(self)
42-
self.icon_browse_btn = QPushButton(self)
43-
self.icon_path_le = QLineEdit(self)
44+
# 应用图标
45+
self.icon_path_label = QLabel()
46+
self.icon_file_dlg = IconFileDlg()
47+
self.icon_browse_btn = QPushButton()
48+
self.icon_path_le = QLineEdit()
4449

4550
# Windows/MacOS 独占,注意后期处理成在Linux下不显示
46-
self.console_checkbox = QCheckBox(self)
51+
self.console_checkbox = QCheckBox()
4752

48-
self.run_packaging_btn = QPushButton(self)
53+
# 预览生成的PyInstaller打包指令
54+
self.pyinstaller_args_browser = QTextBrowser()
55+
56+
# 打包按钮
57+
self.run_packaging_btn = QPushButton()
4958

5059
self.setup_ui()
5160
self._connect_slots()
@@ -67,7 +76,7 @@ def setup_ui(self) -> None:
6776

6877
self.fd_label.setText("单文件/单目录:")
6978
self.one_dir_btn.setText("打包至单个目录")
70-
self.one_dir_btn.setChecked(True)
79+
self.one_dir_btn.setChecked(True) # 默认值
7180
self.one_file_btn.setText("打包至单个文件")
7281
self.fd_group.addButton(self.one_dir_btn, 0)
7382
self.fd_group.addButton(self.one_file_btn, 1)
@@ -79,9 +88,12 @@ def setup_ui(self) -> None:
7988

8089
# Windows/MacOS 独占,注意!!!
8190
self.console_checkbox.setText("为标准I/O启用终端")
82-
self.console_checkbox.setChecked(False)
91+
self.console_checkbox.setChecked(True) # 默认值
92+
93+
self.pyinstaller_args_browser.setMaximumHeight(80)
8394

8495
self.run_packaging_btn.setText("打包!")
96+
# TODO 在完成输入检查后再将打包按钮转为可用
8597
# self.run_packaging_btn.setEnabled(False)
8698

8799
def _connect_slots(self) -> None:
@@ -130,7 +142,7 @@ def one_fd_selected(btn_id: int) -> None:
130142
elif btn_id == 1:
131143
self.option_selected.emit(("FD", "One File"))
132144

133-
self.fd_group.idToggled.connect(one_fd_selected) # type: ignore
145+
self.fd_group.idClicked.connect(one_fd_selected) # type: ignore
134146

135147
@QtCore.Slot(bool)
136148
def console_selected(console: bool) -> None:
@@ -144,7 +156,6 @@ def console_selected(console: bool) -> None:
144156
else:
145157
self.option_selected.emit(("console", "windowed"))
146158

147-
# FIXME 解决启动时不生效
148159
self.console_checkbox.toggled.connect(console_selected) # type: ignore
149160

150161
@QtCore.Slot(str)
@@ -192,5 +203,6 @@ def _set_layout(self) -> None:
192203
main_layout.addLayout(fd_layout)
193204
main_layout.addWidget(self.console_checkbox)
194205
main_layout.addLayout(icon_layout)
206+
main_layout.addWidget(self.pyinstaller_args_browser)
195207
main_layout.addWidget(self.run_packaging_btn)
196208
self.setLayout(main_layout)

src/py2exe-gui/main.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ def __init__(self, *args, **kwargs) -> None:
1313

1414
self.packager = Packaging()
1515

16+
self.packager.args_settled.connect(
17+
lambda val: self.center_widget.pyinstaller_args_browser.setText(str(val))
18+
)
19+
1620
self.center_widget.option_selected.connect(self.packager.get_pyinstaller_args)
1721
self.center_widget.run_packaging_btn.clicked.connect(
1822
self.packager.run_packaging_process

0 commit comments

Comments
 (0)