22# For details: https://github.com/muziing/Py2exe-GUI/blob/main/README.md#license
33
44import sys
5+ from subprocess import call as subprocess_call
56
7+ from PySide6 .QtCore import Slot
68from PySide6 .QtGui import QCloseEvent
79from PySide6 .QtWidgets import QApplication
810
9- from .Core import Packaging , PackagingTask # noqa
11+ from .Constants import PLATFORM # noqa
12+ from .Core import RUNTIME_INFO , Packaging , PackagingTask # noqa
1013from .Resources import compiled_resources # noqa
1114from .Widgets import MainWindow , SubProcessDlg # noqa
1215
@@ -32,27 +35,74 @@ def _connect_slots(self) -> None:
3235 连接各种信号与槽 \n
3336 """
3437
35- center_widget = self .center_widget
36- packaging_task = self .packaging_task
37- packager = self .packager
38-
39- center_widget .option_selected .connect (packaging_task .handle_option )
40- packaging_task .option_set .connect (packager .set_pyinstaller_args )
41- packaging_task .option_set .connect (center_widget .handle_option_set )
42- packaging_task .option_error .connect (center_widget .handle_option_error )
43- packaging_task .ready_to_pack .connect (center_widget .handle_ready_to_pack )
44- packager .args_settled .connect (
45- lambda val : center_widget .pyinstaller_args_browser .enrich_args_text (val )
38+ self ._connect_run_pkg_btn_slot ()
39+ self ._connect_mul_btn_slot (self .subprocess_dlg )
40+
41+ self .center_widget .option_selected .connect (self .packaging_task .handle_option )
42+ self .packaging_task .option_set .connect (self .packager .set_pyinstaller_args )
43+ self .packaging_task .option_set .connect (self .center_widget .handle_option_set )
44+ self .packaging_task .option_error .connect (self .center_widget .handle_option_error )
45+ self .packaging_task .ready_to_pack .connect (
46+ self .center_widget .handle_ready_to_pack
47+ )
48+ self .packager .args_settled .connect (
49+ lambda val : self .center_widget .pyinstaller_args_browser .enrich_args_text (
50+ val
51+ )
4652 )
47- packager .subprocess .output .connect (self .subprocess_dlg .handle_output )
53+ self .packager .subprocess .output .connect (self .subprocess_dlg .handle_output )
54+
55+ # 用户关闭子进程对话框时中止打包进程
56+ self .subprocess_dlg .finished .connect (
57+ lambda : self .packager .subprocess .abort_process (2000 )
58+ )
59+
60+ def _connect_mul_btn_slot (self , subprocess_dlg ):
61+ @Slot ()
62+ def handle_multifunction () -> None :
63+ """
64+ 处理子进程窗口多功能按钮点击信号的槽 \n
65+ """
66+
67+ btn_text = self .subprocess_dlg .multifunction_btn .text ()
68+ if btn_text == "取消" :
69+ self .packager .subprocess .abort_process ()
70+ self .subprocess_dlg .close ()
71+ elif btn_text == "打开输出位置" :
72+ dist_path = self .packaging_task .script_path .parent / "dist"
73+ if PLATFORM .windows == RUNTIME_INFO .platform :
74+ from os import startfile as os_startfile # fmt: skip
75+ os_startfile (dist_path ) # noqa
76+ elif PLATFORM .linux == RUNTIME_INFO .platform :
77+ subprocess_call (["xdg-open" , dist_path ])
78+ elif PLATFORM .macos == RUNTIME_INFO .platform :
79+ subprocess_call (["open" , dist_path ])
80+ elif btn_text == "关闭" :
81+ self .subprocess_dlg .close ()
82+
83+ # 连接信号与槽
84+ subprocess_dlg .multifunction_btn .clicked .connect (handle_multifunction )
85+
86+ def _connect_run_pkg_btn_slot (self ):
87+ @Slot ()
88+ def run_packaging () -> None :
89+ """
90+ “运行打包”按钮的槽函数 \n
91+ """
92+
93+ # 先显示对话框窗口,后运行子进程,确保调试信息/错误信息能被直观显示
94+ self .subprocess_dlg .show ()
95+ self .packager .run_packaging_process ()
96+
97+ self .center_widget .run_packaging_btn .clicked .connect (run_packaging )
4898
4999 def closeEvent (self , event : QCloseEvent ) -> None :
50100 """
51101 重写关闭事件,进行收尾清理 \n
52102 :param event: 关闭事件
53103 """
54104
55- self .packager .subprocess .abort_process ()
105+ # self.packager.subprocess.abort_process(3000) # 不会访问到此行
56106 super ().closeEvent (event )
57107
58108
0 commit comments