1- from PySide6 .QtCore import Qt
1+ import subprocess
2+ from typing import Optional
3+
4+ from PySide6 import QtCore
25from PySide6 .QtGui import QPixmap
36from PySide6 .QtWidgets import (
47 QDialog ,
@@ -19,7 +22,7 @@ class ScriptFileDlg(QFileDialog):
1922 用于获取入口脚本文件的对话框
2023 """
2124
22- def __init__ (self , parent : QWidget = None ) -> None :
25+ def __init__ (self , parent : Optional [ QWidget ] = None ) -> None :
2326 """
2427 :param parent: 父控件对象
2528 """
@@ -48,7 +51,7 @@ class IconFileDlg(QFileDialog):
4851 用于获取应用图标文件的对话框
4952 """
5053
51- def __init__ (self , parent : QWidget = None ) -> None :
54+ def __init__ (self , parent : Optional [ QWidget ] = None ) -> None :
5255 """
5356 :param parent: 父控件对象
5457 """
@@ -77,7 +80,7 @@ class AddDataDlg(QFileDialog):
7780 用于添加附加数据的对话框
7881 """
7982
80- def __init__ (self , parent : QWidget = None ) -> None :
83+ def __init__ (self , parent : Optional [ QWidget ] = None ) -> None :
8184 """
8285 :param parent: 父控件对象
8386 """
@@ -99,7 +102,7 @@ class AboutDlg(QMessageBox):
99102 用于显示关于信息的对话框
100103 """
101104
102- def __init__ (self , parent : QWidget = None ) -> None :
105+ def __init__ (self , parent : Optional [ QWidget ] = None ) -> None :
103106 """
104107 :param parent: 父控件对象
105108 """
@@ -116,7 +119,7 @@ def _setup(self) -> None:
116119
117120 self .setWindowTitle ("关于" )
118121 self .setStandardButtons (QMessageBox .Ok )
119- self .setTextFormat (Qt .MarkdownText )
122+ self .setTextFormat (QtCore . Qt .MarkdownText )
120123 self .setText (self .about_text )
121124 self .setIconPixmap (
122125 QPixmap ("py2exe_gui/Resources/Icons/Py2exe-GUI_icon_72px.png" )
@@ -145,11 +148,9 @@ class SubProcessDlg(QDialog):
145148 用于显示子进程信息的对话框
146149 """
147150
148- # TODO 重构SubProcessDlg
149-
150- def __init__ (self , parent : QWidget = None ) -> None :
151+ def __init__ (self , parent : QWidget ) -> None :
151152 """
152- :param parent: 父控件对象
153+ :param parent: 父控件对象,必须为 MainApp 类
153154 """
154155
155156 super (SubProcessDlg , self ).__init__ (parent )
@@ -177,6 +178,10 @@ def _setup(self) -> None:
177178 main_layout .addWidget (self .multifunction_btn )
178179 self .setLayout (main_layout )
179180
181+ # 连接信号与槽
182+ self .multifunction_btn .clicked .connect (self .handle_multifunction ) # type:ignore
183+
184+ @QtCore .Slot (tuple )
180185 def handle_output (self , subprocess_output : tuple [int , str ]) -> None :
181186 """
182187 处理子进程的输出 \n
@@ -196,17 +201,21 @@ def handle_output(self, subprocess_output: tuple[int, str]) -> None:
196201 if output_text == "正在运行中……" :
197202 self .multifunction_btn .setText ("取消" )
198203
204+ @QtCore .Slot ()
205+ def handle_multifunction (self ) -> None :
206+ """
207+ 处理多功能按钮点击信号的槽 \n
208+ """
199209
200- if __name__ == "__main__" :
201- import sys
202-
203- from PySide6 .QtWidgets import QApplication
204-
205- app = QApplication (sys .argv )
206- # window = ScriptFileDlg()
207- # window = IconFileDlg()
208- # window.fileSelected.connect(lambda f: print(f)) # type: ignore
209- # window = AboutDlg()
210- window = SubProcessDlg ()
211- window .open ()
212- sys .exit (app .exec ())
210+ btn_text = self .multifunction_btn .text ()
211+ if btn_text == "取消" :
212+ self .parent ().packager .subprocess .abort_process ()
213+ self .close ()
214+ elif btn_text == "打开输出位置" :
215+ dist_path = self .parent ().packaging_task .script_path .parent / "dist"
216+ if self .parent ().running_platform == "Windows" :
217+ os .startfile (dist_path ) # type: ignore
218+ elif self .parent ().running_platform == "Linux" :
219+ subprocess .call (["xdg-open" , dist_path ])
220+ elif self .parent ().running_platform == "macOS" :
221+ subprocess .call (["open" , dist_path ])
0 commit comments