33from PySide6 import QtCore
44from PySide6 .QtCore import QObject
55
6- from .subprocess_tool import QSubProcessTool
6+ from .subprocess_tool import SubProcessTool
77
88
99class Packaging (QObject ):
@@ -23,9 +23,9 @@ def __init__(self, parent: Optional[QObject] = None):
2323 ]
2424 self .args_dict : dict = dict .fromkeys (pyinstaller_args , "" )
2525 self ._args : List [str ] = []
26- self .subprocess : QSubProcessTool = QSubProcessTool ( )
26+ self ._subprocess : SubProcessTool = SubProcessTool ( self )
2727
28- def get_pyinstaller_args (self , arg : tuple [str , str ]) -> None :
28+ def set_pyinstaller_args (self , arg : tuple [str , str ]) -> None :
2929 """
3030 解析传递来的PyInstaller运行参数,并添加至命令参数字典 \n
3131 :param arg: 运行参数
@@ -34,9 +34,9 @@ def get_pyinstaller_args(self, arg: tuple[str, str]) -> None:
3434 arg_key , arg_value = arg
3535 if arg_key in self .args_dict .keys ():
3636 self .args_dict [arg_key ] = arg_value
37- self .set_pyinstaller_args ()
37+ self ._add_pyinstaller_args ()
3838
39- def set_pyinstaller_args (self ) -> None :
39+ def _add_pyinstaller_args (self ) -> None :
4040 """
4141 将命令参数字典中的参数按顺序添加到命令参数列表中 \n
4242 :return: None
@@ -67,5 +67,27 @@ def run_packaging_process(self) -> None:
6767 :return: None
6868 """
6969
70- # self.subprocess.output.connect(lambda val: print(val)) # 测试用
71- self .subprocess .start_process ("pyinstaller" , self ._args )
70+ # self._subprocess.output.connect(lambda val: print(val)) # 测试用
71+ self ._subprocess .start_process ("pyinstaller" , self ._args )
72+
73+ def abort_process (self ) -> int :
74+ """
75+ 紧急终止打包进程 \n
76+ :return: 子进程返回值
77+ """
78+
79+ if self ._subprocess .process :
80+ result = 0
81+
82+ def handel (output : tuple ):
83+ """处理子进程的输出,获取进程结束的返回值"""
84+ nonlocal result
85+ if output [0 ] == 1 :
86+ result = int (output [1 ])
87+
88+ self ._subprocess .output .connect (handel )
89+ self ._subprocess .process .terminate ()
90+ self ._subprocess .process .waitForFinished (10000 )
91+ return result
92+ else :
93+ return 0
0 commit comments